Skip to content

Commit

Permalink
remove unneccessary load
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Jan 31, 2025
1 parent 2e61a66 commit d491679
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/app/storybook/board/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export default function StorybookBoardPage() {
<BoardTool editMode={editMode} setEditMode={setEditMode} />
<Board
layout={value.layout}
onChange={(v) =>
onChange={(v) => {
console.log("change here");
setValue({
...value,
layout: v,
})
}
});
}}
editMode={editMode}
/>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/app/storybook/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export default function StorybookRootLayout({
text="Chart"
href="/storybook/chart"
/>
<SidebarMenuItem icon={Component} text="Board" href="/story/board" />
<SidebarMenuItem
icon={Component}
text="Board"
href="/storybook/board"
/>
</div>
<div className="flex-1 overflow-y-auto p-4">
<TooltipProvider>{children}</TooltipProvider>
Expand Down
41 changes: 15 additions & 26 deletions src/components/board/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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: <Square className="h-3 w-3" /> },
{
Expand All @@ -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);
Expand Down Expand Up @@ -95,21 +86,19 @@ export default function Board(props: BoardProps) {

return (
<div>
{!loading && (
<ReactGridLayout
cols={4}
rowHeight={220}
draggableCancel=".cancelSelectorName"
className="layout"
layout={props.layout}
onLayoutChange={props.onChange}
isDraggable={props.editMode === "REARRANGING_CHART"}
isResizable={props.editMode === "REARRANGING_CHART"}
compactType={"horizontal"}
>
{mapItem}
</ReactGridLayout>
)}
<ReactGridLayout
cols={4}
rowHeight={220}
draggableCancel=".cancelSelectorName"
className="layout overflow-x-hidden"
layout={props.layout}
onLayoutChange={props.onChange}
isDraggable={props.editMode === "REARRANGING_CHART"}
isResizable={props.editMode === "REARRANGING_CHART"}
compactType={"vertical"}
>
{mapItem}
</ReactGridLayout>
</div>
);
}

0 comments on commit d491679

Please sign in to comment.