fix: polish forum navigation and interface states

This commit is contained in:
lezi-fun committed 2026-08-11 15:25:05 +08:00
1 parent 0933220c70
commit 6947cdaf36
33 files changed
+1615 -360

No files matched your search

+21 -7
View File
@@ -5,17 +5,31 @@ import { useEffect, useState } from 'react';
import { API } from '@/lib/api';
import { Icon } from './Icons';
export default function Sidebar() {
const [stats, setStats] = useState({ posts: 0, users: 0, topics: 0, online: 0 });
const [links, setLinks] = useState([]);
const emptyStats = { posts: 0, users: 0, topics: 0, online: 0 };
let cachedStats = null;
let cachedLinks = null;
export default function Sidebar({ id = 'sidebar' }) {
const [stats, setStats] = useState(() => cachedStats || emptyStats);
const [links, setLinks] = useState(() => cachedLinks || []);
useEffect(() => {
API.getStats().then(setStats).catch(() => {});
API.getLinks().then(setLinks).catch(() => {});
if (!cachedStats) {
API.getStats().then((nextStats) => {
cachedStats = nextStats;
setStats(nextStats);
}).catch(() => {});
}
if (!cachedLinks) {
API.getLinks().then((nextLinks) => {
cachedLinks = nextLinks;
setLinks(nextLinks);
}).catch(() => {});
}
}, []);
return (
<aside id="sidebar">
<aside id={id} className="sidebar">
<div className="stats-box">
<h4>
<Icon name="book" size={14} /> 社区统计
@@ -29,7 +43,7 @@ export default function Sidebar() {
<h4>
<Icon name="link" size={14} /> 友情链接
</h4>
<ul id="friendlyLinks">
<ul id={id === 'sidebar' ? 'friendlyLinks' : undefined} className="friendly-links">
{links.length === 0 ? (
<li style={{ color: '#94a3b8', fontSize: 13 }}>暂无链接</li>
) : (