@@ -44,12 +44,15 @@ const fileQueryOptions = (repo: string, branch: string, filePath: string) => {
4444const repoDirApiContentsQueryOptions = (
4545 repo : string ,
4646 branch : string ,
47- startingPath : string
47+ startingPath : string ,
48+ candidateStartingFilePath : string
4849) =>
4950 queryOptions ( {
5051 queryKey : [ 'repo-api-contents' , repo , branch , startingPath ] ,
5152 queryFn : ( ) =>
52- fetchRepoDirectoryContents ( { data : { repo, branch, startingPath } } ) ,
53+ fetchRepoDirectoryContents ( {
54+ data : { repo, branch, startingPath, candidateStartingFilePath } ,
55+ } ) ,
5356 } )
5457
5558export const Route = createFileRoute (
@@ -85,38 +88,40 @@ export const Route = createFileRoute(
8588 )
8689
8790 // Used for fetching the file content of the initial file
88- const sandboxStartingFilePath = `examples/${ examplePath } /${ sandboxFirstFileName } `
91+ const explorerStartingFilePath = `examples/${ examplePath } /${ sandboxFirstFileName } `
8992
9093 // Used to indicate from where should the directory tree start.
9194 // i.e. from `examples/react/quickstart` or `examples/react/quickstart/src`
92- const directoryStartingPath = `examples/${ examplePath } ${ sandboxFirstDirectory } `
95+ const explorerDirectoryStartingPath = `examples/${ examplePath } ${ sandboxFirstDirectory } `
9396
9497 await Promise . allSettled ( [
9598 queryClient . ensureQueryData (
96- fileQueryOptions ( library . repo , branch , sandboxStartingFilePath )
99+ fileQueryOptions ( library . repo , branch , explorerStartingFilePath )
97100 ) ,
98101 queryClient . ensureQueryData (
99102 repoDirApiContentsQueryOptions (
100103 library . repo ,
101104 branch ,
102- directoryStartingPath
105+ explorerDirectoryStartingPath ,
106+ explorerStartingFilePath
103107 )
104108 ) ,
105109 ] )
106110
107111 return {
108- directoryStartingPath ,
109- sandboxStartingFilePath ,
112+ explorerDirectoryStartingPath ,
113+ explorerStartingFilePath ,
110114 }
111115 } ,
116+ staleTime : 1000 * 60 * 5 , // 5 minutes
112117} )
113118
114119const bannedDefaultOpenFolders = new Set ( [ 'public' , '.vscode' , 'tests' , 'spec' ] )
115120
116121function RouteComponent ( ) {
117122 // Not sure why this inferred type is not working
118123 // @ts -expect-error
119- const { directoryStartingPath , sandboxStartingFilePath } =
124+ const { explorerDirectoryStartingPath , explorerStartingFilePath } =
120125 Route . useLoaderData ( )
121126
122127 const navigate = Route . useNavigate ( )
@@ -132,8 +137,15 @@ function RouteComponent() {
132137 libraryId
133138 )
134139
135- const { data : gitHubFiles } = useSuspenseQuery (
136- repoDirApiContentsQueryOptions ( library . repo , branch , directoryStartingPath )
140+ const {
141+ data : { githubContents, startingFilePath } ,
142+ } = useSuspenseQuery (
143+ repoDirApiContentsQueryOptions (
144+ library . repo ,
145+ branch ,
146+ explorerDirectoryStartingPath ,
147+ explorerStartingFilePath
148+ )
137149 )
138150
139151 const [ isDark , setIsDark ] = React . useState ( true )
@@ -160,7 +172,9 @@ function RouteComponent() {
160172 }
161173
162174 const currentPath = Route . useSearch ( {
163- select : ( s ) => s . path || sandboxStartingFilePath ,
175+ select : ( s ) => {
176+ return s . path || startingFilePath || explorerStartingFilePath
177+ } ,
164178 } )
165179
166180 const setCurrentPath = ( path : string ) => {
@@ -194,8 +208,8 @@ function RouteComponent() {
194208 const [ expandedFolders , setExpandedFolders ] = React . useState < Set < string > > (
195209 ( ) => {
196210 const expanded = new Set < string > ( )
197- if ( gitHubFiles ) {
198- gitHubFiles . forEach ( ( file : GitHubFileNode ) => {
211+ if ( githubContents ) {
212+ githubContents . forEach ( ( file : GitHubFileNode ) => {
199213 if (
200214 file . type === 'dir' &&
201215 file . depth === 0 &&
@@ -457,10 +471,10 @@ function RouteComponent() {
457471 isResizing ? '' : 'transition-all duration-300'
458472 } ${ isSidebarOpen ? '' : 'w-0 pr-0' } `}
459473 >
460- { gitHubFiles && isSidebarOpen ? (
474+ { githubContents && isSidebarOpen ? (
461475 < div className = "p-2" >
462476 < RenderFileTree
463- files = { gitHubFiles }
477+ files = { githubContents }
464478 libraryColor = { libraryColor }
465479 toggleFolder = { toggleFolder }
466480 prefetchFileContent = { prefetchFileContent }
0 commit comments