index.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { useEffect, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import ReactMarkdown from 'react-markdown';
  4. import remarkGfm from 'remark-gfm';
  5. import { DOC_LAST_UPDATED } from '@/defines';
  6. import { useResponsive } from '@/hooks/useResponsive';
  7. import { getDirByLang, loadMdByLang } from '@/utils/mdLoader';
  8. const PrivacyPolicy: React.FC = () => {
  9. const { i18n, t } = useTranslation();
  10. const { isMobile } = useResponsive();
  11. const [mdContent, setMdContent] = useState<string>('');
  12. const [mdLang, setMdLang] = useState<string>('en-US');
  13. const [dir, setDir] = useState<'ltr' | 'rtl'>('ltr');
  14. useEffect(() => {
  15. loadMdByLang('privacyPolicy', i18n.language, {
  16. replacements: { '[Insert Date]': DOC_LAST_UPDATED }, // 替换 MD 中的 [Insert Date]
  17. }).then(({ content, usedLang }) => {
  18. setMdLang(usedLang);
  19. setMdContent(content);
  20. });
  21. }, [i18n.language]);
  22. useEffect(() => {
  23. setDir(getDirByLang(mdLang));
  24. }, [mdLang]);
  25. return (
  26. <div className="flex items-start justify-center">
  27. <div className={`max-w-[1440px] w-full ${isMobile ? 'px-0' : 'px-[30px]'}`}>
  28. <div
  29. className={`bg-[#0F1116] px-5 sm:px-5 lg:px-[100px] py-[30px] flex flex-col ${isMobile ? 'gap-5 mt-0 pb-[30px]' : 'gap-10 my-[50px] rounded-[12px] pb-[100px]'}`}
  30. >
  31. <span
  32. className={`w-full text-white font-semibold leading-[1.43] text-start uppercase ${isMobile ? 'text-[22px]' : 'text-[35px]'}`}
  33. >
  34. {t('pages.privacyPolicy.title')}
  35. </span>
  36. <div
  37. className={`flex flex-col bg-[#1B1D22] text-white rounded-xl shadow-[0px_4px_10px_0px_rgba(0,0,0,0.05)] ${isMobile ? 'p-[14px] gap-2' : 'p-[25px_30px_25px_25px] gap-5'}`}
  38. dir={dir}
  39. style={{
  40. direction: dir,
  41. textAlign: dir === 'ltr' ? 'left' : 'right',
  42. }}
  43. >
  44. {mdContent && (
  45. <ReactMarkdown remarkPlugins={[remarkGfm]} components={{}}>
  46. {mdContent}
  47. </ReactMarkdown>
  48. )}
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. );
  54. };
  55. export default PrivacyPolicy;