11import React , { useEffect , useState } from 'react' ;
22import { ServerContext } from '@/state/server' ;
3- import { NavLink } from 'react-router-dom' ;
3+ import { NavLink , useLocation } from 'react-router-dom' ;
44import { cleanDirectoryPath } from '@/helpers' ;
55import tw from 'twin.macro' ;
66
@@ -14,14 +14,28 @@ export default ({ renderLeft, withinFileEditor, isNewFile }: Props) => {
1414 const [ file , setFile ] = useState < string | null > ( null ) ;
1515 const id = ServerContext . useStoreState ( state => state . server . data ! . id ) ;
1616 const directory = ServerContext . useStoreState ( state => state . files . directory ) ;
17+ const { hash } = useLocation ( ) ;
1718
1819 useEffect ( ( ) => {
19- const parts = cleanDirectoryPath ( window . location . hash ) . split ( '/' ) ;
20+ let pathHash = cleanDirectoryPath ( hash ) ;
21+ try {
22+ pathHash = decodeURI ( pathHash ) ;
23+ } catch ( e ) {
24+ console . warn ( 'Error decoding URL parts in hash:' , e ) ;
25+ }
2026
2127 if ( withinFileEditor && ! isNewFile ) {
22- setFile ( parts . pop ( ) || null ) ;
28+ let name = pathHash . split ( '/' ) . pop ( ) || null ;
29+ if ( name ) {
30+ try {
31+ name = decodeURIComponent ( name ) ;
32+ } catch ( e ) {
33+ console . warn ( 'Error decoding filename:' , e ) ;
34+ }
35+ }
36+ setFile ( name ) ;
2337 }
24- } , [ withinFileEditor , isNewFile ] ) ;
38+ } , [ withinFileEditor , isNewFile , hash ] ) ;
2539
2640 const breadcrumbs = ( ) : { name : string ; path ?: string } [ ] => directory . split ( '/' )
2741 . filter ( directory => ! ! directory )
@@ -51,16 +65,16 @@ export default ({ renderLeft, withinFileEditor, isNewFile }: Props) => {
5165 to = { `/server/${ id } /files#${ crumb . path } ` }
5266 css = { tw `px-1 text-neutral-200 no-underline hover:text-neutral-100` }
5367 >
54- { crumb . name }
68+ { decodeURIComponent ( crumb . name ) }
5569 </ NavLink > /
5670 </ React . Fragment >
5771 :
58- < span key = { index } css = { tw `px-1 text-neutral-300` } > { crumb . name } </ span >
72+ < span key = { index } css = { tw `px-1 text-neutral-300` } > { decodeURIComponent ( crumb . name ) } </ span >
5973 ) )
6074 }
6175 { file &&
6276 < React . Fragment >
63- < span css = { tw `px-1 text-neutral-300` } > { decodeURI ( file ) } </ span >
77+ < span css = { tw `px-1 text-neutral-300` } > { file } </ span >
6478 </ React . Fragment >
6579 }
6680 </ div >
0 commit comments