Skip to content

Commit

Permalink
perf: load cached about content first (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 14, 2023
1 parent 6167e20 commit 57cb150
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions web/src/pages/About/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -27,7 +30,7 @@ const About = () => {
<>
<Segment>
{
about === '' ? <>
aboutLoaded && about === '' ? <>
<Header as='h3'>关于</Header>
<p>可在设置页面设置关于内容,支持 HTML & Markdown</p>
项目仓库地址:
Expand Down

0 comments on commit 57cb150

Please sign in to comment.