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 { Card, CardContent, CardHeader, CardTitle } from "~/client/components/ui/card"; import { SnapshotFileBrowser } from "~/client/modules/backups/components/snapshot-file-browser"; import { getRepository, getSnapshotDetails } from "~/client/api-client"; import type { Route } from "./+types/snapshot-details"; import { Suspense } from "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 = getSnapshotDetails({ path: { id: params.id, snapshotId: params.snapshotId }, }); const repository = await getRepository({ path: { id: params.id } }); if (!repository.data) return redirect("/repositories"); return { snapshot: snapshot, repository: repository.data }; }; 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, }); const schedules = useQuery({ ...listBackupSchedulesOptions(), }); if (!id || !snapshotId) { return (

Invalid snapshot reference

); } return (

{loaderData.repository.name}

Snapshot: {snapshotId}

} > {(value) => { if (!value.data) return
Snapshot data not found.
; return ; }}
{data?.snapshot && ( Snapshot Information
Snapshot ID:

{data.snapshot.id}

Short ID:

{data.snapshot.short_id}

Hostname:

{data.snapshot.hostname}

Time:

{new Date(data.snapshot.time).toLocaleString()}

Loading...
}> {(value) => { if (!value.data) return null; const backupSchedule = schedules.data?.find((s) => value.data.tags.includes(s.shortId)); return ( <>
Backup Schedule:

{backupSchedule?.name}

Volume:

{backupSchedule?.volume.name}

); }}
Paths:
{data.snapshot.paths.map((path) => (

{path}

))}
)} ); }