From a3c5e310949a0f221363c042158ab8ff530a8d2c Mon Sep 17 00:00:00 2001 From: web Date: Wed, 17 Sep 2025 02:35:53 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Add=20fetchTags=20method?= =?UTF-8?q?=20to=20NodesPage=20and=20ensure=20tags=20are=20fetched=20along?= =?UTF-8?q?side=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/app/dashboard/nodes/page.tsx | 8 +++++++- apps/admin/store/node.ts | 22 ++++++++++++++++++++-- apps/admin/store/server.ts | 12 +++++++++++- apps/admin/store/subscribe.ts | 12 +++++++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/apps/admin/app/dashboard/nodes/page.tsx b/apps/admin/app/dashboard/nodes/page.tsx index c88bc24..bf60842 100644 --- a/apps/admin/app/dashboard/nodes/page.tsx +++ b/apps/admin/app/dashboard/nodes/page.tsx @@ -27,7 +27,7 @@ export default function NodesPage() { // Use our zustand store for server data const { getServerName, getServerAddress, getProtocolPort } = useServer(); - const { fetchNodes } = useNode(); + const { fetchNodes, fetchTags } = useNode(); return ( @@ -55,6 +55,7 @@ export default function NodesPage() { toast.success(t('created')); ref.current?.refresh(); fetchNodes(); + fetchTags(); setLoading(false); return true; } catch (e) { @@ -77,6 +78,7 @@ export default function NodesPage() { toast.success(v ? t('enabled_on') : t('enabled_off')); ref.current?.refresh(); fetchNodes(); + fetchTags(); }} /> ), @@ -151,6 +153,7 @@ export default function NodesPage() { toast.success(t('updated')); ref.current?.refresh(); fetchNodes(); + fetchTags(); setLoading(false); return true; } catch (e) { @@ -169,6 +172,7 @@ export default function NodesPage() { toast.success(t('deleted')); ref.current?.refresh(); fetchNodes(); + fetchTags(); }} cancelText={t('cancel')} confirmText={t('confirm')} @@ -185,6 +189,7 @@ export default function NodesPage() { toast.success(t('copied')); ref.current?.refresh(); fetchNodes(); + fetchTags(); }} > {t('copy')} @@ -202,6 +207,7 @@ export default function NodesPage() { toast.success(t('deleted')); ref.current?.refresh(); fetchNodes(); + fetchTags(); }} cancelText={t('cancel')} confirmText={t('confirm')} diff --git a/apps/admin/store/node.ts b/apps/admin/store/node.ts index a629aa3..eb8eaa0 100644 --- a/apps/admin/store/node.ts +++ b/apps/admin/store/node.ts @@ -6,6 +6,10 @@ interface NodeState { nodes: API.Node[]; tags: string[]; + // Loading states + loading: boolean; + loadingTags: boolean; + // Actions fetchNodes: () => Promise; fetchTags: () => Promise; @@ -24,23 +28,35 @@ export const useNodeStore = create((set, get) => ({ // Initial state nodes: [], tags: [], + loading: false, + loadingTags: false, // Actions fetchNodes: async () => { + if (get().loading) return; + + set({ loading: true }); try { const { data } = await filterNodeList({ page: 1, size: 999999999 }); set({ nodes: data?.data?.list || [] }); } catch (error) { // Handle error silently + } finally { + set({ loading: false }); } }, fetchTags: async () => { + if (get().loadingTags) return; + + set({ loadingTags: true }); try { const { data } = await queryNodeTag(); set({ tags: data?.data?.tags || [] }); } catch (error) { // Handle error silently + } finally { + set({ loadingTags: false }); } }, @@ -88,16 +104,18 @@ export const useNode = () => { const store = useNodeStore(); // Auto-fetch nodes and tags - if (store.nodes.length === 0) { + if (store.nodes.length === 0 && !store.loading) { store.fetchNodes(); } - if (store.tags.length === 0) { + if (store.tags.length === 0 && !store.loadingTags) { store.fetchTags(); } return { nodes: store.nodes, tags: store.tags, + loading: store.loading, + loadingTags: store.loadingTags, fetchNodes: store.fetchNodes, fetchTags: store.fetchTags, getNodeById: store.getNodeById, diff --git a/apps/admin/store/server.ts b/apps/admin/store/server.ts index 87b635e..c3020a6 100644 --- a/apps/admin/store/server.ts +++ b/apps/admin/store/server.ts @@ -5,6 +5,9 @@ interface ServerState { // Data servers: API.Server[]; + // Loading states + loading: boolean; + // Actions fetchServers: () => Promise; @@ -20,14 +23,20 @@ interface ServerState { export const useServerStore = create((set, get) => ({ // Initial state servers: [], + loading: false, // Actions fetchServers: async () => { + if (get().loading) return; + + set({ loading: true }); try { const { data } = await filterServerList({ page: 1, size: 999999999 }); set({ servers: data?.data?.list || [] }); } catch (error) { // Handle error silently + } finally { + set({ loading: false }); } }, @@ -75,12 +84,13 @@ export const useServer = () => { const store = useServerStore(); // Auto-fetch servers - if (store.servers.length === 0) { + if (store.servers.length === 0 && !store.loading) { store.fetchServers(); } return { servers: store.servers, + loading: store.loading, fetchServers: store.fetchServers, getServerById: store.getServerById, getServerName: store.getServerName, diff --git a/apps/admin/store/subscribe.ts b/apps/admin/store/subscribe.ts index 776414a..6ac88e0 100644 --- a/apps/admin/store/subscribe.ts +++ b/apps/admin/store/subscribe.ts @@ -5,6 +5,9 @@ interface SubscribeState { // Data subscribes: API.SubscribeItem[]; + // Loading states + loading: boolean; + // Actions fetchSubscribes: () => Promise; @@ -16,14 +19,20 @@ interface SubscribeState { export const useSubscribeStore = create((set, get) => ({ // Initial state subscribes: [], + loading: false, // Actions fetchSubscribes: async () => { + if (get().loading) return; + + set({ loading: true }); try { const { data } = await getSubscribeList({ page: 1, size: 999999999 }); set({ subscribes: data?.data?.list || [] }); } catch (error) { // Handle error silently + } finally { + set({ loading: false }); } }, @@ -43,12 +52,13 @@ export const useSubscribe = () => { const store = useSubscribeStore(); // Auto-fetch subscribes - if (store.subscribes.length === 0) { + if (store.subscribes.length === 0 && !store.loading) { store.fetchSubscribes(); } return { subscribes: store.subscribes, + loading: store.loading, fetchSubscribes: store.fetchSubscribes, getSubscribeName: store.getSubscribeName, getSubscribeById: store.getSubscribeById,