@@ -2,7 +2,7 @@ import { RefreshIcon } from "~/components/ui/refresh-icon";
22import { Spinner } from "~/components/ui/spinner" ;
33import type { EnvironmentId } from "@t3tools/contracts" ;
44import { ArrowLeftIcon , ChevronRightIcon } from "lucide-react" ;
5- import { useEffect , useMemo , useState } from "react" ;
5+ import { useState } from "react" ;
66
77import { PierreEntryIcon } from "~/components/chat/PierreEntryIcon" ;
88import {
@@ -94,10 +94,7 @@ function BreadcrumbMenuContent(props: {
9494 const { resolvedTheme } = useTheme ( ) ;
9595 const entries = entriesQuery . data ?. entries ?? [ ] ;
9696 const entriesTruncated = entriesQuery . data ?. truncated ?? false ;
97- const children = useMemo (
98- ( ) => fileBreadcrumbChildren ( entries , props . directoryPath ) ,
99- [ entries , props . directoryPath ] ,
100- ) ;
97+ const children = fileBreadcrumbChildren ( entries , props . directoryPath ) ;
10198 const directoryAvailable = entriesQuery . data !== null ;
10299 const parentPath = fileBreadcrumbParent ( props . directoryPath ) ;
103100 const canGoBack =
@@ -222,11 +219,16 @@ function BreadcrumbMenuContent(props: {
222219function FolderContentsMenu ( props : FileBreadcrumbsProps & { readonly crumb : FileBreadcrumb } ) {
223220 const [ open , setOpen ] = useState ( false ) ;
224221 const [ directoryPath , setDirectoryPath ] = useState ( props . crumb . path ) ;
225-
226- useEffect ( ( ) => {
222+ // Opening another file or moving the crumb closes the menu and returns it to the crumb's folder.
223+ const [ shownFor , setShownFor ] = useState ( {
224+ crumbPath : props . crumb . path ,
225+ relativePath : props . relativePath ,
226+ } ) ;
227+ if ( shownFor . crumbPath !== props . crumb . path || shownFor . relativePath !== props . relativePath ) {
228+ setShownFor ( { crumbPath : props . crumb . path , relativePath : props . relativePath } ) ;
227229 setOpen ( false ) ;
228230 setDirectoryPath ( props . crumb . path ) ;
229- } , [ props . crumb . path , props . relativePath ] ) ;
231+ }
230232
231233 const handleOpenChange = ( nextOpen : boolean ) => {
232234 setOpen ( nextOpen ) ;
@@ -299,10 +301,7 @@ function FolderBreadcrumb(props: {
299301 */
300302export function FileBreadcrumbs ( props : FileBreadcrumbsProps ) {
301303 const hostPath = isAbsolutePath ( props . relativePath ) ;
302- const breadcrumbs = useMemo (
303- ( ) => fileBreadcrumbs ( props . projectName , props . trail ) ,
304- [ props . projectName , props . trail ] ,
305- ) ;
304+ const breadcrumbs = fileBreadcrumbs ( props . projectName , props . trail ) ;
306305 const currentPath = breadcrumbPathOf ( props . relativePath ) ;
307306 const currentIndex = breadcrumbs . findIndex ( ( crumb ) => crumb . path === currentPath ) ;
308307
0 commit comments