Skip to content

Commit ddfd43f

Browse files
author
ozen0718
committed
D&D저장 위치 완료
1 parent d2340c8 commit ddfd43f

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"axios": "^1.8.3",
1717
"clsx": "^2.1.1",
1818
"date-fns": "^4.1.0",
19+
"dexie": "^4.0.11",
1920
"lodash": "^4.17.21",
2021
"lucide-react": "^0.485.0",
2122
"moment": "^2.30.1",

src/lib/dashboardOrderDB.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// src/lib/dashboardOrderDB.ts
2+
import Dexie from "dexie";
3+
4+
// DB 인스턴스 생성
5+
export const db = new Dexie("DashboardOrderDB");
6+
7+
// 테이블 구조 정의
8+
db.version(1).stores({
9+
dashboardOrders: "&teamId", // teamId를 키로 사용
10+
});
11+
12+
// 테이블 객체 export
13+
export const dashboardOrdersTable = db.table("dashboardOrders");

src/pages/mydashboard.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { DeleteModal } from "@/components/modal/DeleteModal";
1313
import { TEAM_ID } from "@/constants/team";
1414
import { Search } from "lucide-react";
1515
import { toast } from "react-toastify";
16-
1716
import {
1817
DndContext,
1918
closestCenter,
@@ -28,6 +27,7 @@ import {
2827
arrayMove,
2928
} from "@dnd-kit/sortable";
3029
import SortableCardButton from "@/components/button/SortableCardButton";
30+
import { dashboardOrdersTable } from "@/lib/dashboardOrderDB";
3131

3232
interface Dashboard {
3333
id: number;
@@ -56,7 +56,7 @@ export default function MyDashboardPage() {
5656
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
5757
const [isConfirmDeleteModalOpen, setIsConfirmDeleteModalOpen] =
5858
useState(false);
59-
const itemsPerPage = 6; // 버튼 포함 6개
59+
const itemsPerPage = 6;
6060

6161
const sensors = useSensors(
6262
useSensor(PointerSensor, {
@@ -80,7 +80,18 @@ export default function MyDashboardPage() {
8080
const fetchDashboards = async () => {
8181
try {
8282
const res = await getDashboards({});
83-
setDashboardList(res.dashboards);
83+
const localOrder = await dashboardOrdersTable.get(TEAM_ID);
84+
85+
let orderedList = res.dashboards;
86+
if (localOrder?.order) {
87+
orderedList = res.dashboards
88+
.slice()
89+
.sort(
90+
(a, b) =>
91+
localOrder.order.indexOf(a.id) - localOrder.order.indexOf(b.id)
92+
);
93+
}
94+
setDashboardList(orderedList);
8495
} catch (error) {
8596
console.error("대시보드 불러오기 실패:", error);
8697
}
@@ -121,7 +132,7 @@ export default function MyDashboardPage() {
121132
setSelectedDashboardId(null);
122133
};
123134

124-
const handleDragEnd = (event: DragEndEvent) => {
135+
const handleDragEnd = async (event: DragEndEvent) => {
125136
const { active, over } = event;
126137
if (!over || active.id === over.id) return;
127138

@@ -130,6 +141,12 @@ export default function MyDashboardPage() {
130141

131142
const newOrder = arrayMove(dashboardList, oldIndex, newIndex);
132143
setDashboardList(newOrder);
144+
145+
//D&D 로컬 순서 저장
146+
await dashboardOrdersTable.put({
147+
teamId: TEAM_ID,
148+
order: newOrder.map((d) => d.id),
149+
});
133150
};
134151

135152
return (

0 commit comments

Comments
 (0)