The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import dayjs from 'dayjs'
import { ArrowRightIcon, RotateCcwIcon, XIcon } from 'lucide-react'
import { Button } from 'ui'
import { FilePreview } from './FilePreview'
import type { ObjectVersion } from '@/data/storage/versioning/object-versions-query'
import { formatBytes } from '@/lib/helpers'
interface VersionCompareWidgetProps {
path: string
mimeType?: string
selectedVersion: ObjectVersion
currentVersion?: ObjectVersion
isRestoring: boolean
onRestore: () => void
onDismiss: () => void
}
export const VersionCompareWidget = ({
path,
mimeType,
selectedVersion,
currentVersion,
isRestoring,
onRestore,
onDismiss,
}: VersionCompareWidgetProps) => (
<div className="space-y-3 border-b border-overlay bg-brand-200/30 p-3">
<div className="flex items-center gap-x-1.5">
<RotateCcwIcon size={13} className="shrink-0 text-brand" />
<p className="truncate text-sm font-medium text-foreground">
Restore v.{selectedVersion.versionId}?
</p>
<button
type="button"
tabIndex={0}
className="ml-auto shrink-0 text-foreground-lighter transition-colors hover:text-foreground"
onClick={onDismiss}
aria-label="Cancel comparison"
>
<XIcon size={13} />
</button>
</div>
<div className="flex items-center gap-x-2">
<div className="flex-1 space-y-1.5">
<div className="flex h-24 items-center justify-center overflow-hidden rounded-md border border-brand-400 bg-surface-200">
<FilePreview
path={path}
// This half shows the older bytes, which an overwrite may have retyped.
mimeType={selectedVersion.mimeType ?? mimeType}
size={selectedVersion.size}
versionId={selectedVersion.versionId}
/>
</div>
<p className="truncate text-center font-mono text-xs text-brand">
{dayjs(selectedVersion.createdAt).format('MMM D')} · {formatBytes(selectedVersion.size)}
</p>
</div>
<ArrowRightIcon size={14} className="shrink-0 text-foreground-lighter" />
<div className="flex-1 space-y-1.5">
<div className="flex h-24 items-center justify-center overflow-hidden rounded-md border border-overlay bg-surface-200">
{/* No `versionId`, so the endpoint resolves the current version. */}
<FilePreview path={path} mimeType={mimeType} size={currentVersion?.size} />
</div>
<p className="truncate text-center font-mono text-xs text-foreground-lighter">
Current{currentVersion && <> · {formatBytes(currentVersion.size)}</>}
</p>
</div>
</div>
<Button
variant="primary"
block
icon={<RotateCcwIcon size={14} />}
loading={isRestoring}
onClick={onRestore}
>
Restore version as current
</Button>
<p className="text-xs leading-relaxed text-foreground-lighter">
{currentVersion && <strong>{currentVersion.versionId} </strong>}becomes a noncurrent version —
nothing is deleted.
</p>
</div>
)