misc_pterodactyl-panel/resources/scripts/plugins/useFileManagerSwr.ts
2020-07-10 22:53:52 -07:00

19 lines
563 B
TypeScript

import useSWR from 'swr';
import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory';
import { cleanDirectoryPath } from '@/helpers';
import useServer from '@/plugins/useServer';
import { useLocation } from 'react-router';
export default () => {
const { uuid } = useServer();
const { hash } = useLocation();
return useSWR<FileObject[]>(
`${uuid}:files:${hash}`,
() => loadDirectory(uuid, cleanDirectoryPath(hash)),
{
revalidateOnMount: false,
refreshInterval: 0,
}
);
};