perf: load cached about content first

This commit is contained in:
JustSong
2023-05-14 16:13:12 +08:00
parent a411e230a0
commit d434c370ab

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(() => {
@@ -26,7 +29,7 @@ const About = () => {
return (
<>
<Segment>
{about === '' ? (
{aboutLoaded && about === '' ? (
<>
<Header as='h3'>关于</Header>
<p>可在设置页面设置关于内容支持 HTML & Markdown</p>