import { useMemo, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { FileIcon, Folder } from "lucide-react"; import { listSnapshotFilesOptions } from "~/api-client/@tanstack/react-query.gen"; import { FileTree, type FileEntry } from "~/components/file-tree"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/components/ui/card"; import type { ListSnapshotsResponse } from "~/api-client/types.gen"; interface Props { snapshots: ListSnapshotsResponse; repositoryName: string; snapshotId: string; } export const SnapshotFileBrowser = (props: Props) => { const { snapshots, repositoryName, snapshotId } = props; const [expandedFolders, setExpandedFolders] = useState>(new Set([""])); const { data: filesData, isLoading: filesLoading } = useQuery({ ...listSnapshotFilesOptions({ path: { name: repositoryName, snapshotId }, query: { path: "/" }, }), }); const handleFolderExpand = (folderPath: string) => { const newFolders = new Set(expandedFolders); newFolders.add(folderPath); setExpandedFolders(newFolders); }; const selectedSnapshot = useMemo(() => { return snapshots.find((s) => s.short_id === snapshotId); }, [snapshotId, snapshots]); if (snapshots.length === 0) { return (

No snapshots

Snapshots are point-in-time backups of your data. The first snapshot will appear here after the next scheduled backup.

); } return (
File Browser {`Viewing snapshot from ${new Date(selectedSnapshot?.time ?? 0).toLocaleString()}`} {filesLoading && (

Loading files...

)} {filesData?.files.length === 0 && (

No files in this snapshot

)} {filesData?.files.length && (
)}
); };