Skip to content

Commit

Permalink
refactor: Simplify Board component props and update layout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sokphaladam committed Jan 30, 2025
1 parent 0aaa7d9 commit 50202c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
7 changes: 1 addition & 6 deletions src/app/storybook/board/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export default function StorybookBoardPage() {

return (
<div className="bg-secondary min-h-full w-full flex-1">
<Board
value={{
layout,
onChangeLayout: setLayout,
}}
/>
<Board layout={layout} onChange={setLayout} />
</div>
);
}
20 changes: 10 additions & 10 deletions src/components/board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ export interface BoardChartLayout {

interface BoardProps {
layout: ReactGridLayout.Layout[];
onChangeLayout: (v: ReactGridLayout.Layout[]) => void;
onChange: (v: ReactGridLayout.Layout[]) => void;
}

const ReactGridLayout = WidthProvider(RGL);

export default function Board({ value }: { value: BoardProps }) {
export default function Board(props: BoardProps) {
const [layout, setLayout] = useState<ReactGridLayout.Layout[]>([]);

useEffect(() => {
if (value.layout) {
setLayout(value.layout);
if (props.layout) {
setLayout(props.layout);
}
}, [value]);
}, [props]);

const sizes = [
{ w: 1, h: 1, name: "1", icon: <Square className="h-3 w-3" /> },
Expand All @@ -49,15 +49,15 @@ export default function Board({ value }: { value: BoardProps }) {

const handleClickResize = useCallback(
(w: number, h: number, index: number) => {
const dummy = [...value.layout];
const dummy = [...props.layout];
dummy[index].w = w;
dummy[index].h = h;
value.onChangeLayout(dummy);
props.onChange(dummy);
},
[value]
[props]
);

const mapItem: JSX.Element[] = [...Array(value.layout.length)].map((_, i) => {
const mapItem: JSX.Element[] = [...Array(props.layout.length)].map((_, i) => {
return (
<div
key={i}
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function Board({ value }: { value: BoardProps }) {
<div className="p-4">
<div>Display as [x, y, w, h]:</div>
<div style={{ display: "flex", gap: 7 }}>
{value.layout.map((l) => {
{props.layout.map((l) => {
return (
<div className="layoutItem" key={l.i}>
<b>{l.i}</b>
Expand Down

0 comments on commit 50202c6

Please sign in to comment.