From e3595ac9635cb7bb1cdf3f54c51b42f0a60df93c Mon Sep 17 00:00:00 2001 From: shiva raj badu Date: Fri, 1 Aug 2025 00:37:35 +0545 Subject: [PATCH] refactor(Nextjs): Custom Layout and canvas restrucred --- .../custom-layout/components/EachSlide.tsx | 113 +++++++++++------- .../custom-layout/components/SlideContent.tsx | 8 +- servers/nextjs/app/custom-layout/page.tsx | 26 ++-- 3 files changed, 90 insertions(+), 57 deletions(-) diff --git a/servers/nextjs/app/custom-layout/components/EachSlide.tsx b/servers/nextjs/app/custom-layout/components/EachSlide.tsx index af88f730..3c066864 100644 --- a/servers/nextjs/app/custom-layout/components/EachSlide.tsx +++ b/servers/nextjs/app/custom-layout/components/EachSlide.tsx @@ -11,6 +11,7 @@ import { RotateCcw, SendHorizontal, X, + Repeat2, } from "lucide-react"; import React, { useState, useEffect, useRef, useCallback } from "react"; import ToolTip from "@/components/ToolTip"; @@ -391,32 +392,63 @@ const EachSlide = ({ const strokeWidths = [1, 3, 5, 8, 12]; return ( - - + + - {slide.processing ? ( - - ) : slide.processed ? ( - - ) : slide.error ? ( - - ) : ( -
- )} +
+
+ {slide.processing ? ( + + ) : slide.processed ? ( + + ) : slide.error ? ( + + ) : ( +
+ )} +
+ +
+ {slide.processed && slide.html && !isEditMode && ( +
+ + + +
+ )} +
+ + + +
+
+
{/* Edit Mode Controls */} {isEditMode && slide.processed && slide.html && ( -
+
{/* Drawing Tools */}
-

- Edit Mode -

- {/* Drawing Tools */}
+
+ +
@@ -662,19 +696,6 @@ const EachSlide = ({ > Open in new tab - - {slide.processed && slide.html && !isEditMode && ( -
- -
- -
-
-
- )}
); diff --git a/servers/nextjs/app/custom-layout/components/SlideContent.tsx b/servers/nextjs/app/custom-layout/components/SlideContent.tsx index 98318ec9..40d63d91 100644 --- a/servers/nextjs/app/custom-layout/components/SlideContent.tsx +++ b/servers/nextjs/app/custom-layout/components/SlideContent.tsx @@ -1,10 +1,16 @@ import React, { memo } from "react"; const SlideContent = memo(({ slide }: { slide: any }) => { + const cleanHtml = slide.html + .replace(/```html/g, "") + .replace(/```/g, "") + .replace(//g, "") + .replace(/<\/html>/g, "") + .replace(/html/g, ""); return (
); diff --git a/servers/nextjs/app/custom-layout/page.tsx b/servers/nextjs/app/custom-layout/page.tsx index d448c525..79e3bd36 100644 --- a/servers/nextjs/app/custom-layout/page.tsx +++ b/servers/nextjs/app/custom-layout/page.tsx @@ -39,6 +39,7 @@ const CustomLayoutPage = () => { const [isProcessingPptx, setIsProcessingPptx] = useState(false); const [slides, setSlides] = useState([]); const [isSavingLayout, setIsSavingLayout] = useState(false); + const [isLayoutSaved, setIsLayoutSaved] = useState(false); // Warning before page unload useEffect(() => { @@ -46,10 +47,11 @@ const CustomLayoutPage = () => { e.preventDefault(); return "You have unsaved changes. Are you sure you want to leave?"; }; - - window.addEventListener("beforeunload", handleBeforeUnload); + if (slides.length > 0 && !isLayoutSaved) { + window.addEventListener("beforeunload", handleBeforeUnload); + } return () => window.removeEventListener("beforeunload", handleBeforeUnload); - }, []); + }, [slides, isLayoutSaved]); // Save layout functionality const saveLayout = useCallback(async () => { @@ -134,6 +136,7 @@ const CustomLayoutPage = () => { ); toast.success(`Layout saved successfully`); + setIsLayoutSaved(true); } catch (error) { console.error("Error saving layout:", error); toast.error("Failed to save layout", { @@ -181,6 +184,7 @@ const CustomLayoutPage = () => { // Process individual slide to HTML const processSlideToHtml = useCallback( async (slide: SlideData, index: number) => { + setIsLayoutSaved(false); console.log( `Starting to process slide ${slide.slide_number} at index ${index}` ); @@ -354,6 +358,7 @@ const CustomLayoutPage = () => { // Retry failed slide const retrySlide = useCallback( (index: number) => { + setIsLayoutSaved(false); const slide = slides[index]; if (slide) { processSlideToHtml(slide, index); @@ -365,6 +370,7 @@ const CustomLayoutPage = () => { // Mark slide as modified when it's updated const handleSlideUpdate = useCallback( (index: number, updatedSlideData: any) => { + setIsLayoutSaved(false); setSlides((prevSlides) => prevSlides.map((s, i) => i === index @@ -389,9 +395,9 @@ const CustomLayoutPage = () => { return (
-
+
{/* Header */} -
+

Custom Layout Processor

@@ -415,18 +421,18 @@ const CustomLayoutPage = () => { {!selectedFile ? ( -
+

@@ -520,11 +526,11 @@ const CustomLayoutPage = () => { {/* Floating Save Layout Button */} {slides.length > 0 && slides.some((s) => s.processed) && ( -

+