From 7d76e9a7e953c4c74a3ee147b563886601365480 Mon Sep 17 00:00:00 2001 From: Leonxie Date: Fri, 23 Jan 2026 14:38:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E7=9F=A5=E9=81=93=E8=AF=A5=E8=AF=B4?= =?UTF-8?q?=E4=BB=80=E4=B9=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- front/src/components/CreatePost.tsx | 3 ++- front/src/components/StatusDisplay.tsx | 9 ++++++++- front/src/context/LayoutContext.tsx | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index da73abc..b92b3f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -back/data/ \ No newline at end of file +back/data/ +back/__pycache__/ \ No newline at end of file diff --git a/front/src/components/CreatePost.tsx b/front/src/components/CreatePost.tsx index caa860b..9b910ff 100644 --- a/front/src/components/CreatePost.tsx +++ b/front/src/components/CreatePost.tsx @@ -120,7 +120,7 @@ const remarkTagPlugin = () => { const CreatePost: React.FC = () => { const styles = useStyles(); const navigate = useNavigate(); - const { isDarkMode, toasterId } = useLayout(); + const { isDarkMode, toasterId, triggerRefresh } = useLayout(); const { dispatchToast } = useToastController(toasterId); const [value, setValue] = useState(""); const [lastSaved, setLastSaved] = useState(() => new Date().toLocaleTimeString('zh-CN', { hour12: false })); @@ -170,6 +170,7 @@ const CreatePost: React.FC = () => { { intent: 'success' } ); + triggerRefresh(); navigate('/'); } else if (response.code === 2005) { dispatchToast( diff --git a/front/src/components/StatusDisplay.tsx b/front/src/components/StatusDisplay.tsx index 6b20342..b129d2e 100644 --- a/front/src/components/StatusDisplay.tsx +++ b/front/src/components/StatusDisplay.tsx @@ -76,7 +76,7 @@ const useStyles = makeStyles({ const StatusDisplay: React.FC = () => { const styles = useStyles(); - const { toasterId } = useLayout(); + const { toasterId, refreshTrigger } = useLayout(); const { dispatchToast } = useToastController(toasterId); const [isApiOnline, setIsApiOnline] = useState(null); const [statics, setStatics] = useState(null); @@ -121,6 +121,13 @@ const StatusDisplay: React.FC = () => { }; }, [checkStatus, refreshStatics]); + // Listen for global refresh trigger + useEffect(() => { + if (refreshTrigger > 0) { + refreshStatics(false); + } + }, [refreshTrigger, refreshStatics]); + return (
diff --git a/front/src/context/LayoutContext.tsx b/front/src/context/LayoutContext.tsx index 503af22..cb8544d 100644 --- a/front/src/context/LayoutContext.tsx +++ b/front/src/context/LayoutContext.tsx @@ -10,6 +10,8 @@ interface LayoutContextType { isDarkMode: boolean; toggleTheme: () => void; toasterId: string; + refreshTrigger: number; + triggerRefresh: () => void; } const LayoutContext = createContext(undefined); @@ -18,6 +20,7 @@ export const LayoutProvider: React.FC<{ children: React.ReactNode; toasterId: st const [settings, setSettings] = useState(null); const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(false); const [isDarkMode, setIsDarkMode] = useState(false); + const [refreshTrigger, setRefreshTrigger] = useState(0); const { dispatchToast } = useToastController(toasterId); useEffect(() => { @@ -47,9 +50,10 @@ export const LayoutProvider: React.FC<{ children: React.ReactNode; toasterId: st const toggleSidebar = () => setIsSidebarCollapsed(prev => !prev); const toggleTheme = () => setIsDarkMode(prev => !prev); + const triggerRefresh = () => setRefreshTrigger(prev => prev + 1); return ( - + {children} );