import React, { useEffect, useState } from 'react'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ServerContext } from '@/state/server'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { httpErrorToHuman } from '@/api/http'; import { CSSTransition } from 'react-transition-group'; import Spinner from '@/components/elements/Spinner'; import FileObjectRow from '@/components/server/files/FileObjectRow'; import FileManagerBreadcrumbs from '@/components/server/files/FileManagerBreadcrumbs'; import { FileObject } from '@/api/server/files/loadDirectory'; import NewDirectoryButton from '@/components/server/files/NewDirectoryButton'; import { Link } from 'react-router-dom'; import Can from '@/components/elements/Can'; const sortFiles = (files: FileObject[]): FileObject[] => { return files.sort((a, b) => a.name.localeCompare(b.name)) .sort((a, b) => a.isFile === b.isFile ? 0 : (a.isFile ? 1 : -1)); }; export default () => { const [ loading, setLoading ] = useState(true); const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); const { id } = ServerContext.useStoreState(state => state.server.data!); const { contents: files } = ServerContext.useStoreState(state => state.files); const { getDirectoryContents } = ServerContext.useStoreActions(actions => actions.files); useEffect(() => { setLoading(true); clearFlashes(); getDirectoryContents(window.location.hash) .then(() => setLoading(false)) .catch(error => { console.error(error.message, { error }); addError({ message: httpErrorToHuman(error), key: 'files' }); }); }, []); return (
{ loading ? : {!files.length ?

This directory seems to be empty.

:
{files.length > 250 ?

This directory is too large to display in the browser, limiting the output to the first 250 files.

{ sortFiles(files.slice(0, 250)).map(file => ( )) }
: sortFiles(files).map(file => ( )) }
}
New File
}
); };