asset viewer now viewing on tabs

Tabs is better for this yay

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-28 19:34:10 +08:00
parent 5b784ca87c
commit 05f27e34d7
26 changed files with 1679 additions and 351 deletions
@@ -1,7 +1,8 @@
// modules/admin/pages/assets/ViewAudioAsset.jsx
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { ArrowLeft, Lock, Globe, Music2, Pencil } from "lucide-react";
import { Lock, Globe, Music2, Pencil, Info } from "lucide-react";
import { useDateFormat } from "@/hooks/useDateFormat";
import { useAssetFetchState } from "@/hooks/useAssetFetchState";
@@ -9,24 +10,16 @@ import { useAssetPreviewSrc } from "@/hooks/useAssetPreviewSrc";
import { formatFileSize } from "@/utils/format.util";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { AudioBlock } from "@/components/generic/Blocks/Admin/AudioBlock";
import { MediaFallback } from "@/components/generic/MediaFallback";
import AssetPageLoader from "@/components/generic/AssetLoader";
import DetailTabsHeader from "@/components/generic/DetailTabsHeader";
import { SectionCard, InfoRow } from "@/components/generic/DetailSectionCard";
// ─── Shared meta row (same pattern as other viewers) ─────────────────────────
function MetaRow({ label, value }) {
if (!value && value !== 0) return null;
return (
<div className="flex items-start gap-3 py-2">
<span className="text-muted-foreground text-sm w-36 shrink-0">{label}</span>
<span className="text-sm font-medium break-all">{String(value)}</span>
</div>
);
}
// ─── Page ─────────────────────────────────────────────────────────────────────
const TABS = [
{ key: "preview", label: "Preview", icon: Music2 },
{ key: "info", label: "File Info", icon: Info },
];
export default function ViewAudioAsset() {
const { assetId } = useParams();
@@ -35,6 +28,7 @@ export default function ViewAudioAsset() {
const { asset: selectedAsset, loading, notFound } = useAssetFetchState(assetId);
const { src: streamUrl, thumbnailUrl } = useAssetPreviewSrc(selectedAsset, { scope: "admin" });
const [activeTab, setActiveTab] = useState("preview");
if (loading) {
return <AssetPageLoader />;
@@ -60,75 +54,82 @@ export default function ViewAudioAsset() {
};
return (
<div className="max-w-7xl mx-auto px-4 py-6 space-y-6">
<div className="flex flex-col min-h-screen bg-muted/60">
<DetailTabsHeader
icon={Music2}
title={a.display_name ?? a.original_name}
subtitle={a.mime_type}
onBack={() => navigate("/admin/assets")}
tabs={TABS}
activeTab={activeTab}
onTabChange={setActiveTab}
actions={
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
}
/>
{/* ── Header ── */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" onClick={() => navigate("/admin/assets")}>
<ArrowLeft className="h-4 w-4" />
</Button>
<div className="flex-1 min-w-0">
<h1 className="text-xl font-semibold truncate">{a.display_name ?? a.original_name}</h1>
<p className="text-sm text-muted-foreground">{a.mime_type}</p>
</div>
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
</div>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-6">
{/* ── Audio player ── */}
<div className="lg:col-span-3 space-y-4">
{streamUrl ? (
<div className="lg:container lg:mx-auto lg:px-6 px-4 py-6">
{activeTab === "preview" ? (
streamUrl ? (
<AudioBlock content={audioContent} />
) : (
<MediaFallback className="size-full" />
)}
</div>
)
) : (
<div className="max-w-3xl mx-auto space-y-5 pb-16">
<SectionCard icon={Info} title="File Info">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Original Name">{a.original_name}</InfoRow>
<InfoRow label="Extension">{a.extension}</InfoRow>
<InfoRow label="File Size">{formatFileSize(a.file_size)}</InfoRow>
<InfoRow label="MIME Type">{a.mime_type}</InfoRow>
</div>
</SectionCard>
{/* ── Metadata panel ── */}
<div className="lg:col-span-2 space-y-4">
<div className="rounded-lg border bg-card p-4 space-y-1">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">File Info</p>
<MetaRow label="Original Name" value={a.original_name} />
<MetaRow label="Extension" value={a.extension} />
<MetaRow label="File Size" value={formatFileSize(a.file_size)} />
<MetaRow label="MIME Type" value={a.mime_type} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Storage</p>
<MetaRow label="Provider" value={a.storage_provider} />
<MetaRow label="Bucket" value={a.storage_bucket} />
<MetaRow label="Key" value={a.storage_key} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Access</p>
<div className="flex items-center gap-2 py-1">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<MetaRow label="Access Level" value={a.access_level} />
<MetaRow label="Owner Type" value={a.owner_type} />
<MetaRow label="Owner ID" value={a.owner_id} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Timestamps</p>
<MetaRow label="Created By" value={a.creator?.full_name ?? a.createdBy} />
<MetaRow label="Created" value={a.createdAt ? fmtDateTime(a.createdAt) : null} />
<MetaRow label="Modified By" value={a.updater?.full_name ?? a.updatedBy} />
<MetaRow label="Modified" value={a.updatedAt ? fmtDateTime(a.updatedAt) : null} />
<SectionCard icon={Music2} title="Storage">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Provider">{a.storage_provider}</InfoRow>
<InfoRow label="Bucket">{a.storage_bucket}</InfoRow>
<InfoRow label="Key">{a.storage_key}</InfoRow>
</div>
</SectionCard>
<SectionCard icon={Lock} title="Access">
<div className="space-y-4">
<div className="flex items-center gap-2">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Access Level">{a.access_level}</InfoRow>
<InfoRow label="Owner Type">{a.owner_type}</InfoRow>
<InfoRow label="Owner ID">{a.owner_id}</InfoRow>
</div>
</div>
</SectionCard>
<SectionCard icon={Info} title="Timestamps">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Created By">{a.creator?.full_name ?? a.createdBy}</InfoRow>
<InfoRow label="Created">{a.createdAt ? fmtDateTime(a.createdAt) : null}</InfoRow>
<InfoRow label="Modified By">{a.updater?.full_name ?? a.updatedBy}</InfoRow>
<InfoRow label="Modified">{a.updatedAt ? fmtDateTime(a.updatedAt) : null}</InfoRow>
</div>
</SectionCard>
{a.description && (
<SectionCard icon={Info} title="Description">
<p className="text-sm text-foreground">{a.description}</p>
</SectionCard>
)}
</div>
{a.description && (
<div className="rounded-lg border bg-card p-4">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Description</p>
<p className="text-sm text-foreground">{a.description}</p>
</div>
)}
</div>
)}
</div>
</div>
);
}
}
@@ -1,7 +1,8 @@
// modules/admin/pages/assets/ViewDocumentAsset.jsx
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { ArrowLeft, Lock, Globe, FileText, Pencil } from "lucide-react";
import { Lock, Globe, FileText, Pencil, Info } from "lucide-react";
import { useDateFormat } from "@/hooks/useDateFormat";
import { useAssetFetchState } from "@/hooks/useAssetFetchState";
@@ -9,22 +10,18 @@ import { useAssetPreviewSrc } from "@/hooks/useAssetPreviewSrc";
import { formatFileSize } from "@/utils/format.util";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import FileZoomViewer from "@/components/generic/FileZoomViewer";
import AssetPageLoader from "@/components/generic/AssetLoader";
function MetaRow({ label, value }) {
if (!value && value !== 0) return null;
return (
<div className="flex items-start gap-3 py-2">
<span className="text-muted-foreground text-sm w-36 shrink-0">{label}</span>
<span className="text-sm font-medium break-all">{String(value)}</span>
</div>
);
}
import DetailTabsHeader from "@/components/generic/DetailTabsHeader";
import { SectionCard, InfoRow } from "@/components/generic/DetailSectionCard";
const PREVIEWABLE = ["pdf", "txt", "html", "htm", "csv", "md"];
const TABS = [
{ key: "preview", label: "Preview", icon: FileText },
{ key: "info", label: "File Info", icon: Info },
];
export default function ViewDocumentAsset() {
const { assetId } = useParams();
const navigate = useNavigate();
@@ -32,6 +29,7 @@ export default function ViewDocumentAsset() {
const { asset: selectedAsset, loading, notFound } = useAssetFetchState(assetId);
const { src: streamUrl, loading: previewLoading } = useAssetPreviewSrc(selectedAsset, { scope: "admin" });
const [activeTab, setActiveTab] = useState("preview");
if (loading) {
return <AssetPageLoader />;
@@ -52,34 +50,33 @@ export default function ViewDocumentAsset() {
const isPdf = ext === "pdf";
return (
<div className="max-w-7xl mx-auto px-4 py-6 space-y-6">
<div className="flex flex-col min-h-screen bg-muted/60">
<DetailTabsHeader
icon={FileText}
title={a.display_name ?? a.original_name}
subtitle={a.mime_type}
onBack={() => navigate("/admin/assets")}
tabs={TABS}
activeTab={activeTab}
onTabChange={setActiveTab}
actions={
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
}
/>
{/* ── Header ── */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" onClick={() => navigate("/admin/assets")}>
<ArrowLeft className="h-4 w-4" />
</Button>
<div className="flex-1 min-w-0">
<h1 className="text-xl font-semibold truncate">{a.display_name ?? a.original_name}</h1>
<p className="text-sm text-muted-foreground">{a.mime_type}</p>
</div>
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
</div>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-6">
{/* ── Document preview ── */}
<div className="lg:col-span-3">
{isPdf ? (
<div className="rounded-lg border overflow-hidden">
<div className={`lg:container lg:mx-auto lg:px-6 px-4 py-6 flex flex-col${activeTab === "preview" ? " flex-1 min-h-0" : ""}`}>
{activeTab === "preview" ? (
isPdf ? (
<div className="rounded-lg border overflow-hidden flex flex-col flex-1 min-h-0">
<FileZoomViewer
src={streamUrl}
mimeType={a.mime_type}
fileName={a.display_name ?? a.original_name}
loading={previewLoading}
canvasClassName="flex-1 min-h-[500px]"
/>
</div>
) : canPreview && streamUrl ? (
@@ -98,49 +95,59 @@ export default function ViewDocumentAsset() {
Preview not available for this file type.
</p>
</div>
)}
</div>
)
) : (
<div className="max-w-3xl mx-auto space-y-5 pb-16">
<SectionCard icon={Info} title="File Info">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Original Name">{a.original_name}</InfoRow>
<InfoRow label="Extension">{a.extension}</InfoRow>
<InfoRow label="File Size">{formatFileSize(a.file_size)}</InfoRow>
<InfoRow label="MIME Type">{a.mime_type}</InfoRow>
</div>
</SectionCard>
{/* ── Metadata panel ── */}
<div className="lg:col-span-2 space-y-4">
<div className="rounded-lg border bg-card p-4 space-y-1">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">File Info</p>
<MetaRow label="Original Name" value={a.original_name} />
<MetaRow label="Extension" value={a.extension} />
<MetaRow label="File Size" value={formatFileSize(a.file_size)} />
<MetaRow label="MIME Type" value={a.mime_type} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Storage</p>
<MetaRow label="Provider" value={a.storage_provider} />
<MetaRow label="Bucket" value={a.storage_bucket} />
<MetaRow label="Key" value={a.storage_key} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Access</p>
<div className="flex items-center gap-2 py-1">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<MetaRow label="Access Level" value={a.access_level} />
<MetaRow label="Owner Type" value={a.owner_type} />
<MetaRow label="Owner ID" value={a.owner_id} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Timestamps</p>
<MetaRow label="Created By" value={a.creator?.full_name ?? a.createdBy} />
<MetaRow label="Created" value={a.createdAt ? fmtDateTime(a.createdAt) : null} />
<MetaRow label="Modified By" value={a.updater?.full_name ?? a.updatedBy} />
<MetaRow label="Modified" value={a.updatedAt ? fmtDateTime(a.updatedAt) : null} />
<SectionCard icon={FileText} title="Storage">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Provider">{a.storage_provider}</InfoRow>
<InfoRow label="Bucket">{a.storage_bucket}</InfoRow>
<InfoRow label="Key">{a.storage_key}</InfoRow>
</div>
</SectionCard>
<SectionCard icon={Lock} title="Access">
<div className="space-y-4">
<div className="flex items-center gap-2">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Access Level">{a.access_level}</InfoRow>
<InfoRow label="Owner Type">{a.owner_type}</InfoRow>
<InfoRow label="Owner ID">{a.owner_id}</InfoRow>
</div>
</div>
</SectionCard>
<SectionCard icon={Info} title="Timestamps">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Created By">{a.creator?.full_name ?? a.createdBy}</InfoRow>
<InfoRow label="Created">{a.createdAt ? fmtDateTime(a.createdAt) : null}</InfoRow>
<InfoRow label="Modified By">{a.updater?.full_name ?? a.updatedBy}</InfoRow>
<InfoRow label="Modified">{a.updatedAt ? fmtDateTime(a.updatedAt) : null}</InfoRow>
</div>
</SectionCard>
{a.description && (
<SectionCard icon={Info} title="Description">
<p className="text-sm text-foreground">{a.description}</p>
</SectionCard>
)}
</div>
{a.description && (
<div className="rounded-lg border bg-card p-4">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Description</p>
<p className="text-sm text-foreground">{a.description}</p>
</div>
)}
</div>
)}
</div>
</div>
);
}
}
@@ -2,7 +2,7 @@
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { ArrowLeft, Lock, Globe, Pencil, Download } from "lucide-react";
import { Image, Info, Lock, Globe, Pencil, Download } from "lucide-react";
import { useDateFormat } from "@/hooks/useDateFormat";
import { useAssetFetchState } from "@/hooks/useAssetFetchState";
@@ -11,20 +11,15 @@ import { formatFileSize } from "@/utils/format.util";
import { downloadAsset } from "@/utils/media.util";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import FileZoomViewer from "@/components/generic/FileZoomViewer";
import AssetPageLoader from "@/components/generic/AssetLoader";
import DetailTabsHeader from "@/components/generic/DetailTabsHeader";
import { SectionCard, InfoRow } from "@/components/generic/DetailSectionCard";
function MetaRow({ label, value }) {
if (!value && value !== 0) return null;
return (
<div className="flex items-start gap-3 py-2">
<span className="text-muted-foreground text-sm w-36 shrink-0">{label}</span>
<span className="text-sm font-medium break-all">{String(value)}</span>
</div>
);
}
const TABS = [
{ key: "preview", label: "Preview", icon: Image },
{ key: "info", label: "File Info", icon: Info },
];
export default function ViewImageAsset() {
const { assetId } = useParams();
@@ -34,6 +29,7 @@ export default function ViewImageAsset() {
const { asset: selectedAsset, loading, notFound } = useAssetFetchState(assetId);
const { src: streamUrl, loading: previewLoading } = useAssetPreviewSrc(selectedAsset, { scope: "admin" });
const [downloading, setDownloading] = useState(false);
const [activeTab, setActiveTab] = useState("preview");
async function handleDownload() {
setDownloading(true);
@@ -60,79 +56,92 @@ export default function ViewImageAsset() {
const a = selectedAsset;
return (
<div className="max-w-7xl mx-auto px-4 py-6 space-y-6">
<div className="flex flex-col min-h-screen bg-muted/60">
<DetailTabsHeader
icon={Image}
title={a.display_name ?? a.original_name}
subtitle={a.mime_type}
onBack={() => navigate("/admin/assets")}
tabs={TABS}
activeTab={activeTab}
onTabChange={setActiveTab}
actions={
<>
<Button variant="outline" className="hidden" onClick={handleDownload} disabled={downloading}>
<Download className="h-3.5 w-3.5" />
{downloading ? "Downloading…" : "Download"}
</Button>
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
</>
}
/>
{/* ── Header ── */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" onClick={() => navigate("/admin/assets")}>
<ArrowLeft className="h-4 w-4" />
</Button>
<div className="flex-1 min-w-0">
<h1 className="text-xl font-semibold truncate">{a.display_name ?? a.original_name}</h1>
<p className="text-sm text-muted-foreground">{a.mime_type}</p>
</div>
<Button variant="outline" className="hidden" onClick={handleDownload} disabled={downloading}>
<Download className="h-3.5 w-3.5" />
{downloading ? "Downloading…" : "Download"}
</Button>
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
</div>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-6">
{/* ── Image preview ── */}
<div className="lg:col-span-3 rounded-lg border overflow-hidden">
<FileZoomViewer
src={streamUrl}
mimeType={a.mime_type}
fileName={a.display_name ?? a.original_name}
loading={previewLoading}
/>
</div>
{/* ── Metadata panel ── */}
<div className="lg:col-span-2 space-y-4">
<div className="rounded-lg border bg-card p-4 space-y-1">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">File Info</p>
<MetaRow label="Original Name" value={a.original_name} />
<MetaRow label="Extension" value={a.extension} />
<MetaRow label="File Size" value={formatFileSize(a.file_size)} />
<MetaRow label="Resolution" value={a.resolution} />
<MetaRow label="Dimensions" value={a.width && a.height ? `${a.width} × ${a.height}` : null} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Storage</p>
<MetaRow label="Provider" value={a.storage_provider} />
<MetaRow label="Bucket" value={a.storage_bucket} />
<MetaRow label="Key" value={a.storage_key} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Access</p>
<div className="flex items-center gap-2 py-1">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<MetaRow label="Access Level" value={a.access_level} />
<MetaRow label="Owner Type" value={a.owner_type} />
<MetaRow label="Owner ID" value={a.owner_id} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Timestamps</p>
<MetaRow label="Created By" value={a.creator?.full_name ?? a.createdBy} />
<MetaRow label="Created" value={a.createdAt ? fmtDateTime(a.createdAt) : null} />
<MetaRow label="Modified By" value={a.updater?.full_name ?? a.updatedBy} />
<MetaRow label="Modified" value={a.updatedAt ? fmtDateTime(a.updatedAt) : null} />
<div className={`lg:container lg:mx-auto lg:px-6 px-4 py-6 flex flex-col${activeTab === "preview" ? " flex-1 min-h-0" : ""}`}>
{activeTab === "preview" ? (
<div className="rounded-lg border overflow-hidden flex flex-col flex-1 min-h-0">
<FileZoomViewer
src={streamUrl}
mimeType={a.mime_type}
fileName={a.display_name ?? a.original_name}
loading={previewLoading}
canvasClassName="flex-1 min-h-[500px]"
/>
</div>
) : (
<div className="max-w-3xl mx-auto space-y-5 pb-16">
<SectionCard icon={Info} title="File Info">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Original Name">{a.original_name}</InfoRow>
<InfoRow label="Extension">{a.extension}</InfoRow>
<InfoRow label="File Size">{formatFileSize(a.file_size)}</InfoRow>
<InfoRow label="Resolution">{a.resolution}</InfoRow>
<InfoRow label="Dimensions">{a.width && a.height ? `${a.width} × ${a.height}` : null}</InfoRow>
</div>
</SectionCard>
{a.description && (
<div className="rounded-lg border bg-card p-4">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Description</p>
<p className="text-sm text-foreground">{a.description}</p>
</div>
)}
</div>
<SectionCard icon={Image} title="Storage">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Provider">{a.storage_provider}</InfoRow>
<InfoRow label="Bucket">{a.storage_bucket}</InfoRow>
<InfoRow label="Key">{a.storage_key}</InfoRow>
</div>
</SectionCard>
<SectionCard icon={Lock} title="Access">
<div className="space-y-4">
<div className="flex items-center gap-2">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Access Level">{a.access_level}</InfoRow>
<InfoRow label="Owner Type">{a.owner_type}</InfoRow>
<InfoRow label="Owner ID">{a.owner_id}</InfoRow>
</div>
</div>
</SectionCard>
<SectionCard icon={Info} title="Timestamps">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Created By">{a.creator?.full_name ?? a.createdBy}</InfoRow>
<InfoRow label="Created">{a.createdAt ? fmtDateTime(a.createdAt) : null}</InfoRow>
<InfoRow label="Modified By">{a.updater?.full_name ?? a.updatedBy}</InfoRow>
<InfoRow label="Modified">{a.updatedAt ? fmtDateTime(a.updatedAt) : null}</InfoRow>
</div>
</SectionCard>
{a.description && (
<SectionCard icon={Info} title="Description">
<p className="text-sm text-foreground">{a.description}</p>
</SectionCard>
)}
</div>
)}
</div>
</div>
);
@@ -1,27 +1,24 @@
// modules/admin/pages/assets/ViewVideoAsset.jsx
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { ArrowLeft, Lock, Globe, Pencil } from "lucide-react";
import { Lock, Globe, Pencil, Video, Info } from "lucide-react";
import { useDateFormat } from "@/hooks/useDateFormat";
import { useAssetFetchState } from "@/hooks/useAssetFetchState";
import { formatFileSize, formatPlayerTime } from "@/utils/format.util";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { VideoBlock } from "@/components/generic/Blocks/Admin/VideoBlock";
import { TranscodeStatusBanner } from "@/components/generic/TranscodeStatusBanner";
import AssetPageLoader from "@/components/generic/AssetLoader";
import DetailTabsHeader from "@/components/generic/DetailTabsHeader";
import { SectionCard, InfoRow } from "@/components/generic/DetailSectionCard";
function MetaRow({ label, value }) {
if (!value && value !== 0) return null;
return (
<div className="flex items-start gap-3 py-2">
<span className="text-muted-foreground text-sm w-36 shrink-0">{label}</span>
<span className="text-sm font-medium break-all">{String(value)}</span>
</div>
);
}
const TABS = [
{ key: "preview", label: "Preview", icon: Video },
{ key: "info", label: "File Info", icon: Info },
];
export default function ViewVideoAsset() {
const { assetId } = useParams();
@@ -29,6 +26,7 @@ export default function ViewVideoAsset() {
const { fmtDateTime } = useDateFormat();
const { asset: selectedAsset, loading, notFound } = useAssetFetchState(assetId);
const [activeTab, setActiveTab] = useState("preview");
if (loading) {
return <AssetPageLoader />;
@@ -46,102 +44,112 @@ export default function ViewVideoAsset() {
const a = selectedAsset;
return (
<div className="max-w-7xl mx-auto px-4 py-6 space-y-6">
<div className="flex flex-col min-h-screen bg-muted/60">
<DetailTabsHeader
icon={Video}
title={a.display_name ?? a.original_name}
subtitle={a.mime_type}
onBack={() => navigate("/admin/assets")}
tabs={TABS}
activeTab={activeTab}
onTabChange={setActiveTab}
actions={
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
}
/>
{/* ── Header ── */}
<div className="flex items-center gap-3">
<Button variant="ghost" size="icon" onClick={() => navigate("/admin/assets")}>
<ArrowLeft className="h-4 w-4" />
</Button>
<div className="flex-1 min-w-0">
<h1 className="text-xl font-semibold truncate">{a.display_name ?? a.original_name}</h1>
<p className="text-sm text-muted-foreground">{a.mime_type}</p>
</div>
<Button variant="outline" onClick={() => navigate(`/admin/assets/edit/${a.asset_id}`)}>
<Pencil className="h-3.5 w-3.5" />
Edit Info
</Button>
</div>
<div className="lg:container lg:mx-auto lg:px-6 px-4 py-6">
{activeTab === "preview" ? (
<div className="space-y-3">
<TranscodeStatusBanner status={a.transcode_status} />
<VideoBlock
readOnly
onUpdate={() => {}}
content={{
asset_id: a.asset_id,
storage_provider: a.storage_provider,
url: a.file_url,
thumbnail_url: a.thumbnail_url,
title: a.display_name ?? a.original_name,
tag: a.extension?.toUpperCase() ?? "",
}}
/>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-6">
{/* ── Video player ── */}
<div className="lg:col-span-3 space-y-3">
<TranscodeStatusBanner status={a.transcode_status} />
<VideoBlock
readOnly
onUpdate={() => {}}
content={{
asset_id: a.asset_id,
storage_provider: a.storage_provider,
url: a.file_url,
thumbnail_url: a.thumbnail_url,
title: a.display_name ?? a.original_name,
tag: a.extension?.toUpperCase() ?? "",
}}
/>
{/* Thumbnail strip */}
{a.thumbnail_url && (
<div className="rounded-lg border overflow-hidden bg-muted/30">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground px-3 py-2">Thumbnail</p>
<img
src={a.thumbnail_url}
alt="Thumbnail"
className="w-full max-h-40 object-cover"
draggable={false}
onContextMenu={(e) => e.preventDefault()}
/>
</div>
)}
</div>
{/* ── Metadata panel ── */}
<div className="lg:col-span-2 space-y-4">
<div className="rounded-lg border bg-card p-4 space-y-1">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Video Info</p>
<MetaRow label="Original Name" value={a.original_name} />
<MetaRow label="Extension" value={a.extension} />
<MetaRow label="File Size" value={formatFileSize(a.file_size)} />
<MetaRow label="Resolution" value={a.resolution} />
<MetaRow label="Dimensions" value={a.width && a.height ? `${a.width} × ${a.height}` : null} />
<MetaRow label="Duration" value={a.duration == null ? null : formatPlayerTime(a.duration)} />
<MetaRow label="Frame Rate" value={a.frame_rate ? `${a.frame_rate} fps` : null} />
<MetaRow label="Bitrate" value={a.bitrate ? `${a.bitrate} kbps` : null} />
<MetaRow label="Video Codec" value={a.video_codec} />
<MetaRow label="Audio Codec" value={a.audio_codec} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Storage</p>
<MetaRow label="Provider" value={a.storage_provider} />
<MetaRow label="Bucket" value={a.storage_bucket} />
<MetaRow label="Key" value={a.storage_key} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Access</p>
<div className="flex items-center gap-2 py-1">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<MetaRow label="Access Level" value={a.access_level} />
<MetaRow label="Owner Type" value={a.owner_type} />
<MetaRow label="Owner ID" value={a.owner_id} />
<Separator className="my-2" />
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Timestamps</p>
<MetaRow label="Created By" value={a.creator?.full_name ?? a.createdBy} />
<MetaRow label="Created" value={a.createdAt ? fmtDateTime(a.createdAt) : null} />
<MetaRow label="Modified By" value={a.updater?.full_name ?? a.updatedBy} />
<MetaRow label="Modified" value={a.updatedAt ? fmtDateTime(a.updatedAt) : null} />
{/* Thumbnail strip */}
{a.thumbnail_url && (
<div className="rounded-lg border overflow-hidden bg-muted/30">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground px-3 py-2">Thumbnail</p>
<img
src={a.thumbnail_url}
alt="Thumbnail"
className="w-full max-h-40 object-cover"
draggable={false}
onContextMenu={(e) => e.preventDefault()}
/>
</div>
)}
</div>
) : (
<div className="max-w-3xl mx-auto space-y-5 pb-16">
<SectionCard icon={Info} title="Video Info">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Original Name">{a.original_name}</InfoRow>
<InfoRow label="Extension">{a.extension}</InfoRow>
<InfoRow label="File Size">{formatFileSize(a.file_size)}</InfoRow>
<InfoRow label="Resolution">{a.resolution}</InfoRow>
<InfoRow label="Dimensions">{a.width && a.height ? `${a.width} × ${a.height}` : null}</InfoRow>
<InfoRow label="Duration">{a.duration == null ? null : formatPlayerTime(a.duration)}</InfoRow>
<InfoRow label="Frame Rate">{a.frame_rate ? `${a.frame_rate} fps` : null}</InfoRow>
<InfoRow label="Bitrate">{a.bitrate ? `${a.bitrate} kbps` : null}</InfoRow>
<InfoRow label="Video Codec">{a.video_codec}</InfoRow>
<InfoRow label="Audio Codec">{a.audio_codec}</InfoRow>
</div>
</SectionCard>
{a.description && (
<div className="rounded-lg border bg-card p-4">
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2">Description</p>
<p className="text-sm text-foreground">{a.description}</p>
</div>
)}
</div>
<SectionCard icon={Video} title="Storage">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Provider">{a.storage_provider}</InfoRow>
<InfoRow label="Bucket">{a.storage_bucket}</InfoRow>
<InfoRow label="Key">{a.storage_key}</InfoRow>
</div>
</SectionCard>
<SectionCard icon={Lock} title="Access">
<div className="space-y-4">
<div className="flex items-center gap-2">
{a.is_public
? <><Globe className="h-3.5 w-3.5 text-green-500" /><Badge variant="outline" className="text-green-600 border-green-400">Public</Badge></>
: <><Lock className="h-3.5 w-3.5 text-yellow-500" /><Badge variant="outline" className="text-yellow-600 border-yellow-400">Private</Badge></>
}
</div>
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Access Level">{a.access_level}</InfoRow>
<InfoRow label="Owner Type">{a.owner_type}</InfoRow>
<InfoRow label="Owner ID">{a.owner_id}</InfoRow>
</div>
</div>
</SectionCard>
<SectionCard icon={Info} title="Timestamps">
<div className="grid grid-cols-2 gap-4">
<InfoRow label="Created By">{a.creator?.full_name ?? a.createdBy}</InfoRow>
<InfoRow label="Created">{a.createdAt ? fmtDateTime(a.createdAt) : null}</InfoRow>
<InfoRow label="Modified By">{a.updater?.full_name ?? a.updatedBy}</InfoRow>
<InfoRow label="Modified">{a.updatedAt ? fmtDateTime(a.updatedAt) : null}</InfoRow>
</div>
</SectionCard>
{a.description && (
<SectionCard icon={Info} title="Description">
<p className="text-sm text-foreground">{a.description}</p>
</SectionCard>
)}
</div>
)}
</div>
</div>
);
}
}