2020-07-11 05:38:07 +00:00
|
|
|
import useSWR from 'swr';
|
2022-02-27 17:44:22 +00:00
|
|
|
import { loadDirectory, FileObject } from '@/api/server/files';
|
2020-07-11 05:38:07 +00:00
|
|
|
import { cleanDirectoryPath } from '@/helpers';
|
2020-07-18 17:45:41 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
2020-07-11 05:38:07 +00:00
|
|
|
|
2021-09-11 21:17:20 +00:00
|
|
|
export const getDirectorySwrKey = (uuid: string, directory: string): string => `${uuid}:files:${directory}`;
|
|
|
|
|
2020-07-11 05:38:07 +00:00
|
|
|
export default () => {
|
2020-08-26 04:39:00 +00:00
|
|
|
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
2020-07-18 17:45:41 +00:00
|
|
|
const directory = ServerContext.useStoreState(state => state.files.directory);
|
2020-07-11 05:38:07 +00:00
|
|
|
|
|
|
|
return useSWR<FileObject[]>(
|
2021-09-11 21:17:20 +00:00
|
|
|
getDirectorySwrKey(uuid, directory),
|
2020-07-18 17:45:41 +00:00
|
|
|
() => loadDirectory(uuid, cleanDirectoryPath(directory)),
|
2020-07-11 05:53:52 +00:00
|
|
|
{
|
2020-09-10 04:32:43 +00:00
|
|
|
focusThrottleInterval: 30000,
|
|
|
|
revalidateOnMount: false,
|
2020-07-11 05:53:52 +00:00
|
|
|
refreshInterval: 0,
|
2020-11-01 19:44:47 +00:00
|
|
|
errorRetryCount: 2,
|
2020-07-18 17:45:41 +00:00
|
|
|
},
|
2020-07-11 05:38:07 +00:00
|
|
|
);
|
|
|
|
};
|