11import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
22import { faFileAlt , faFileArchive , faFileImport , faFolder } from '@fortawesome/free-solid-svg-icons' ;
3- import { bytesToHuman , cleanDirectoryPath } from '@/helpers' ;
3+ import { bytesToHuman , encodePathSegments } from '@/helpers' ;
44import { differenceInHours , format , formatDistanceToNow } from 'date-fns' ;
55import React , { memo } from 'react' ;
66import { FileObject } from '@/api/server/files/loadDirectory' ;
77import FileDropdownMenu from '@/components/server/files/FileDropdownMenu' ;
88import { ServerContext } from '@/state/server' ;
9- import { NavLink , useHistory , useRouteMatch } from 'react-router-dom' ;
9+ import { NavLink , useRouteMatch } from 'react-router-dom' ;
1010import tw from 'twin.macro' ;
1111import isEqual from 'react-fast-compare' ;
1212import styled from 'styled-components/macro' ;
1313import SelectFileCheckbox from '@/components/server/files/SelectFileCheckbox' ;
1414import { usePermissions } from '@/plugins/usePermissions' ;
15+ import { join } from 'path' ;
1516
1617const Row = styled . div `
1718 ${ tw `flex bg-neutral-700 rounded-sm mb-px text-sm hover:text-neutral-100 cursor-pointer items-center no-underline hover:bg-neutral-600` } ;
@@ -21,33 +22,17 @@ const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
2122 const [ canReadContents ] = usePermissions ( [ 'file.read-content' ] ) ;
2223 const directory = ServerContext . useStoreState ( state => state . files . directory ) ;
2324
24- const history = useHistory ( ) ;
2525 const match = useRouteMatch ( ) ;
2626
27- const destination = cleanDirectoryPath ( `${ directory } /${ file . name } ` ) . split ( '/' ) . join ( '/' ) ;
28-
29- const onRowClick = ( e : React . MouseEvent < HTMLAnchorElement , MouseEvent > ) => {
30- // Don't rely on the onClick to work with the generated URL. Because of the way this
31- // component re-renders you'll get redirected into a nested directory structure since
32- // it'll cause the directory variable to update right away when you click.
33- //
34- // Just trust me future me, leave this be.
35- if ( ! file . isFile ) {
36- e . preventDefault ( ) ;
37- history . push ( `#${ destination } ` ) ;
38- }
39- } ;
40-
4127 return (
4228 ( ! canReadContents || ( file . isFile && ! file . isEditable ( ) ) ) ?
4329 < div css = { tw `flex flex-1 text-neutral-300 no-underline p-3 cursor-default overflow-hidden truncate` } >
4430 { children }
4531 </ div >
4632 :
4733 < NavLink
48- to = { `${ match . url } ${ file . isFile ? '/edit' : '' } #${ destination } ` }
34+ to = { `${ match . url } ${ file . isFile ? '/edit' : '' } #${ encodePathSegments ( join ( directory , file . name ) ) } ` }
4935 css = { tw `flex flex-1 text-neutral-300 no-underline p-3 overflow-hidden truncate` }
50- onClick = { onRowClick }
5136 >
5237 { children }
5338 </ NavLink >
@@ -72,7 +57,7 @@ const FileObjectRow = ({ file }: { file: FileObject }) => (
7257 }
7358 </ div >
7459 < div css = { tw `flex-1 truncate` } >
75- { decodeURIComponent ( file . name ) }
60+ { file . name }
7661 </ div >
7762 { file . isFile &&
7863 < div css = { tw `w-1/6 text-right mr-4 hidden sm:block` } >
0 commit comments