From 8f0eda21c58cdce2a697b0eae44fee5c19bc6024 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 11 Sep 2021 14:17:20 -0700 Subject: [PATCH] Fix all screens on the panel unintentionally loading the root directory for a server --- resources/scripts/components/server/InstallListener.tsx | 6 +++--- resources/scripts/plugins/useFileManagerSwr.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/scripts/components/server/InstallListener.tsx b/resources/scripts/components/server/InstallListener.tsx index c0a7f6ac..fbf377a2 100644 --- a/resources/scripts/components/server/InstallListener.tsx +++ b/resources/scripts/components/server/InstallListener.tsx @@ -1,16 +1,16 @@ import useWebsocketEvent from '@/plugins/useWebsocketEvent'; import { ServerContext } from '@/state/server'; import { SocketEvent } from '@/components/server/events'; -import useFileManagerSwr from '@/plugins/useFileManagerSwr'; +import { mutate } from 'swr'; +import { getDirectorySwrKey } from '@/plugins/useFileManagerSwr'; const InstallListener = () => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const getServer = ServerContext.useStoreActions(actions => actions.server.getServer); - const { mutate } = useFileManagerSwr(); const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState); useWebsocketEvent(SocketEvent.BACKUP_RESTORE_COMPLETED, () => { - mutate(undefined); + mutate(getDirectorySwrKey(uuid, '/'), undefined); setServerFromState(s => ({ ...s, status: null })); }); diff --git a/resources/scripts/plugins/useFileManagerSwr.ts b/resources/scripts/plugins/useFileManagerSwr.ts index 390ce839..e134cb40 100644 --- a/resources/scripts/plugins/useFileManagerSwr.ts +++ b/resources/scripts/plugins/useFileManagerSwr.ts @@ -3,12 +3,14 @@ import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory'; import { cleanDirectoryPath } from '@/helpers'; import { ServerContext } from '@/state/server'; +export const getDirectorySwrKey = (uuid: string, directory: string): string => `${uuid}:files:${directory}`; + export default () => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const directory = ServerContext.useStoreState(state => state.files.directory); return useSWR( - `${uuid}:files:${directory}`, + getDirectorySwrKey(uuid, directory), () => loadDirectory(uuid, cleanDirectoryPath(directory)), { focusThrottleInterval: 30000,