forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseFileManagerSwr.ts
More file actions
22 lines (19 loc) · 817 Bytes
/
useFileManagerSwr.ts
File metadata and controls
22 lines (19 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import useSWR from 'swr';
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<FileObject[]>(
getDirectorySwrKey(uuid, directory),
() => loadDirectory(uuid, cleanDirectoryPath(directory)),
{
focusThrottleInterval: 30000,
revalidateOnMount: false,
refreshInterval: 0,
errorRetryCount: 2,
},
);
};