@@ -160,12 +160,12 @@ export function Files() {
160160
161161 const [ uploading , setUploading ] = useState ( false )
162162 const [ uploadProgress , setUploadProgress ] = useState ( { completed : 0 , total : 0 } )
163+ const [ inputValue , setInputValue ] = useState ( '' )
163164 const [ debouncedSearchTerm , setDebouncedSearchTerm ] = useState ( '' )
164165 const searchTimerRef = useRef < ReturnType < typeof setTimeout > > ( null )
165- const searchValueRef = useRef ( '' )
166166
167167 const handleSearchChange = useCallback ( ( value : string ) => {
168- searchValueRef . current = value
168+ setInputValue ( value )
169169 if ( searchTimerRef . current ) clearTimeout ( searchTimerRef . current )
170170 searchTimerRef . current = setTimeout ( ( ) => {
171171 setDebouncedSearchTerm ( value )
@@ -175,7 +175,14 @@ export function Files() {
175175 const [ creatingFile , setCreatingFile ] = useState ( false )
176176 const [ isDirty , setIsDirty ] = useState ( false )
177177 const [ saveStatus , setSaveStatus ] = useState < SaveStatus > ( 'idle' )
178- const [ previewMode , setPreviewMode ] = useState < PreviewMode > ( 'preview' )
178+ const [ previewMode , setPreviewMode ] = useState < PreviewMode > ( ( ) => {
179+ if ( fileIdFromRoute ) {
180+ const file = files . find ( ( f ) => f . id === fileIdFromRoute )
181+ if ( file && isPreviewable ( file ) ) return 'preview'
182+ return 'editor'
183+ }
184+ return 'preview'
185+ } )
179186 const [ showUnsavedChangesAlert , setShowUnsavedChangesAlert ] = useState ( false )
180187 const [ showDeleteConfirm , setShowDeleteConfirm ] = useState ( false )
181188 const [ contextMenuFile , setContextMenuFile ] = useState < WorkspaceFileRecord | null > ( null )
@@ -284,7 +291,15 @@ export function Files() {
284291 } ,
285292 }
286293 } )
287- } , [ baseRows , listRename . editingId , listRename . editValue , filteredFiles ] )
294+ } , [
295+ baseRows ,
296+ listRename . editingId ,
297+ listRename . editValue ,
298+ listRename . setEditValue ,
299+ listRename . submitRename ,
300+ listRename . cancelRename ,
301+ filteredFiles ,
302+ ] )
288303
289304 const handleFileChange = useCallback (
290305 async ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -696,15 +711,18 @@ export function Files() {
696711
697712 const canEdit = userPermissions . canEdit === true
698713
714+ const handleSearchClearAll = useCallback ( ( ) => {
715+ handleSearchChange ( '' )
716+ } , [ handleSearchChange ] )
717+
699718 const searchConfig : SearchConfig = useMemo (
700719 ( ) => ( {
701- get value ( ) {
702- return searchValueRef . current
703- } ,
720+ value : inputValue ,
704721 onChange : handleSearchChange ,
722+ onClearAll : handleSearchClearAll ,
705723 placeholder : 'Search files...' ,
706724 } ) ,
707- [ handleSearchChange ]
725+ [ inputValue , handleSearchChange , handleSearchClearAll ]
708726 )
709727
710728 const createConfig = useMemo (
0 commit comments