perf: load cached about content first (#60)

This commit is contained in:
JustSong 2023-05-14 16:13:42 +08:00
parent 6167e20b34
commit 57cb150177

View File

@ -5,18 +5,21 @@ import { marked } from 'marked';
const About = () => {
const [about, setAbout] = useState('');
const [aboutLoaded, setAboutLoaded] = useState(false);
const displayAbout = async () => {
setAbout(localStorage.getItem('about') || '');
const res = await API.get('/api/about');
const { success, message, data } = res.data;
if (success) {
let HTMLAbout = marked.parse(data);
localStorage.setItem('about', HTMLAbout);
setAbout(HTMLAbout);
localStorage.setItem('about', HTMLAbout);
} else {
showError(message);
setAbout('加载关于内容失败...');
}
setAboutLoaded(true);
};
useEffect(() => {
@ -27,7 +30,7 @@ const About = () => {
<>
<Segment>
{
about === '' ? <>
aboutLoaded && about === '' ? <>
<Header as='h3'>关于</Header>
<p>可在设置页面设置关于内容支持 HTML & Markdown</p>
项目仓库地址