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'; export default () => { const [ loading, setLoading ] = useState(true); const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); const { contents: files, directory } = ServerContext.useStoreState(state => state.files); const { setDirectory, getDirectoryContents } = ServerContext.useStoreActions(actions => actions.files); const load = () => { setLoading(true); clearFlashes(); getDirectoryContents(window.location.hash.replace(/^#(\/)*/, '/')) .then(() => setLoading(false)) .catch(error => { console.error(error.message, { error }); addError({ message: httpErrorToHuman(error), key: 'files' }); }); }; const breadcrumbs = (): { name: string; path?: string }[] => directory.split('/') .filter(directory => !!directory) .map((directory, index, dirs) => { if (index === dirs.length - 1) { return { name: directory }; } return { name: directory, path: `/${dirs.slice(0, index + 1).join('/')}` }; }); useEffect(() => load(), [ directory ]); return (
/home/ setDirectory('/')} className={'px-1 text-neutral-200 no-underline hover:text-neutral-100'} > container / { breadcrumbs().map((crumb, index) => ( crumb.path ? setDirectory(crumb.path!)} className={'px-1 text-neutral-200 no-underline hover:text-neutral-100'} > {crumb.name} / : {crumb.name} )) }
{ loading ? : !files.length ?

This directory seems to be empty.

:
{ files.map(file => ( )) }
}
); };