From d491679672a811a4770cbfa21362786b189c25c6 Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Fri, 31 Jan 2025 19:51:50 +0700 Subject: [PATCH] remove unneccessary load --- src/app/storybook/board/page.tsx | 7 +++--- src/app/storybook/layout.tsx | 6 ++++- src/components/board/index.tsx | 41 ++++++++++++-------------------- 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/app/storybook/board/page.tsx b/src/app/storybook/board/page.tsx index 53305925..79fb4fa8 100644 --- a/src/app/storybook/board/page.tsx +++ b/src/app/storybook/board/page.tsx @@ -46,12 +46,13 @@ export default function StorybookBoardPage() { + onChange={(v) => { + console.log("change here"); setValue({ ...value, layout: v, - }) - } + }); + }} editMode={editMode} /> diff --git a/src/app/storybook/layout.tsx b/src/app/storybook/layout.tsx index c350c5b7..a8026508 100644 --- a/src/app/storybook/layout.tsx +++ b/src/app/storybook/layout.tsx @@ -56,7 +56,11 @@ export default function StorybookRootLayout({ text="Chart" href="/storybook/chart" /> - +
{children} diff --git a/src/components/board/index.tsx b/src/components/board/index.tsx index 83ce8978..11eafc79 100644 --- a/src/components/board/index.tsx +++ b/src/components/board/index.tsx @@ -1,7 +1,7 @@ "use client"; import { cn } from "@/lib/utils"; import { RectangleHorizontal, Square } from "lucide-react"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback } from "react"; import RGL, { WidthProvider } from "react-grid-layout"; import { buttonVariants } from "../ui/button"; import "./board-style.css"; @@ -23,14 +23,6 @@ interface BoardProps { const ReactGridLayout = WidthProvider(RGL); export default function Board(props: BoardProps) { - const [loading, setLoading] = useState(true); - - useEffect(() => { - if (props.layout.length > 0 && !!loading) { - setLoading(false); - } - }, [props, loading]); - const sizes = [ { w: 1, h: 1, name: "1", icon: }, { @@ -50,8 +42,7 @@ export default function Board(props: BoardProps) { const handleClickResize = useCallback( (w: number, h: number, index: number) => { - setLoading(true); - const dummy = [...props.layout]; + const dummy = structuredClone(props.layout); dummy[index].w = w; dummy[index].h = h; props.onChange(dummy); @@ -95,21 +86,19 @@ export default function Board(props: BoardProps) { return (
- {!loading && ( - - {mapItem} - - )} + + {mapItem} +
); }