Skip to content

Commit 31d1768

Browse files
committed
feat: query를 이용한 페이지 생성, 제거 구현
1 parent 4987453 commit 31d1768

File tree

3 files changed

+72
-84
lines changed

3 files changed

+72
-84
lines changed
Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,14 @@
11
import usePageStore from "@/store/usePageStore";
22
import Editor from "./editor";
3-
import { JSONContent } from "novel";
4-
5-
interface Page {
6-
title: string;
7-
content?: JSONContent;
8-
}
9-
10-
const pages: Page[] = [
11-
{
12-
title: "Page 1",
13-
content: {
14-
type: "doc",
15-
content: [
16-
{
17-
type: "paragraph",
18-
content: [{ type: "text", text: "This is page 1" }],
19-
},
20-
],
21-
},
22-
},
23-
24-
{
25-
title: "Page 2",
26-
content: {
27-
type: "doc",
28-
content: [
29-
{
30-
type: "paragraph",
31-
content: [{ type: "text", text: "This is page 2" }],
32-
},
33-
],
34-
},
35-
},
36-
37-
{
38-
title: "Page 3",
39-
content: {
40-
type: "doc",
41-
content: [
42-
{
43-
type: "paragraph",
44-
content: [{ type: "text", text: "This is page 3" }],
45-
},
46-
],
47-
},
48-
},
49-
];
50-
51-
const getPageFromID = (id: number) => {
52-
return pages[id];
53-
};
3+
import { usePage } from "@/hooks/usePages";
544

555
export default function EditorView() {
566
const { currentPage } = usePageStore();
57-
if (currentPage === null) {
58-
return null;
59-
}
7+
const { data } = usePage(currentPage);
608

61-
const defaultEditorContent = getPageFromID(currentPage).content;
62-
if (!defaultEditorContent) {
63-
return (
64-
<div>
65-
페이지를 로딩할 수 없었습니다<div className=""></div>
66-
</div>
67-
);
9+
if (!data) {
10+
return <div></div>;
6811
}
6912

70-
return (
71-
<Editor
72-
key={currentPage}
73-
initialValue={defaultEditorContent}
74-
pageId={currentPage}
75-
/>
76-
);
13+
return <Editor key={data.id} initialValue={data.content} pageId={data.id} />;
7714
}

frontend/src/components/sidebar/NoteList.tsx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,53 @@
1-
import { cn } from "@/lib/utils";
2-
import usePageStore from "@/store/usePageStore";
1+
import { Trash2 } from "lucide-react";
2+
3+
import RemoveNoteModal from "./RemoveNoteModal";
34

4-
const noteList = [
5-
{ id: 0, icon: "🌳", title: "그라운드 룰" },
6-
{ id: 1, icon: "🚩", title: "커밋 컨벤션" },
7-
{ id: 2, icon: "🗂️", title: "데일리 스크럼" },
8-
];
5+
import { useNoteList } from "@/hooks/useNoteList";
6+
import { cn } from "@/lib/utils";
97

108
interface NoteListProps {
119
className?: string;
1210
}
1311

1412
export default function NoteList({ className }: NoteListProps) {
15-
const { setCurrentPage } = usePageStore();
13+
const {
14+
data,
15+
isModalOpen,
16+
handleNoteClick,
17+
openModal,
18+
onConfirm,
19+
onCloseModal,
20+
} = useNoteList();
1621

17-
const handleNoteClick = (id: number) => {
18-
setCurrentPage(id);
19-
};
22+
if (!data) {
23+
return <div>로딩중</div>;
24+
}
2025

2126
return (
2227
<div className={cn("flex flex-col gap-0.5 text-sm font-medium", className)}>
23-
{noteList.map(({ id, icon, title }) => (
28+
<RemoveNoteModal
29+
isOpen={isModalOpen}
30+
onConfirm={onConfirm}
31+
onCloseModal={onCloseModal}
32+
/>
33+
{data.map(({ id, title }) => (
2434
<button
2535
onClick={() => handleNoteClick(id)}
2636
key={id}
27-
className="flex flex-row gap-1 rounded-sm px-2 py-1 hover:bg-neutral-100"
37+
className="group flex flex-row justify-between rounded-sm px-2 py-1 hover:bg-neutral-100"
2838
>
29-
<div>{icon}</div>
30-
<div>{title}</div>
39+
<div className="flex flex-row gap-1">
40+
<div>{title}</div>
41+
</div>
42+
<span
43+
className="hidden text-neutral-400 transition-colors hover:text-red-500 group-hover:block"
44+
onClick={(e) => {
45+
e.stopPropagation();
46+
openModal(id);
47+
}}
48+
>
49+
<Trash2 width={20} height={20} />
50+
</span>
3151
</button>
3252
))}
3353
</div>

frontend/src/components/sidebar/Tools.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
import { PencilLine } from "lucide-react";
22

3+
import { useCreatePage, usePages } from "@/hooks/usePages";
4+
import usePageStore from "@/store/usePageStore";
5+
6+
// TODO: 에디터 렌더링할 때 필요한 id 받아오는 방법 수정 해야할듯
37
export default function Tools() {
8+
const { setCurrentPage } = usePageStore();
9+
const { data } = usePages();
10+
const createMutation = useCreatePage();
11+
12+
if (!data) {
13+
return <div>로딩중...</div>;
14+
}
15+
416
return (
5-
<button className="flex flex-row items-center gap-1 rounded-sm px-2 py-1 font-medium hover:bg-neutral-100">
17+
<button
18+
className="flex flex-row items-center gap-1 rounded-sm px-2 py-1 font-medium hover:bg-neutral-100"
19+
onClick={() => {
20+
createMutation.mutate({
21+
title: "제목 없음",
22+
content: {
23+
type: "doc",
24+
content: [
25+
{
26+
type: "paragraph",
27+
content: [{ type: "text", text: "This is page 1" }],
28+
},
29+
],
30+
},
31+
x: 0,
32+
y: 0,
33+
});
34+
setCurrentPage(data[data.length - 1].id);
35+
}}
36+
>
637
<div>
738
<PencilLine width={20} height={20} widths={1} />
839
</div>

0 commit comments

Comments
 (0)