diff --git a/electron/servers/nextjs/app/(presentation-generator)/template-preview/[slug]/page.tsx b/electron/servers/nextjs/app/(presentation-generator)/template-preview/[slug]/page.tsx index c661c623..f812c885 100644 --- a/electron/servers/nextjs/app/(presentation-generator)/template-preview/[slug]/page.tsx +++ b/electron/servers/nextjs/app/(presentation-generator)/template-preview/[slug]/page.tsx @@ -1,308 +1,22 @@ -"use client"; -import React, { useCallback, useEffect, useState } from "react"; -import { useParams, usePathname, useRouter } from "next/navigation"; -import { Card } from "@/components/ui/card"; -import { Button } from "@/components/ui/button"; -import { ArrowLeft, Home, Loader2, Trash2 } from "lucide-react"; +import GroupLayoutPreview from './components/TemplatePreviewClient'; -import { useFontLoader } from "../../hooks/useFontLoader"; -import { MixpanelEvent, trackEvent } from "@/utils/mixpanel"; -import TemplateService from "../../services/api/template"; -import Header from "../../(dashboard)/dashboard/components/Header"; -import { toast } from "sonner"; -import { CustomTemplateLayout, useCustomTemplateDetails } from "@/app/hooks/useCustomTemplates"; -import { templates as templateGroups, getTemplatesByTemplateName } from "@/app/presentation-templates"; +// Allow dynamic params for custom templates +export const dynamicParams = true; -const GroupLayoutPreview = () => { - const params = useParams(); - const router = useRouter(); - const pathname = usePathname(); +// Generate static params for built-in template groups +export async function generateStaticParams() { + // Pre-render built-in template routes at build time + // Custom templates (custom-*) will be generated on-demand + return [ + { slug: 'neo-general' }, + { slug: 'neo-standard' }, + { slug: 'neo-modern' }, + { slug: 'general' }, + { slug: 'modern' }, + { slug: 'standard' }, + ]; +} - const templateParams = params.slug as string; - - // Check if this is a custom template - const isCustom = templateParams.startsWith("custom-"); - const customTemplateId = isCustom ? templateParams.split("custom-")[1] : null; - - - // Fetch static templates if not custom - const staticTemplates = !isCustom ? getTemplatesByTemplateName(templateParams) : []; - - const staticGroup = !isCustom ? templateGroups.find((g: { id: string }) => g.id === templateParams) : null; - - // Fetch custom template details if custom - const { - template: customTemplate, - loading: customLoading, - error: customError, - fonts: customFonts, - } = useCustomTemplateDetails({ id: templateParams?.split("custom-")[1] || "", name: "", description: "" }); - - - - useEffect(() => { - const existingScript = document.querySelector('script[src*="tailwindcss.com"]'); - if (!existingScript) { - const script = document.createElement("script"); - script.src = "https://cdn.tailwindcss.com"; - script.async = true; - document.head.appendChild(script); - } - }, [templateParams]); - - const handleDeleteCustomTemplate = async () => { - if (!customTemplateId) return; - - const confirmed = window.confirm( - "Are you sure you want to delete this template? This action cannot be undone." - ); - if (!confirmed) return; - - const success = await TemplateService.deleteCustomTemplate(customTemplateId); - if (success.success) { - toast.success("Template deleted successfully"); - router.push("/template-preview"); - } else { - toast.error("Failed to delete template"); - } - }; - - - // Loading state for custom templates - if (isCustom && (customLoading)) { - return ( -
-
-
- - Compiling templates... -
-
- ); - } - - // Error state - if (isCustom && customError) { - return ( -
-
-
-

Error loading template

-

{customError}

- -
-
- ); - } - - // Empty state - if ( - (!isCustom && (!staticGroup || staticTemplates.length === 0)) || - (isCustom && (!customTemplate)) - ) { - return ( -
-
-
-

- Template not found -

- -
-
- ); - } - - // Determine what to render - const templateName = isCustom ? customTemplate?.template.name || "Custom Template" : staticGroup?.name || ""; - const templateDescription = isCustom - ? customTemplate?.template.description || "" - : staticGroup?.description || ""; - const layoutCount = isCustom - ? customTemplate?.layouts.length || 0 - : staticTemplates.length; - - console.log('compileLayout', customTemplate) - - return ( -
-
- - {/* Header */} -
-
-
-
- - -
- - {isCustom && ( -
- - -
- )} -
- -
-
-

{templateName}

- {isCustom && ( - - Custom - - )} -
-

- {layoutCount} layout{layoutCount !== 1 ? "s" : ""} •{" "} - {templateDescription} -

-
-
- -
- - {/* Layout Grid - Wrapped in SchemaHighlightProvider for custom templates */} -
- {/* Static Templates */} - {!isCustom && ( -
- {staticTemplates.map((template: any, index: number) => { - const LayoutComponent = template.component; - - return ( - -
-
-
-

- {template.layoutName} -

-

- {template.layoutDescription} -

-
-
- - {template.layoutId} - - - #{index + 1} - -
-
-
- -
-
- -
-
-
- ); - })} -
- )} - - {/* Custom Templates - with page-level schema editor */} - {isCustom && ( - -
- {/* Slides List */} - - {customTemplate && customTemplate.layouts.map((layout: CustomTemplateLayout, index: number) => { - const LayoutComponent = layout.component; - return ( - -
-
-
-

- {layout.rawLayoutName} -

-

- {layout.layoutDescription} -

-
-
-
- - {templateParams}:{layout.layoutId} - - -
-
- -
-
- -
-
-
- ); - })} - - -
- )} -
-
- ); -}; - -export default GroupLayoutPreview; \ No newline at end of file +export default function GroupLayoutPreviewPage() { + return ; +} \ No newline at end of file