Skip to content

Commit bb59a1f

Browse files
authored
Merge pull request #104 from boostcampwm-2024/fix-fe-#49
노드 백스페이스 삭제 기능 개선
2 parents 4dfa24c + 3c5e9c5 commit bb59a1f

File tree

7 files changed

+48
-22
lines changed

7 files changed

+48
-22
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { createPage, deletePage } from "./api/pageApi";
22
export { useCreatePage, useDeletePage } from "./model/pageMutations";
33

4+
export { useDeletePageStore } from "./model/deletePageStore";
45
export { usePageStore } from "./model/pageStore";
56
export { type Page, type CreatePageRequest } from "./model/pageTypes";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { create } from "zustand";
2+
3+
interface DeletePageStore {
4+
noteIdToDelete: number | null;
5+
setNoteIdToDelete: (noteIdToDelete: number | null) => void;
6+
isModalOpen: boolean;
7+
setIsModalOpen: () => void;
8+
}
9+
10+
export const useDeletePageStore = create<DeletePageStore>((set) => ({
11+
noteIdToDelete: null,
12+
setNoteIdToDelete: (noteIdToDelete: number | null) => set({ noteIdToDelete }),
13+
isModalOpen: false,
14+
setIsModalOpen: () => set((state) => ({ isModalOpen: !state.isModalOpen })),
15+
}));

apps/frontend/src/features/canvas/model/useCanvas.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useWorkspace } from "@/shared/lib";
2020
import { useUserStore } from "@/entities/user";
2121
import { useCanvasConnection } from "./useCanvasConnection";
2222
import useConnectionStore from "@/shared/model/useConnectionStore";
23+
import { useNoteList } from "@/shared/model/useNoteList";
2324

2425
export interface YNode extends Node {
2526
isHolding: boolean;
@@ -41,6 +42,7 @@ export const useCanvas = () => {
4142
const holdingNodeRef = useRef<string | null>(null);
4243

4344
const { currentPage, setCurrentPage } = usePageStore();
45+
const { openModal } = useNoteList();
4446
const { users } = useUserStore();
4547

4648
const { fitView } = useReactFlow();
@@ -239,7 +241,15 @@ export const useCanvas = () => {
239241
}
240242
});
241243

242-
onNodesChange(changes);
244+
const changesWithoutRemove = changes.filter((change) => {
245+
if (change.type !== "remove") return true;
246+
else {
247+
openModal(Number(change.id));
248+
return false;
249+
}
250+
});
251+
252+
onNodesChange(changesWithoutRemove);
243253
},
244254
[nodes, edges, onNodesChange, provider],
245255
);

apps/frontend/src/features/canvas/ui/Canvas/index.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {
1111
import "@xyflow/react/dist/style.css";
1212

1313
import { CollaborativeCursors } from "../CollaborativeCursors";
14+
import { RemoveNoteModal } from "../RemoveNoteModal";
1415
import { useCanvas } from "../../model/useCanvas";
1516
import { MemoizedGroupNode, NoteNode, NoteNodeType } from "@/entities/node";
1617
import { cn } from "@/shared/lib";
1718
import { useConnectionStatus } from "@/shared/model/useConnectionStatus";
19+
import { useNoteList } from "@/shared/model/useNoteList";
1820

1921
interface CanvasProps {
2022
className?: string;
@@ -37,6 +39,8 @@ export function Canvas({ className }: CanvasProps) {
3739
onNodeDragStop,
3840
onConnect,
3941
} = useCanvas();
42+
const { isModalOpen, onConfirm, onCloseModal } = useNoteList();
43+
4044
const status = useConnectionStatus();
4145

4246
const proOptions = { hideAttribution: true };
@@ -61,6 +65,11 @@ export function Canvas({ className }: CanvasProps) {
6165

6266
return (
6367
<div className={cn(className)} onMouseMove={handleMouseMove}>
68+
<RemoveNoteModal
69+
isOpen={isModalOpen}
70+
onConfirm={onConfirm}
71+
onCloseModal={onCloseModal}
72+
/>
6473
<ReactFlow
6574
nodes={nodes}
6675
edges={edges}

apps/frontend/src/features/pageSidebar/ui/NoteList/index.tsx

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Trash2 } from "lucide-react";
22

3-
import { RemoveNoteModal } from "../RemoveNoteModal";
4-
import { useNoteList } from "../../model/useNoteList";
3+
import { useNoteList } from "@/shared/model/useNoteList";
54
import { cn } from "@/shared/lib";
65
import { Button, Emoji } from "@/shared/ui";
76

@@ -10,22 +9,10 @@ interface NoteListProps {
109
}
1110

1211
export function NoteList({ className }: NoteListProps) {
13-
const {
14-
pages,
15-
isModalOpen,
16-
handleNoteClick,
17-
openModal,
18-
onConfirm,
19-
onCloseModal,
20-
} = useNoteList();
12+
const { pages, handleNoteClick, openModal } = useNoteList();
2113

2214
return (
2315
<div className={cn("flex flex-col gap-0.5 text-sm font-medium", className)}>
24-
<RemoveNoteModal
25-
isOpen={isModalOpen}
26-
onConfirm={onConfirm}
27-
onCloseModal={onCloseModal}
28-
/>
2916
{pages &&
3017
pages.map(({ id, title, emoji }) => (
3118
<Button

apps/frontend/src/features/pageSidebar/model/useNoteList.ts apps/frontend/src/shared/model/useNoteList.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useEffect, useState } from "react";
22

33
import { Node, NoteNodeData } from "@/entities/node";
4-
import { useDeletePage, usePageStore } from "@/entities/page";
4+
import {
5+
useDeletePage,
6+
useDeletePageStore,
7+
usePageStore,
8+
} from "@/entities/page";
59
import useConnectionStore from "@/shared/model/useConnectionStore";
610

711
export const useNoteList = () => {
@@ -31,8 +35,8 @@ export const useNoteList = () => {
3135
};
3236
}, [canvas.provider]);
3337

34-
const [noteIdToDelete, setNoteIdToDelete] = useState<number | null>(null);
35-
const [isModalOpen, setIsModalOpen] = useState(false);
38+
const { noteIdToDelete, setNoteIdToDelete, isModalOpen, setIsModalOpen } =
39+
useDeletePageStore();
3640

3741
const deleteMutation = useDeletePage();
3842

@@ -42,7 +46,7 @@ export const useNoteList = () => {
4246

4347
const openModal = (noteId: number) => {
4448
setNoteIdToDelete(noteId);
45-
setIsModalOpen(true);
49+
setIsModalOpen();
4650
};
4751

4852
const onConfirm = () => {
@@ -56,12 +60,12 @@ export const useNoteList = () => {
5660
nodesMap.delete(noteIdToDelete.toString());
5761
deleteMutation.mutate({ id: noteIdToDelete });
5862

59-
setIsModalOpen(false);
63+
setIsModalOpen();
6064
setCurrentPage(null);
6165
};
6266

6367
const onCloseModal = () => {
64-
setIsModalOpen(false);
68+
setIsModalOpen();
6569
};
6670

6771
return {

0 commit comments

Comments
 (0)