2020-07-11 05:38:07 +00:00
|
|
|
import useSWR from 'swr';
|
|
|
|
import loadDirectory, { FileObject } from '@/api/server/files/loadDirectory';
|
|
|
|
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
|
|
|
|
|
|
|
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[]>(
|
2020-07-18 17:45:41 +00:00
|
|
|
`${uuid}:files:${directory}`,
|
|
|
|
() => loadDirectory(uuid, cleanDirectoryPath(directory)),
|
2020-07-11 05:53:52 +00:00
|
|
|
{
|
2020-07-18 17:45:41 +00:00
|
|
|
revalidateOnMount: true,
|
2020-07-11 05:53:52 +00:00
|
|
|
refreshInterval: 0,
|
2020-07-18 17:45:41 +00:00
|
|
|
},
|
2020-07-11 05:38:07 +00:00
|
|
|
);
|
|
|
|
};
|