11import React , { useEffect , useState } from 'react' ;
22import FlashMessageRender from '@/components/FlashMessageRender' ;
33import { ServerContext } from '@/state/server' ;
4- import loadDirectory , { FileObject } from '@/api/server/files/loadDirectory' ;
54import { Actions , useStoreActions } from 'easy-peasy' ;
65import { ApplicationStore } from '@/state' ;
76import { httpErrorToHuman } from '@/api/http' ;
87import { CSSTransition } from 'react-transition-group' ;
98import { Link } from 'react-router-dom' ;
109import Spinner from '@/components/elements/Spinner' ;
1110import FileObjectRow from '@/components/server/files/FileObjectRow' ;
12- import { getDirectoryFromHash } from '@/helpers' ;
1311
1412export default ( ) => {
1513 const [ loading , setLoading ] = useState ( true ) ;
16- const [ files , setFiles ] = useState < FileObject [ ] > ( [ ] ) ;
17- const server = ServerContext . useStoreState ( state => state . server . data ! ) ;
1814 const { addError, clearFlashes } = useStoreActions ( ( actions : Actions < ApplicationStore > ) => actions . flashes ) ;
15+ const { contents : files } = ServerContext . useStoreState ( state => state . files ) ;
16+ const getDirectoryContents = ServerContext . useStoreActions ( actions => actions . files . getDirectoryContents ) ;
17+
18+ const urlDirectory = window . location . hash . replace ( / ^ # ( \/ ) + / , '/' ) ;
1919
2020 const load = ( ) => {
2121 setLoading ( true ) ;
2222 clearFlashes ( ) ;
23- loadDirectory ( server . uuid , getDirectoryFromHash ( ) )
24- . then ( files => {
25- setFiles ( files ) ;
26- setLoading ( false ) ;
27- } )
23+
24+ getDirectoryContents ( urlDirectory )
25+ . then ( ( ) => setLoading ( false ) )
2826 . catch ( error => {
2927 if ( error . response && error . response . status === 404 ) {
3028 window . location . hash = '#/' ;
@@ -36,7 +34,7 @@ export default () => {
3634 } ) ;
3735 } ;
3836
39- const breadcrumbs = ( ) : { name : string ; path ?: string } [ ] => getDirectoryFromHash ( ) . split ( '/' )
37+ const breadcrumbs = ( ) : { name : string ; path ?: string } [ ] => urlDirectory . split ( '/' )
4038 . filter ( directory => ! ! directory )
4139 . map ( ( directory , index , dirs ) => {
4240 if ( index === dirs . length - 1 ) {
@@ -86,7 +84,7 @@ export default () => {
8684 < div >
8785 {
8886 files . map ( file => (
89- < FileObjectRow key = { file . name } directory = { getDirectoryFromHash ( ) } file = { file } />
87+ < FileObjectRow key = { file . name } file = { file } />
9088 ) )
9189 }
9290 </ div >
0 commit comments