@@ -25,22 +25,12 @@ type SearchResult = {
2525 } ;
2626}
2727
28- interface FileSearchCommandDialogProps {
29- repoName : string ;
30- revisionName ?: string ;
31- isOpen : boolean ;
32- onOpenChange : ( isOpen : boolean ) => void ;
33- onSelect : ( file : FileTreeItem ) => void ;
34- }
3528
36- export const FileSearchCommandDialog = ( {
37- repoName,
38- revisionName,
39- isOpen,
40- onOpenChange,
41- onSelect : _onSelect ,
42- } : FileSearchCommandDialogProps ) => {
29+ export const FileSearchCommandDialog = ( ) => {
30+ const { repoName, revisionName } = useBrowseParams ( ) ;
4331 const domain = useDomain ( ) ;
32+ const { state : { isFileSearchOpen } , updateBrowseState } = useBrowseState ( ) ;
33+
4434 const commandListRef = useRef < HTMLDivElement > ( null ) ;
4535 const inputRef = useRef < HTMLInputElement > ( null ) ;
4636 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
@@ -50,7 +40,9 @@ export const FileSearchCommandDialog = ({
5040
5141 useHotkeys ( "mod+p" , ( event ) => {
5242 event . preventDefault ( ) ;
53- onOpenChange ( ! isOpen ) ;
43+ updateBrowseState ( {
44+ isFileSearchOpen : ! isFileSearchOpen ,
45+ } ) ;
5446 } , {
5547 enableOnFormTags : true ,
5648 enableOnContentEditable : true ,
@@ -59,15 +51,15 @@ export const FileSearchCommandDialog = ({
5951
6052 // Whenever we open the dialog, clear the search query
6153 useEffect ( ( ) => {
62- if ( isOpen ) {
54+ if ( isFileSearchOpen ) {
6355 setSearchQuery ( '' ) ;
6456 }
65- } , [ isOpen ] ) ;
57+ } , [ isFileSearchOpen ] ) ;
6658
6759 const { data : files , isLoading, isError } = useQuery ( {
6860 queryKey : [ 'files' , repoName , revisionName , domain ] ,
6961 queryFn : ( ) => unwrapServiceError ( getFiles ( { repoName, revisionName : revisionName ?? 'HEAD' } , domain ) ) ,
70- enabled : isOpen ,
62+ enabled : isFileSearchOpen ,
7163 } ) ;
7264
7365 const { filteredFiles, maxResultsHit } = useMemo ( ( ) : { filteredFiles : SearchResult [ ] ; maxResultsHit : boolean } => {
@@ -117,9 +109,16 @@ export const FileSearchCommandDialog = ({
117109 const filtered = prev . filter ( f => f . path !== file . path ) ;
118110 return [ file , ...filtered ] ;
119111 } ) ;
120- onOpenChange ( false ) ;
121- _onSelect ( file ) ;
122- } , [ setRecentlyOpened , onOpenChange , _onSelect ] ) ;
112+ navigateToPath ( {
113+ repoName,
114+ revisionName,
115+ path : file . path ,
116+ pathType : 'blob' ,
117+ } ) ;
118+ updateBrowseState ( {
119+ isFileSearchOpen : false ,
120+ } ) ;
121+ } , [ navigateToPath , repoName , revisionName , setRecentlyOpened , updateBrowseState ] ) ;
123122
124123 // @note : We were hitting issues when the user types into the input field while the files are still
125124 // loading. The workaround was to set `disabled` when loading and then focus the input field when
@@ -132,9 +131,11 @@ export const FileSearchCommandDialog = ({
132131
133132 return (
134133 < Dialog
135- open = { isOpen }
134+ open = { isFileSearchOpen }
136135 onOpenChange = { ( isOpen ) => {
137- onOpenChange ( isOpen ) ;
136+ updateBrowseState ( {
137+ isFileSearchOpen : isOpen ,
138+ } ) ;
138139 } }
139140 modal = { true }
140141 >
0 commit comments