@@ -5,36 +5,28 @@ import { Actions, useStoreActions } from 'easy-peasy';
55import { ApplicationStore } from '@/state' ;
66import { httpErrorToHuman } from '@/api/http' ;
77import { CSSTransition } from 'react-transition-group' ;
8- import { Link } from 'react-router-dom' ;
98import Spinner from '@/components/elements/Spinner' ;
109import FileObjectRow from '@/components/server/files/FileObjectRow' ;
1110
1211export default ( ) => {
1312 const [ loading , setLoading ] = useState ( true ) ;
1413 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 ( / ^ # ( \/ ) + / , '/' ) ;
14+ const { contents : files , directory } = ServerContext . useStoreState ( state => state . files ) ;
15+ const { setDirectory, getDirectoryContents } = ServerContext . useStoreActions ( actions => actions . files ) ;
1916
2017 const load = ( ) => {
2118 setLoading ( true ) ;
2219 clearFlashes ( ) ;
2320
24- getDirectoryContents ( urlDirectory )
21+ getDirectoryContents ( window . location . hash . replace ( / ^ # ( \/ ) * / , '/' ) )
2522 . then ( ( ) => setLoading ( false ) )
2623 . catch ( error => {
27- if ( error . response && error . response . status === 404 ) {
28- window . location . hash = '#/' ;
29- return ;
30- }
31-
3224 console . error ( error . message , { error } ) ;
3325 addError ( { message : httpErrorToHuman ( error ) , key : 'files' } ) ;
3426 } ) ;
3527 } ;
3628
37- const breadcrumbs = ( ) : { name : string ; path ?: string } [ ] => urlDirectory . split ( '/' )
29+ const breadcrumbs = ( ) : { name : string ; path ?: string } [ ] => directory . split ( '/' )
3830 . filter ( directory => ! ! directory )
3931 . map ( ( directory , index , dirs ) => {
4032 if ( index === dirs . length - 1 ) {
@@ -44,27 +36,32 @@ export default () => {
4436 return { name : directory , path : `/${ dirs . slice ( 0 , index + 1 ) . join ( '/' ) } ` } ;
4537 } ) ;
4638
47- useEffect ( ( ) => load ( ) , [ ] ) ;
39+ useEffect ( ( ) => load ( ) , [ directory ] ) ;
4840
4941 return (
5042 < div className = { 'my-10 mb-6' } >
51- < FlashMessageRender byKey = { 'files' } />
43+ < FlashMessageRender byKey = { 'files' } className = { 'mb-4' } />
5244 < React . Fragment >
5345 < div className = { 'flex items-center text-sm mb-4 text-neutral-500' } >
5446 /< span className = { 'px-1 text-neutral-300' } > home</ span > /
55- < Link to = { '#' } className = { 'px-1 text-neutral-200 no-underline hover:text-neutral-100' } >
47+ < a
48+ href = { '#' }
49+ onClick = { ( ) => setDirectory ( '/' ) }
50+ className = { 'px-1 text-neutral-200 no-underline hover:text-neutral-100' }
51+ >
5652 container
57- </ Link > /
53+ </ a > /
5854 {
5955 breadcrumbs ( ) . map ( ( crumb , index ) => (
6056 crumb . path ?
6157 < React . Fragment key = { index } >
62- < Link
63- to = { `#${ crumb . path } ` }
58+ < a
59+ href = { `#${ crumb . path } ` }
60+ onClick = { ( ) => setDirectory ( crumb . path ! ) }
6461 className = { 'px-1 text-neutral-200 no-underline hover:text-neutral-100' }
6562 >
6663 { crumb . name }
67- </ Link > /
64+ </ a > /
6865 </ React . Fragment >
6966 :
7067 < span key = { index } className = { 'px-1 text-neutral-300' } > { crumb . name } </ span >
0 commit comments