@@ -3,6 +3,8 @@ import { ServerContext } from '@/state/server';
33import { 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' ;
68
79interface Props {
810 withinFileEditor ?: boolean ;
@@ -14,6 +16,10 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
1416 const id = ServerContext . useStoreState ( state => state . server . data ! . id ) ;
1517 const directory = ServerContext . useStoreState ( state => state . files . directory ) ;
1618
19+ const { data : files } = useFileManagerSwr ( ) ;
20+ const setSelectedFiles = ServerContext . useStoreActions ( actions => actions . files . setSelectedFiles ) ;
21+ const selectedFilesLength = ServerContext . useStoreState ( state => state . files . selectedFiles . length ) ;
22+
1723 useEffect ( ( ) => {
1824 const parts = cleanDirectoryPath ( window . location . hash ) . split ( '/' ) ;
1925
@@ -32,8 +38,20 @@ export default ({ withinFileEditor, isNewFile }: Props) => {
3238 return { name : decodeURIComponent ( directory ) , path : `/${ dirs . slice ( 0 , index + 1 ) . join ( '/' ) } ` } ;
3339 } ) ;
3440
41+ const onSelectAllClick = ( e : React . ChangeEvent < HTMLInputElement > ) => {
42+ setSelectedFiles ( e . currentTarget . checked ? ( files ?. map ( file => file . name ) || [ ] ) : [ ] ) ;
43+ } ;
44+
3545 return (
3646 < div css = { tw `flex items-center text-sm mb-4 text-neutral-500` } >
47+ { ! ! ( files && files . length ) &&
48+ < FileActionCheckbox
49+ type = { 'checkbox' }
50+ css = { tw `mx-4` }
51+ checked = { selectedFilesLength === ( files ? files . length : - 1 ) }
52+ onChange = { onSelectAllClick }
53+ />
54+ }
3755 /< span css = { tw `px-1 text-neutral-300` } > home</ span > /
3856 < NavLink
3957 to = { `/server/${ id } /files` }
0 commit comments