import React, { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Card, Grid, Header } from 'semantic-ui-react'; import { API, showError, showNotice, timestamp2string } from '../../helpers'; import { StatusContext } from '../../context/Status'; import { marked } from 'marked'; import { UserContext } from '../../context/User'; import { Link } from 'react-router-dom'; const Home = () => { const { t } = useTranslation(); const [statusState, statusDispatch] = useContext(StatusContext); const [homePageContentLoaded, setHomePageContentLoaded] = useState(false); const [homePageContent, setHomePageContent] = useState(''); const [userState] = useContext(UserContext); const displayNotice = async () => { const res = await API.get('/api/notice'); const { success, message, data } = res.data; if (success) { let oldNotice = localStorage.getItem('notice'); if (data !== oldNotice && data !== '') { const htmlNotice = marked(data); showNotice(htmlNotice, true); localStorage.setItem('notice', data); } } else { showError(message); } }; const displayHomePageContent = async () => { setHomePageContent(localStorage.getItem('home_page_content') || ''); const res = await API.get('/api/home_page_content'); const { success, message, data } = res.data; if (success) { let content = data; if (!data.startsWith('https://')) { content = marked.parse(data); } setHomePageContent(content); localStorage.setItem('home_page_content', content); } else { showError(message); setHomePageContent(t('home.loading_failed')); } setHomePageContentLoaded(true); }; const getStartTimeString = () => { const timestamp = statusState?.status?.start_time; return timestamp2string(timestamp); }; useEffect(() => { displayNotice().then(); displayHomePageContent().then(); }, []); return ( <> {homePageContentLoaded && homePageContent === '' ? (
{t('home.welcome.description')}
{!userState.user &&{t('home.welcome.login_notice')}
}{t('home.system_status.info.name')} {statusState?.status?.system_name}
{t('home.system_status.info.version')} {statusState?.status?.version || 'unknown'}
{t('home.system_status.info.source')} {t('home.system_status.info.source_link')}
{t('home.system_status.info.start_time')} {getStartTimeString()}
{t('home.system_status.config.email_verify')} {statusState?.status?.email_verification ? t('home.system_status.config.enabled') : t('home.system_status.config.disabled')}
{t('home.system_status.config.github_oauth')} {statusState?.status?.github_oauth ? t('home.system_status.config.enabled') : t('home.system_status.config.disabled')}
{t('home.system_status.config.wechat_login')} {statusState?.status?.wechat_login ? t('home.system_status.config.enabled') : t('home.system_status.config.disabled')}
{t('home.system_status.config.turnstile')} {statusState?.status?.turnstile_check ? t('home.system_status.config.enabled') : t('home.system_status.config.disabled')}