11import React , { useEffect , useState } from 'react' ;
22import { ServerContext } from '@/state/server' ;
3- import { NavLink , useRouteMatch } from 'react-router-dom' ;
3+ import { NavLink } from 'react-router-dom' ;
44import { cleanDirectoryPath } from '@/helpers' ;
55import tw from 'twin.macro' ;
6- import { FileActionCheckbox } from '@/components/server/files/SelectFileCheckbox' ;
7- import useFileManagerSwr from '@/plugins/useFileManagerSwr' ;
86
97interface Props {
8+ renderLeft ?: JSX . Element ;
109 withinFileEditor ?: boolean ;
1110 isNewFile ?: boolean ;
1211}
1312
14- export default ( { withinFileEditor, isNewFile } : Props ) => {
13+ export default ( { renderLeft , withinFileEditor, isNewFile } : Props ) => {
1514 const [ file , setFile ] = useState < string | null > ( null ) ;
16- const { params } = useRouteMatch < Record < string , string > > ( ) ;
1715 const id = ServerContext . useStoreState ( state => state . server . data ! . id ) ;
1816 const directory = ServerContext . useStoreState ( state => state . files . directory ) ;
1917
20- const { data : files } = useFileManagerSwr ( ) ;
21- const setSelectedFiles = ServerContext . useStoreActions ( actions => actions . files . setSelectedFiles ) ;
22- const selectedFilesLength = ServerContext . useStoreState ( state => state . files . selectedFiles . length ) ;
23-
2418 useEffect ( ( ) => {
2519 const parts = cleanDirectoryPath ( window . location . hash ) . split ( '/' ) ;
2620
@@ -39,22 +33,9 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
3933 return { name : directory , path : `/${ dirs . slice ( 0 , index + 1 ) . join ( '/' ) } ` } ;
4034 } ) ;
4135
42- const onSelectAllClick = ( e : React . ChangeEvent < HTMLInputElement > ) => {
43- setSelectedFiles ( e . currentTarget . checked ? ( files ?. map ( file => file . name ) || [ ] ) : [ ] ) ;
44- } ;
45-
4636 return (
4737 < div css = { tw `flex flex-grow-0 items-center text-sm text-neutral-500 overflow-x-hidden` } >
48- { ( files && files . length > 0 && ! params ?. action ) ?
49- < FileActionCheckbox
50- type = { 'checkbox' }
51- css = { tw `mx-4` }
52- checked = { selectedFilesLength === ( files ? files . length : - 1 ) }
53- onChange = { onSelectAllClick }
54- />
55- :
56- < div css = { tw `w-12` } />
57- }
38+ { renderLeft || < div css = { tw `w-12` } /> }
5839 /< span css = { tw `px-1 text-neutral-300` } > home</ span > /
5940 < NavLink
6041 to = { `/server/${ id } /files` }
0 commit comments