import { useQuery } from "@tanstack/react-query"; import { redirect, useParams, Link, Await } from "react-router"; import { listBackupSchedulesOptions, listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen"; import { Button } from "~/client/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { SnapshotFileBrowser } from "~/client/modules/backups/components/snapshot-file-browser"; import { formatDateTime } from "~/client/lib/datetime"; import { parseError } from "~/client/lib/errors"; import { getRepository, getSnapshotDetails } from "~/client/api-client"; import type { Route } from "./+types/snapshot-details"; import { Suspense } from "react"; import { Database } from "lucide-react"; export const handle = { breadcrumb: (match: Route.MetaArgs) => [ { label: "Repositories", href: "/repositories" }, { label: match.loaderData?.repository.name || match.params.id, href: `/repositories/${match.params.id}` }, { label: match.params.snapshotId }, ], }; export function meta({ params }: Route.MetaArgs) { return [ { title: `Zerobyte - Snapshot ${params.snapshotId}` }, { name: "description", content: "Browse and restore files from a backup snapshot.", }, ]; } export const clientLoader = async ({ params }: Route.ClientLoaderArgs) => { const [snapshot, repository] = await Promise.all([ getSnapshotDetails({ path: { id: params.id, snapshotId: params.snapshotId }, }), getRepository({ path: { id: params.id } }), ]); if (!repository.data) return redirect("/repositories"); return { snapshot: snapshot, repository: repository.data, snapshotError: parseError(snapshot.error)?.message ?? null, }; }; export default function SnapshotDetailsPage({ loaderData }: Route.ComponentProps) { const { id, snapshotId } = useParams<{ id: string; snapshotId: string; }>(); const { data } = useQuery({ ...listSnapshotFilesOptions({ path: { id: id ?? "", snapshotId: snapshotId ?? "" }, query: { path: "/" }, }), enabled: !!id && !!snapshotId && !loaderData.snapshotError, }); const schedules = useQuery({ ...listBackupSchedulesOptions(), }); if (!id || !snapshotId) { return (
Invalid snapshot reference
Snapshot not found
This snapshot does not exist in {loaderData.repository.name}.
It may have been deleted manually outside of Zerobyte.
Snapshot: {snapshotId}
{data.snapshot.id}
{data.snapshot.short_id}
{data.snapshot.hostname}
{formatDateTime(data.snapshot.time)}
{backupSchedule?.name}
{backupSchedule?.volume.name}
{path}
))}