@@ -71,12 +71,12 @@ function ScrollSpy(props) {
7171
7272
7373const FilesList = memo ( ( props : any ) => {
74- const { structure, setDirty, selectFile, selectedFileId, webAudio} = props ;
74+ const { structure, setDirty, isDirty , selectFile, selectedFileId, webAudio} = props ;
7575
7676 return (
7777 < ul className = "files-browser" > {
7878 structure . files . length === 0 ?
79- < li className = "status" > { gettext ( "Empty folder" ) } </ li > : (
79+ ( ! isDirty && < li className = "status" > { gettext ( "Empty folder" ) } </ li > ) : (
8080 < > { structure . files . map ( file => (
8181 < li key = { file . id } onClick = { ( ) => selectFile ( file ) } >
8282 < Figure { ...file } webAudio = { webAudio } isSelected = { file . id === selectedFileId } />
@@ -197,6 +197,13 @@ const FileSelectDialog = forwardRef((props: any, forwardedRef) => {
197197 const response = await fetch ( `${ baseUrl } structure/${ realm } ${ params . size === 0 ? '' : `?${ params . toString ( ) } ` } ` ) ;
198198 if ( response . ok ) {
199199 setStructure ( await response . json ( ) ) ;
200+ window . setTimeout ( ( ) => {
201+ // first show the structure from the root for orientation, then scroll to the current folder
202+ const currentListItem = ref . current . querySelector ( 'ul[role="navigation"] li:has(>[aria-current="true"]' ) ;
203+ if ( currentListItem ) {
204+ currentListItem . scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
205+ }
206+ } , 999 ) ;
200207 } else {
201208 console . error ( response ) ;
202209 }
@@ -324,17 +331,20 @@ const FileSelectDialog = forwardRef((props: any, forwardedRef) => {
324331 handleUpload = { handleUpload }
325332 ref = { uploaderRef }
326333 settings = { { csrf_token : csrfToken , base_url : baseUrl } }
327- > {
328- structure . files === null ?
329- < div className = "status" > { gettext ( "Loading files…" ) } </ div > :
334+ > { Array . isArray ( structure . files ) ?
330335 < FilesList
331336 structure = { structure }
332337 setDirty = { setDirty }
338+ isDirty = { isDirty }
333339 selectFile = { selectFile }
334340 selectedFileId = { props . selectedFileId }
335341 webAudio = { webAudio }
336342 />
337- } </ FileUploader >
343+ :
344+ < div className = "status" > { gettext ( "Loading structure…" ) } </ div >
345+ }
346+ { isDirty && < div className = "status" > { gettext ( "Loading files…" ) } </ div > }
347+ </ FileUploader >
338348 </ div >
339349 </ > }
340350 </ div >
0 commit comments