From c0da075f030902c967ee1a05337b500f89376a9d Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 17 Mar 2026 14:45:00 +0100 Subject: [PATCH] feat(frontend): config history sheet with pin and restore --- .../components/config-history-sheet.tsx | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 k-tv-frontend/app/(main)/dashboard/components/config-history-sheet.tsx diff --git a/k-tv-frontend/app/(main)/dashboard/components/config-history-sheet.tsx b/k-tv-frontend/app/(main)/dashboard/components/config-history-sheet.tsx new file mode 100644 index 0000000..f29172d --- /dev/null +++ b/k-tv-frontend/app/(main)/dashboard/components/config-history-sheet.tsx @@ -0,0 +1,119 @@ +'use client' + +import { useState } from 'react' +import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { useConfigHistory, usePinSnapshot, useRestoreConfig } from '@/hooks/use-channels' +import { cn } from '@/lib/utils' + +interface Props { + channelId: string + open: boolean + onOpenChange: (open: boolean) => void +} + +export function ConfigHistorySheet({ channelId, open, onOpenChange }: Props) { + const { data: snapshots } = useConfigHistory(channelId) + const pin = usePinSnapshot() + const restore = useRestoreConfig() + const [pinningId, setPinningId] = useState(null) + const [pinLabel, setPinLabel] = useState('') + + return ( + + + + Config history + +
+ {(snapshots ?? []).map((snap, i) => ( +
+
+
+ v{snap.version_num} —{' '} + {new Date(snap.created_at).toLocaleString()} + {i === 0 && ( + + current + + )} +
+ {snap.label ? ( +
📌 {snap.label}
+ ) : ( +
Auto-saved
+ )} +
+ + {i === 0 && ( + pinningId === snap.id ? ( +
+ setPinLabel(e.target.value)} + className="h-7 text-xs w-32" + placeholder="label…" + onKeyDown={e => { + if (e.key === 'Enter') { + pin.mutate({ channelId, snapId: snap.id, label: pinLabel }) + setPinningId(null) + } + if (e.key === 'Escape') setPinningId(null) + }} + /> + + +
+ ) : ( + + ) + )} + + {i > 0 && ( + + )} +
+ ))} + {(snapshots ?? []).length === 0 && ( +

+ No history yet. History is created automatically when you save changes. +

+ )} +
+
+
+ ) +}