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