From 67fe35ffb420dbf1b74c1cb768a9ebec1e511a9a Mon Sep 17 00:00:00 2001 From: Hina Garg Date: Tue, 14 Jan 2025 17:46:39 -0500 Subject: [PATCH] Visual Builder Changes -- Added editable tags for Image, RTE, SLT Fields --- src/app/test/page.tsx | 161 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 10 deletions(-) diff --git a/src/app/test/page.tsx b/src/app/test/page.tsx index d56d987..e10b40c 100644 --- a/src/app/test/page.tsx +++ b/src/app/test/page.tsx @@ -1,14 +1,155 @@ -import LikeButton from "@/components/like"; +"use client"; + +import Image from "next/image"; +import { getPage, initLivePreview, stack } from "@/lib/contentstack"; +import { useEffect, useState } from "react"; +import { Page } from "@/lib/types"; +import { useSearchParams } from "next/navigation"; +import ContentstackLivePreview, { + VB_EmptyBlockParentClass, +} from "@contentstack/live-preview-utils"; -function Header({ title }:{title:string}) { - return

{title ? title : 'Default title'}

; -} - export default function TestPage() { + const [page, setPage] = useState(); + const searchParams = useSearchParams(); + const live_preview = searchParams.get("live_preview"); + const entry_uid = searchParams.get("entry_uid"); + const content_type_uid = searchParams.get("content_type_uid"); + + // If we're in Live Preview mode, set up the query parameters + if (live_preview) { + stack.livePreviewQuery({ + live_preview, + contentTypeUid: content_type_uid || "", + entryUid: entry_uid || "", + }); + } + + // Fetch and set content + const getContent = async () => { + const newPage = await getPage("/test", "page"); + setPage(newPage); + }; + + console.log( + "page", + JSON.stringify(page?.page_components?.[0].hero_banner.banner_description) + ); + + useEffect(() => { + initLivePreview(); + // Re-fetch content automatically when an entry changes in Live Preview + ContentstackLivePreview.onEntryChange(getContent); + }, []); + return ( -
-
- -
+
+ {/* Main container with max width and centered alignment */} +
+ {/* Section with padding */} + + {/* Page Title */} + {page?.title ? ( +

+ {page?.title} +

+ ) : null} + + {/* Hero Banner Image (from the first page_component if available) */} + {page?.page_components?.[0].hero_banner.banner_image?.url ? ( + {page.page_components[0].hero_banner.banner_image.title} + ) : null} + + {/* Main container for page_components */} +
+ {page?.page_components?.map((item, index) => { + // --- HERO BANNER BLOCK --- + if (item.hero_banner) { + return ( +
+ {/* Banner Title */} + {item.hero_banner.banner_title ? ( +

{item.hero_banner.banner_title}

+ ) : null} + + {/* Banner Description */} + {item.hero_banner.banner_description ? ( +
+ ) : null} +
+ ); + } + + // --- RECENT ARTICLES BLOCK --- + else if (item.recent_articles) { + return ( +
+ {/* Recent Articles Title */} +

{item.recent_articles.title}

+ + {/* Recent Articles Subtitle */} + {item.recent_articles.subtitle ? ( +
+ {item.recent_articles.subtitle} +
+ ) : null} +
+ ); + } + + // --- DUAL CONTENT CTA BLOCK --- + else if (item.dual_content_cta) { + return ( +
+

{item.dual_content_cta.title}

+
+ ); + } + + return null; + })} +
+
+
); -} \ No newline at end of file +}