Files
kandev/apps/web/components/task/file-browser-load-state.tsx
T
2026-07-23 20:02:20 +01:00

51 lines
1.4 KiB
TypeScript

"use client";
import { PanelLoadingState } from "@/components/panel-loading-state";
import type { FileTreeNode } from "@/lib/types/backend";
import { WorkspaceUnavailable } from "./workspace-unavailable";
type RenderSessionOrLoadStateInput = {
isSessionFailed: boolean;
sessionError: string | null | undefined;
loadState: string;
isLoadingTree: boolean;
tree: FileTreeNode | null;
loadError: string | null;
onRetry: () => void;
};
export function renderSessionOrLoadState({
isSessionFailed,
sessionError,
loadState,
isLoadingTree,
tree,
loadError,
onRetry,
}: RenderSessionOrLoadStateInput) {
if (isSessionFailed) {
return <WorkspaceUnavailable error={sessionError} />;
}
if ((loadState === "loading" || isLoadingTree) && !tree) {
return <PanelLoadingState label="Loading files..." />;
}
if (loadState === "waiting") {
return <PanelLoadingState testId="file-tree-waiting" label="Preparing workspace..." />;
}
if (loadState === "manual") {
return (
<div data-testid="file-tree-manual" className="p-4 text-sm text-muted-foreground space-y-2">
<div>{loadError ?? "Workspace is still starting."}</div>
<button
type="button"
className="text-xs text-foreground underline cursor-pointer"
onClick={onRetry}
>
Retry
</button>
</div>
);
}
return null;
}