import { useQuery } from "@tanstack/react-query"; import { redirect, useParams, Link } 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"; 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 = await getSnapshotDetails({ path: { id: params.id, snapshotId: params.snapshotId }, }); if (!snapshot.data) return redirect("/repositories"); const repository = await getRepository({ path: { id: params.id } }); if (!repository.data) return redirect("/repositories"); return { snapshot: snapshot.data, 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(), }); const backupIds = loaderData.tags.map(Number).filter((tag) => !Number.isNaN(tag)); const backup = schedules.data?.find((b) => backupIds.includes(b.id)); if (!id || !snapshotId) { return (
Invalid snapshot reference
Snapshot: {snapshotId}
{data.snapshot.id}
{data.snapshot.short_id}
{data.snapshot.hostname}
{new Date(data.snapshot.time).toLocaleString()}
{backup.name}
{backup.volume.name}
{path}
))}