1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-25 02:22:36 +01:00
Pterodactyl-Panel/resources/scripts/plugins/useFileManagerSwr.ts
2022-11-25 13:25:03 -07:00

23 lines
817 B
TypeScript

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,
},
);
};