Open History to see the last commit
1import { thrownErrorMessage } from "@t3tools/client-runtime/errors";
2import { m } from "~/i18n/messages";
3import { RefreshIcon } from "~/components/ui/refresh-icon";
4import type {
5 ContextMenuItem as TreeContextMenuItem,
6 ContextMenuOpenContext as TreeContextMenuOpenContext,
7} from "@pierre/trees";
8import type { EnvironmentId, ProjectEntry } from "@t3tools/contracts";
9import { FileTree, useFileTree, useFileTreeSearch, useFileTreeSelector } from "@pierre/trees/react";
10import { settlePromise } from "@t3tools/client-runtime/state/runtime";
11import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
12import * as AsyncResult from "effect/reactivity/AsyncResult";
13import * as Cause from "effect/Cause";
14import { T, useGT, useMessages } from "gt-react";
15import { ChevronsDownUpIcon, ChevronsUpDownIcon } from "lucide-react";
16import { type Ref, useEffect, useEffectEvent, useRef, useState } from "react";
17
18import { Button } from "~/components/ui/button";
19import { InputGroup, InputGroupInput } from "~/components/ui/input-group";
20import { toastManager } from "~/components/ui/toast";
21import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
22import { useComposerHandleContext } from "~/composerHandleContext";
23import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
24import { useStableCallback } from "~/hooks/useStableCallback";
25import { useTheme } from "~/hooks/useTheme";
26import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";
27import { useFileContextMenu, type FileContextMenuAction } from "~/fileContextMenu";
28import { readLocalApi } from "~/localApi";
29import { T3_PIERRE_ICONS } from "~/pierre-icons";
30import { PIERRE_TREE_UNSAFE_CSS, pierreTreeStyle } from "~/pierre-tree-theme";
31
32import { joinHostPath } from "./filePath";
33import { createFileTreeDragMentionController } from "./fileTreeDragMention";
34import {
35 areAllDirectoriesExpanded,
36 coalesceReentrantCalls,
37 readExpandedDirectories,
38 setAllDirectoriesExpanded,
39 writeExpandedDirectories,
40} from "./fileTreeExpansion";
41import { buildFileTreePathUpdates, shouldRebuildFileTree } from "./fileTreePathReconciliation";
42import { loadFileAncestors } from "./loadFileAncestors";
43import { useDirectoryEntries } from "./useDirectoryEntries";
44import { useProjectPathSearch } from "~/state/queries";
45import { isMacPlatform } from "~/lib/utils";
46import { type PreviewAction, subscribePreviewAction } from "../preview/previewActionBus";
47
48interface FileBrowserPanelProps {
49 environmentId: EnvironmentId;
50 cwd: string;
51 projectName: string;
52 selectedPath: string | null;
53 selectedPathRevealId: number;
54 onOpenFile: (relativePath: string) => void;
55 /** Host-folder entries use absolute paths. Avoid full traversal: disable expand-all and search only
56 * loaded folders. */
57 hostFolder?: boolean;
58 onRefreshSelectedFile?: () => void;
59 workspaceMutationId: string | null;
60 answersPanelFind?: boolean;
61}
62
63function treePath(entry: ProjectEntry): string {
64 return entry.kind === "directory" ? `${entry.path}/` : entry.path;
65}
66
67function RefreshFilesButton(props: { isPending: boolean; onRefresh: () => void }) {
68 const gt = useGT();
69 return (
70 <Tooltip>
71 <TooltipTrigger
72 render={
73 <Button
74 type="button"
75 variant="ghost"
76 size="icon-xs"
77 aria-label={gt("Refresh workspace files")}
78 onClick={props.onRefresh}
79 />
80 }
81 >
82 <RefreshIcon refreshing={props.isPending} />
83 </TooltipTrigger>
84 <TooltipPopup>{props.isPending ? gt("Refreshing…") : gt("Refresh files")}</TooltipPopup>
85 </Tooltip>
86 );
87}
88
89function FileSearchField({
90 ref,
91 ...props
92}: {
93 ariaLabel: string;
94 name: string;
95 onClose: () => void;
96 onValueChange: (value: string) => void;
97 ref: Ref<HTMLInputElement>;
98 value: string;
99}) {
100 const gt = useGT();
101 return (
102 <InputGroup variant="ghost" className="h-7 min-w-0 flex-1">
103 <InputGroupInput
104 ref={ref}
105 type="search"
106 name={props.name}
107 size="sm"
108 value={props.value}
109 aria-label={props.ariaLabel}
110 placeholder={gt("Search files")}
111 data-workspace-focus-default
112 spellCheck={false}
113 onChange={(event) => props.onValueChange(event.target.value)}
114 onKeyDown={(event) => {
115 if (event.key !== "Escape") return;
116 props.onClose();
117 event.currentTarget.blur();
118 }}
119 />
120 </InputGroup>
121 );
122}
123
124function buildTreeEntries(
125 directoryEntries: readonly ProjectEntry[],
126 searchEntries: readonly ProjectEntry[],
127 searchPending: boolean,
128 query: string,
129) {
130 const result = new Map(directoryEntries.map((entry) => [entry.path, entry]));
131 if (query.trim() && !searchPending) {
132 for (const entry of searchEntries) {
133 if (!result.has(entry.path)) result.set(entry.path, entry);
134 const segments = entry.path.split("/");
135 for (let index = 1; index < segments.length; index++) {
136 const path = segments.slice(0, index).join("/");
137 if (!result.has(path)) result.set(path, { path, kind: "directory" });
138 }
139 }
140 }
141 const entries = [...result.values()];
142 const entryKinds: ReadonlyMap<string, ProjectEntry["kind"]> = new Map(
143 entries.map((entry) => [entry.path, entry.kind] as const),
144 );
145 const treePaths = entries.map(treePath);
146 const directories = entries.filter((entry) => entry.kind === "directory");
147 const directoryPaths = directories.map(treePath);
148 // Expanding a folder lists it, and an ignored one such as `node_modules` can hold tens of
149 // thousands, so expand all skips ignored folders. They still open by hand.
150 const expandableDirectoryPaths = directories.filter((entry) => !entry.ignored).map(treePath);
151 return { entries, entryKinds, treePaths, directoryPaths, expandableDirectoryPaths };
152}
153
154export default function FileBrowserPanel({
155 environmentId,
156 cwd,
157 projectName,
158 selectedPath,
159 selectedPathRevealId,
160 onOpenFile,
161 onRefreshSelectedFile,
162 workspaceMutationId,
163 hostFolder = false,
164 answersPanelFind = false,
165}: FileBrowserPanelProps) {
166 const panelPath = (relativePath: string) =>
167 hostFolder ? joinHostPath(cwd, relativePath) : relativePath;
168 const gt = useGT();
169 const messages = useMessages();
170 const { resolvedTheme } = useTheme();
171 const composerRef = useComposerHandleContext();
172 const fileContextMenu = useFileContextMenu(environmentId);
173 const {
174 entries: directoryEntries,
175 load,
176 refresh,
177 ready,
178 error,
179 isPending,
180 loadingDirectories,
181 } = useDirectoryEntries(environmentId, cwd);
182 const [query, setQuery] = useState("");
183 const [expandAll, setExpandAll] = useState(false);
184 const pathSearch = useProjectPathSearch(
185 { environmentId, cwd: hostFolder ? null : cwd, query: query.slice(0, 256) },
186 200,
187 undefined,
188 messages,
189 );
190 const { entries, entryKinds, treePaths, directoryPaths, expandableDirectoryPaths } =
191 buildTreeEntries(directoryEntries, pathSearch.entries, pathSearch.isPending, query);
192 const entryKindsRef = useRef(entryKinds);
193 const previousTreePathsRef = useRef<readonly string[] | null>(null);
194 const syncingSelectionRef = useRef(false);
195 const treeSelectionPathRef = useRef<string | null>(null);
196 const handledRevealRef = useRef<{ path: string; revealId: number } | null>(null);
197
198 // Shadow-DOM row rects are unreliable; capture the composed contextmenu event's viewport position.
199 const contextMenuPointerRef = useRef<{ x: number; y: number; at: number } | null>(null);
200
201 const showEntryContextMenu = useStableCallback(
202 (item: TreeContextMenuItem, context: TreeContextMenuOpenContext) => {
203 const api = readLocalApi();
204 if (!api) {
205 context.close();
206 return;
207 }
208 const relativePath = item.path.replace(/\/$/, "");
209 const mention = serializeComposerFileLink(panelPath(relativePath));
210 const pointer = contextMenuPointerRef.current;
211 const pointerIsFresh = pointer !== null && performance.now() - pointer.at < 1000;
212 const anchorRect = context.anchorElement.getBoundingClientRect();
213 const position = pointerIsFresh
214 ? { x: pointer.x, y: pointer.y }
215 : { x: anchorRect.left, y: anchorRect.bottom };
216 const fileTarget = { environmentId, filePath: relativePath, workspaceRoot: cwd };
217 const fileMenuItems = fileContextMenu.buildItems(fileTarget);
218 // The app menu owns focus; the tree's outside-click handler would dismiss it before click.
219 context.close({ restoreFocus: !pointerIsFresh });
220 void settlePromise(async () => {
221 const clicked = await api.contextMenu.show(
222 [
223 ...fileMenuItems,
224 { id: "copy-mention", label: gt("Copy mention") },
225 { id: "add-to-chat", label: gt("Add to chat") },
226 ],
227 position,
228 );
229 if (clicked === null) return;
230 // Open-with submenu ids are absent from the top-level item list.
231 const isFileMenuAction =
232 fileMenuItems.some((entry) => entry.id === clicked) || clicked.startsWith("editor:");
233 if (isFileMenuAction) {
234 await fileContextMenu.activate(clicked as FileContextMenuAction, fileTarget);
235 return;
236 }
237 if (clicked === "copy-mention") {
238 try {
239 await writeTextToClipboard(mention);
240 } catch (error) {
241 toastManager.add({
242 type: "error",
243 title: gt("Failed to copy mention"),
244 description: thrownErrorMessage(error, m) ?? gt("An error occurred."),
245 });
246 }
247 return;
248 }
249 if (clicked === "add-to-chat") {
250 const composer = composerRef?.current;
251 if (!composer) {
252 toastManager.add({
253 type: "error",
254 title: gt("Unable to add to chat"),
255 description: gt("Open a chat for this project and try again."),
256 });
257 return;
258 }
259 const inserted = composer.insertTextAtEnd(`${mention} `, { ensureLeadingBoundary: true });
260 if (!inserted) {
261 toastManager.add({
262 type: "error",
263 title: gt("Unable to add to chat"),
264 description: gt("The chat isn't ready to accept input right now."),
265 });
266 }
267 }
268 }).then((result) => {
269 if (!AsyncResult.isSuccess(result)) throw Cause.squash(result.cause);
270 });
271 },
272 );
273
274 const loadingDirectoriesRef = useRef(loadingDirectories);
275 const dragMention = createFileTreeDragMentionController(
276 hostFolder ? { mentionPath: (path: string) => joinHostPath(cwd, path) } : {},
277 );
278 const { model } = useFileTree({
279 composition: {
280 contextMenu: {
281 triggerMode: "right-click",
282 onOpen: (item, context) => {
283 showEntryContextMenu(item, context);
284 },
285 },
286 },
287 dragAndDrop: { canDrop: () => false },
288 density: "compact",
289 fileTreeSearchMode: "hide-non-matches",
290 flattenEmptyDirectories: true,
291 initialExpansion: "closed",
292 icons: T3_PIERRE_ICONS,
293 onSelectionChange: (selectedPaths) => {
294 // Update drag selection even for reveals so subsequent drags cannot use stale paths.
295 dragMention.handleSelectionChange(selectedPaths);
296 if (syncingSelectionRef.current) return;
297 if (dragMention.isDragInProgress()) {
298 return;
299 }
300 const selectedPath = selectedPaths.at(-1)?.replace(/\/$/, "");
301 if (selectedPath && entryKindsRef.current.get(selectedPath) === "file") {
302 treeSelectionPathRef.current = selectedPath;
303 onOpenFile(panelPath(selectedPath));
304 }
305 },
306 paths: [],
307 renderRowDecoration: ({ item, row }) =>
308 row.kind === "directory" &&
309 row.isExpanded &&
310 loadingDirectoriesRef.current.has(item.path.replace(/\/$/, ""))
311 ? { icon: "t3-tree-icon-loading", title: gt("Loading…") }
312 : null,
313 search: false,
314 onSearchChange: (value) => setQuery(value ?? ""),
315 unsafeCSS: PIERRE_TREE_UNSAFE_CSS,
316 });
317 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- makes the Pierre tree model re-render row decorations when loading directories change
318 useEffect(() => {
319 if (loadingDirectoriesRef.current === loadingDirectories) return;
320 loadingDirectoriesRef.current = loadingDirectories;
321 model.setComposition(model.getComposition());
322 }, [loadingDirectories, model]);
323 const search = useFileTreeSearch(model);
324 // Pierre restores the unfiltered tree when a search has no matches.
325 const hasNoSearchMatches = search.value.trim().length > 0 && search.matchingPaths.length === 0;
326 const allDirectoriesExpanded = useFileTreeSelector(model, (currentModel) =>
327 areAllDirectoriesExpanded(currentModel, expandableDirectoryPaths),
328 );
329 const toggleAllDirectories = () => {
330 const expanded = !(expandAll || allDirectoriesExpanded);
331 setExpandAll(expanded);
332 setAllDirectoriesExpanded(
333 model,
334 expanded ? expandableDirectoryPaths : directoryPaths,
335 expanded,
336 );
337 };
338 const closeSearch = () => {
339 setQuery("");
340 search.close();
341 };
342 const searchInputRef = useRef<HTMLInputElement>(null);
343 const focusSearch = () => {
344 searchInputRef.current?.focus();
345 searchInputRef.current?.select();
346 };
347 const onPanelAction = useEffectEvent((action: PreviewAction) => {
348 // Hidden panel tabs stay mounted; only the visible Files tab answers.
349 if (action === "find" && searchInputRef.current?.getClientRects().length) focusSearch();
350 });
351 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the panel find command, which fires while focus is anywhere in the right panel
352 useEffect(() => {
353 if (!answersPanelFind) return;
354 return subscribePreviewAction(onPanelAction);
355 }, [answersPanelFind]);
356 const expandedPathsRef = useRef(new Set<string>());
357 const expansionRoot = `${environmentId}:${cwd}`;
358 // Folders expanded when the panel last unmounted; each reopens once lazy loading lists it.
359 const [pendingExpandedPaths] = useState(() => new Set(readExpandedDirectories(expansionRoot)));
360 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the Pierre tree model to load directories as they are expanded
361 useEffect(() => {
362 const currentPaths = new Set(directoryPaths);
363 for (const path of expandedPathsRef.current) {
364 if (!currentPaths.has(path)) expandedPathsRef.current.delete(path);
365 }
366 // Restoring calls item.expand(), which notifies subscribers synchronously.
367 const loadExpanded = coalesceReentrantCalls(() => {
368 if (model.isSearchOpen()) return;
369 let changed = false;
370 for (const path of directoryPaths) {
371 const item = model.getItem(path);
372 if (item?.isDirectory() && pendingExpandedPaths.delete(path) && "expand" in item) {
373 item.expand();
374 }
375 if (item?.isDirectory() && "isExpanded" in item && item.isExpanded()) {
376 if (!expandedPathsRef.current.has(path)) {
377 expandedPathsRef.current.add(path);
378 changed = true;
379 void load(path.replace(/\/$/, ""));
380 }
381 } else {
382 if (item?.isDirectory() && expandedPathsRef.current.has(path)) setExpandAll(false);
383 if (expandedPathsRef.current.delete(path)) changed = true;
384 }
385 }
386 if (changed) {
387 writeExpandedDirectories(expansionRoot, [
388 ...expandedPathsRef.current,
389 ...pendingExpandedPaths,
390 ]);
391 }
392 });
393 loadExpanded();
394 return model.subscribe(loadExpanded);
395 }, [directoryPaths, expansionRoot, load, model, pendingExpandedPaths]);
396 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- pushes ignored-file status into the imperative Pierre tree model
397 useEffect(() => {
398 model.setGitStatus(
399 entries
400 .filter((entry) => entry.ignored)
401 .map((entry) => ({
402 path: treePath(entry),
403 status: "ignored",
404 })),
405 );
406 }, [entries, model]);
407 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- loads the selected file's ancestor directories and aborts on cleanup
408 useEffect(() => {
409 if (!selectedPath) return;
410 const controller = new AbortController();
411 void loadFileAncestors(selectedPath, load, { signal: controller.signal });
412 return () => {
413 controller.abort();
414 };
415 }, [load, selectedPath]);
416 const handleSearchValueChange = (value: string) => {
417 setQuery(value);
418 if (value.trim().length === 0) {
419 search.close();
420 return;
421 }
422 search.setValue(value);
423 };
424 const handleRefresh = () => {
425 refresh();
426 if (query.trim()) pathSearch.refresh();
427 onRefreshSelectedFile?.();
428 };
429 useWorkspaceMutationRefresh({
430 mutationId: workspaceMutationId,
431 refresh: () => {
432 refresh();
433 if (query.trim()) pathSearch.refresh();
434 },
435 resourceKey: `files:${environmentId}:${cwd}`,
436 });
437
438 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- applies tree path changes to the imperative Pierre tree model as a reset or batch update
439 useEffect(() => {
440 if (!ready) return;
441 if (previousTreePathsRef.current === treePaths) return;
442 entryKindsRef.current = entryKinds;
443 const previousTreePaths = previousTreePathsRef.current;
444 previousTreePathsRef.current = treePaths;
445 if (previousTreePaths === null) {
446 model.resetPaths(treePaths);
447 return;
448 }
449 const updates = buildFileTreePathUpdates(previousTreePaths, treePaths);
450 if (shouldRebuildFileTree(previousTreePaths, treePaths, updates)) {
451 // A reset keeps old search matches, so search closes first and recomputes afterwards.
452 const activeSearch = model.isSearchOpen() ? model.getSearchValue() : null;
453 if (activeSearch !== null) model.closeSearch();
454 model.resetPaths(treePaths, { initialExpandedPaths: [...expandedPathsRef.current] });
455 if (activeSearch !== null) model.setSearch(activeSearch);
456 return;
457 }
458 if (updates.length > 0) model.batch(updates);
459 }, [ready, entryKinds, model, treePaths]);
460
461 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- expands every directory in the Pierre tree model while expand-all is on and no search is active
462 useEffect(() => {
463 if (expandAll && !query.trim())
464 setAllDirectoriesExpanded(model, expandableDirectoryPaths, true);
465 }, [expandableDirectoryPaths, expandAll, model, query]);
466
467 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals an externally selected path in the Pierre tree model by expanding, selecting and scrolling
468 useEffect(() => {
469 if (!selectedPath) {
470 handledRevealRef.current = null;
471 return;
472 }
473 const selectedKind = entryKinds.get(selectedPath);
474 if (selectedKind === undefined) {
475 handledRevealRef.current = null;
476 return;
477 }
478 const revealRequest = { path: selectedPath, revealId: selectedPathRevealId };
479 const handledReveal = handledRevealRef.current;
480 // Refresh rebuilds treePaths; replaying handled reveals would close search and steal focus.
481 if (
482 handledReveal?.path === revealRequest.path &&
483 handledReveal.revealId === revealRequest.revealId
484 ) {
485 return;
486 }
487 const selectedTreePath = selectedKind === "directory" ? `${selectedPath}/` : selectedPath;
488 const selectedItem = model.getItem(selectedTreePath);
489 if (!selectedItem) return;
490
491 // Reveal only external selections; tree selections are visible and re-revealing would close search.
492 const selectedInTree = model
493 .getSelectedPaths()
494 .some((path) => path.replace(/\/$/, "") === selectedPath);
495 if (selectedInTree && treeSelectionPathRef.current === selectedPath) {
496 treeSelectionPathRef.current = null;
497 handledRevealRef.current = revealRequest;
498 return;
499 }
500 treeSelectionPathRef.current = null;
501 handledRevealRef.current = revealRequest;
502
503 syncingSelectionRef.current = true;
504 setQuery("");
505 model.closeSearch();
506 for (const path of model.getSelectedPaths()) {
507 model.getItem(path)?.deselect();
508 }
509
510 // Directory paths include trailing slashes; ancestor lookups must match.
511 const segments = selectedPath.split("/");
512 let ancestorPath = "";
513 for (const segment of segments.slice(0, -1)) {
514 ancestorPath = ancestorPath ? `${ancestorPath}/${segment}` : segment;
515 const item = model.getItem(`${ancestorPath}/`) ?? model.getItem(ancestorPath);
516 if (item && "expand" in item) item.expand();
517 }
518
519 if ("expand" in selectedItem) selectedItem.expand();
520 selectedItem.select();
521 model.scrollToPath(selectedTreePath, {
522 focus: true,
523 offset: "center",
524 });
525 queueMicrotask(() => {
526 syncingSelectionRef.current = false;
527 });
528 }, [entryKinds, model, selectedPath, selectedPathRevealId]);
529
530 return (
531 <div
532 className="flex min-h-0 flex-1 flex-col bg-background"
533 data-file-browser-panel={`${environmentId}:${cwd}`}
534 // Capture runs before the tree's shadow-internal row handler opens the menu.
535 onContextMenuCapture={(event) => {
536 contextMenuPointerRef.current = { x: event.clientX, y: event.clientY, at: event.timeStamp };
537 }}
538 // Capture dragstart before the tree selects the row so selection sees the drag flag.
539 onDragStartCapture={(event) => dragMention.handleDragStart(event.nativeEvent)}
540 onDragEnd={() => dragMention.handleDragEnd((path) => model.getItem(path)?.deselect())}
541 onKeyDown={(event) => {
542 const isModPressed = isMacPlatform(navigator.platform) ? event.metaKey : event.ctrlKey;
543 if (!isModPressed || event.altKey || event.shiftKey || event.key.toLowerCase() !== "f")
544 return;
545 event.preventDefault();
546 focusSearch();
547 }}
548 >
549 <div
550 className="flex h-10 min-h-10 shrink-0 items-center gap-1 border-b border-border/60 bg-background px-2 in-data-[preview-panel-mode=inline]:mb-1 in-data-[preview-panel-mode=inline]:h-9 in-data-[preview-panel-mode=inline]:min-h-9 in-data-[preview-panel-mode=inline]:border-b-transparent"
551 data-surface-subheader
552 >
553 <RefreshFilesButton isPending={isPending} onRefresh={handleRefresh} />
554 <FileSearchField
555 ref={searchInputRef}
556 name="project-files-search"
557 ariaLabel={gt("Search {projectName} files", { projectName })}
558 value={search.value}
559 onValueChange={handleSearchValueChange}
560 onClose={closeSearch}
561 />
562 {directoryPaths.length > 0 && !hostFolder ? (
563 <Tooltip>
564 <TooltipTrigger
565 render={
566 <Button
567 type="button"
568 size="icon-xs"
569 variant="ghost"
570 aria-label={
571 expandAll || allDirectoriesExpanded
572 ? gt("Collapse all folders")
573 : gt("Expand all folders")
574 }
575 onClick={toggleAllDirectories}
576 />
577 }
578 >
579 {allDirectoriesExpanded ? (
580 <ChevronsDownUpIcon className="size-3.5" />
581 ) : (
582 <ChevronsUpDownIcon className="size-3.5" />
583 )}
584 </TooltipTrigger>
585 <TooltipPopup>
586 {expandAll || allDirectoriesExpanded
587 ? gt("Collapse all folders")
588 : gt("Expand all folders")}
589 </TooltipPopup>
590 </Tooltip>
591 ) : null}
592 </div>
593 {error || pathSearch.error ? (
594 <button
595 type="button"
596 onClick={handleRefresh}
597 className="p-4 text-left text-xs leading-relaxed text-destructive"
598 >
599 {gt("{error} Click to retry.", { error: error ?? pathSearch.error })}
600 </button>
601 ) : null}
602 {query.trim() && pathSearch.truncated && !pathSearch.isPending ? (
603 <div className="px-3 py-1 text-xs text-muted-foreground">
604 <T>More matches available. Refine your search.</T>
605 </div>
606 ) : null}
607 {(!ready || pathSearch.isPending) && (
608 <div
609 role="status"
610 className={
611 entries.length > 0 && !hasNoSearchMatches
612 ? "sr-only"
613 : "px-3 py-1 text-xs text-muted-foreground"
614 }
615 >
616 <T>Loading files…</T>
617 </div>
618 )}
619 {hasNoSearchMatches ? (
620 ready && !isPending && !pathSearch.isPending && !error && !pathSearch.error ? (
621 <div role="status" className="px-3 py-4 text-xs text-muted-foreground">
622 <T>No matching files.</T>
623 </div>
624 ) : null
625 ) : (
626 <FileTree
627 model={model}
628 aria-label={gt("{projectName} files", { projectName })}
629 className="min-h-0 flex-1 overflow-hidden"
630 style={pierreTreeStyle(resolvedTheme)}
631 />
632 )}
633 </div>
634 );
635}