🐛 fix: Add fetchTags method to NodesPage and ensure tags are fetched alongside nodes

This commit is contained in:
web 2025-09-17 02:35:53 -07:00
parent 1b715c5f8b
commit a3c5e31094
4 changed files with 49 additions and 5 deletions

View File

@ -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 (
<ProTable<API.Node, { search: string }>
@ -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')}

View File

@ -6,6 +6,10 @@ interface NodeState {
nodes: API.Node[];
tags: string[];
// Loading states
loading: boolean;
loadingTags: boolean;
// Actions
fetchNodes: () => Promise<void>;
fetchTags: () => Promise<void>;
@ -24,23 +28,35 @@ export const useNodeStore = create<NodeState>((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,

View File

@ -5,6 +5,9 @@ interface ServerState {
// Data
servers: API.Server[];
// Loading states
loading: boolean;
// Actions
fetchServers: () => Promise<void>;
@ -20,14 +23,20 @@ interface ServerState {
export const useServerStore = create<ServerState>((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,

View File

@ -5,6 +5,9 @@ interface SubscribeState {
// Data
subscribes: API.SubscribeItem[];
// Loading states
loading: boolean;
// Actions
fetchSubscribes: () => Promise<void>;
@ -16,14 +19,20 @@ interface SubscribeState {
export const useSubscribeStore = create<SubscribeState>((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,