fix(templates): real per-category counts in sidebar (drop hardcoded 418/851)
Category badges now show the live template count per category computed from the catalog (0 → no badge), instead of hardcoded demo numbers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -29,11 +29,10 @@ const SIDEBAR_CATEGORIES: {
|
|||||||
id: VideoSidebarCategoryId;
|
id: VideoSidebarCategoryId;
|
||||||
labelKey: string;
|
labelKey: string;
|
||||||
icon: ComponentType<{ className?: string }>;
|
icon: ComponentType<{ className?: string }>;
|
||||||
count?: number;
|
|
||||||
}[] = [
|
}[] = [
|
||||||
{ id: "all", labelKey: "categoryAll", icon: LayoutGrid },
|
{ id: "all", labelKey: "categoryAll", icon: LayoutGrid },
|
||||||
{ id: "animation", labelKey: "categoryAnimation", icon: Play, count: 418 },
|
{ id: "animation", labelKey: "categoryAnimation", icon: Play },
|
||||||
{ id: "intros", labelKey: "categoryIntros", icon: Clapperboard, count: 851 },
|
{ id: "intros", labelKey: "categoryIntros", icon: Clapperboard },
|
||||||
{ id: "editing", labelKey: "categoryEditing", icon: Scissors },
|
{ id: "editing", labelKey: "categoryEditing", icon: Scissors },
|
||||||
{ id: "invitation", labelKey: "categoryInvitation", icon: Mail },
|
{ id: "invitation", labelKey: "categoryInvitation", icon: Mail },
|
||||||
{ id: "holiday", labelKey: "categoryHoliday", icon: Gift },
|
{ id: "holiday", labelKey: "categoryHoliday", icon: Gift },
|
||||||
@@ -54,6 +53,8 @@ interface VideoTemplatesCategorySidebarProps {
|
|||||||
onAspectRatioChange: (value: AspectRatioFilter) => void;
|
onAspectRatioChange: (value: AspectRatioFilter) => void;
|
||||||
showFilters: boolean;
|
showFilters: boolean;
|
||||||
onToggleFilters: () => void;
|
onToggleFilters: () => void;
|
||||||
|
/** Live template count per category id (+ "all"), computed from the catalog. */
|
||||||
|
counts?: Record<string, number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VideoTemplatesCategorySidebar({
|
export function VideoTemplatesCategorySidebar({
|
||||||
@@ -65,6 +66,7 @@ export function VideoTemplatesCategorySidebar({
|
|||||||
onAspectRatioChange,
|
onAspectRatioChange,
|
||||||
showFilters,
|
showFilters,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
counts,
|
||||||
}: VideoTemplatesCategorySidebarProps) {
|
}: VideoTemplatesCategorySidebarProps) {
|
||||||
const t = useTranslations("auto.componentsTemplatesVideoVideoTemplatesCategorySidebar");
|
const t = useTranslations("auto.componentsTemplatesVideoVideoTemplatesCategorySidebar");
|
||||||
return (
|
return (
|
||||||
@@ -93,9 +95,9 @@ export function VideoTemplatesCategorySidebar({
|
|||||||
aria-hidden
|
aria-hidden
|
||||||
/>
|
/>
|
||||||
<span className="min-w-0 flex-1 truncate text-start">{t(category.labelKey)}</span>
|
<span className="min-w-0 flex-1 truncate text-start">{t(category.labelKey)}</span>
|
||||||
{category.count !== undefined ? (
|
{counts?.[category.id] ? (
|
||||||
<span className="ms-auto rounded bg-gray-100 px-1.5 py-0.5 text-[11px] text-gray-500">
|
<span className="ms-auto rounded bg-gray-100 px-1.5 py-0.5 text-[11px] text-gray-500">
|
||||||
{category.count}
|
{counts[category.id].toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -66,6 +66,15 @@ export function VideoTemplatesPageContent({
|
|||||||
// Real admin-sourced templates only — no hardcoded demo fallback.
|
// Real admin-sourced templates only — no hardcoded demo fallback.
|
||||||
const catalog = initialCatalog ?? [];
|
const catalog = initialCatalog ?? [];
|
||||||
|
|
||||||
|
// Live template count per sidebar category (+ total), computed from the catalog.
|
||||||
|
const categoryCounts = useMemo(() => {
|
||||||
|
const counts: Record<string, number> = { all: catalog.length };
|
||||||
|
for (const tpl of catalog) {
|
||||||
|
counts[tpl.videoCategory] = (counts[tpl.videoCategory] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}, [catalog]);
|
||||||
|
|
||||||
const filtered = useMemo(
|
const filtered = useMemo(
|
||||||
() =>
|
() =>
|
||||||
filterVideoCatalog(catalog, {
|
filterVideoCatalog(catalog, {
|
||||||
@@ -120,6 +129,7 @@ export function VideoTemplatesPageContent({
|
|||||||
onAspectRatioChange={setAspectRatio}
|
onAspectRatioChange={setAspectRatio}
|
||||||
showFilters={showFilters}
|
showFilters={showFilters}
|
||||||
onToggleFilters={() => setShowFilters((v) => !v)}
|
onToggleFilters={() => setShowFilters((v) => !v)}
|
||||||
|
counts={categoryCounts}
|
||||||
/>
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user