Skip to content

Commit 535a50c

Browse files
committed
little bit update
1 parent 5c1f90b commit 535a50c

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

src/components/CommandBox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function CommandBox({ addWidget }) {
2121
const [open, setOpen] = useState(false);
2222
useEffect(() => {
2323
const down = (e) => {
24-
if (e.key === "j" && (e.metaKey || e.ctrlKey)) {
24+
if (e.key === "t" || (e.key === "T" && (e.metaKey || e.ctrlKey))) {
2525
e.preventDefault();
2626
setOpen((open) => !open);
2727
}

src/components/Layouts/AppLayout.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TitleBar from "../TitleBar";
33
import { Outlet } from "react-router";
44
import { Toaster } from "../ui/sonner";
55

6-
import { setData } from "../../utils/store";
6+
import { getData, setData } from "../../utils/store";
77

88
export default function AppLayout() {
99
const [isSettingWindow, setIsSettingWindow] = useState(false);
@@ -18,9 +18,16 @@ export default function AppLayout() {
1818
container.current.offsetWidth,
1919
container.current.offsetHeight,
2020
];
21-
22-
await setData("container", offSet);
23-
setIsSettingWindow(true);
21+
const fetchLayout = async () => {
22+
// const savedLayout = await getData("container");
23+
// console.log("Saving layout", savedLayout);
24+
// if (savedLayout == null) {
25+
// await setData("container", offSet);
26+
// }
27+
await setData("container", offSet);
28+
setIsSettingWindow(true);
29+
};
30+
fetchLayout();
2431
};
2532

2633
updateContainerSize();

src/components/WorkSpace/DragAndDrop.jsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import "./DragAndDrop.css";
2-
import { getData } from "@/utils/store";
2+
import { getData, setData } from "@/utils/store";
33
import { v4 as uuidv4 } from "uuid";
44
import { useState, useEffect, useRef } from "react";
55
import GridLayout from "react-grid-layout";
66
import RenderWidget from "../Widgets/RenderWidget";
77
import { alertError } from "@/lib/alertCustomized";
8-
import MenuWidget from "./Menu/MenuWidget";
98
import CommandBox from "../CommandBox";
109

1110
const DragAndDrop = () => {
@@ -50,14 +49,28 @@ const DragAndDrop = () => {
5049
const [map, setMap] = useState(Array(30).fill(0));
5150

5251
useEffect(() => {
53-
const initialLayout = [
54-
{ i: "Clock_1", x: 0, y: 0, w: 1, h: 1, type: "clock" },
55-
{ i: "Clock_2", x: 2, y: 0, w: 2, h: 1, type: "clock" },
56-
{ i: "Music_3", x: 4, y: 0, w: 1, h: 1, type: "music" },
57-
];
58-
setLayout(initialLayout);
52+
const fetchLayout = async () => {
53+
const savedLayout = await getData("layout");
54+
//console.log(savedLayout);
55+
if (
56+
savedLayout &&
57+
JSON.stringify(savedLayout) !== JSON.stringify(layout)
58+
) {
59+
setLayout(savedLayout);
60+
}
61+
};
62+
fetchLayout();
5963
}, []);
6064

65+
useEffect(() => {
66+
setMap(createMap(layout));
67+
const saveLayout = async () => {
68+
//console.log("Saving layout", layout);
69+
await setData("layout", layout);
70+
};
71+
saveLayout();
72+
}, [layout]);
73+
6174
const createMap = (layout) => {
6275
let map = Array(30).fill(0);
6376

@@ -73,10 +86,6 @@ const DragAndDrop = () => {
7386
return map;
7487
};
7588

76-
useEffect(() => {
77-
setMap(createMap(layout));
78-
}, [layout]);
79-
8089
const handleLayoutChange = (newLayout) => {
8190
let changed = false;
8291
const fixedLayout = newLayout.map((item) => {

0 commit comments

Comments
 (0)