Skip to content

Commit 3957d43

Browse files
committed
fix: API 명세 변경에 따른 쿼리 수정
1 parent 75a436d commit 3957d43

File tree

10 files changed

+61
-34
lines changed

10 files changed

+61
-34
lines changed

frontend/src/api/node.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ export interface NodeCoors {
1111
y: number;
1212
}
1313

14+
interface NodeResponse {
15+
message: string;
16+
coordinate: NodeCoors;
17+
}
18+
1419
export const getNodeCoors = async (id: number) => {
1520
const url = `/node${id}`;
1621

17-
const res = await Get<NodeCoors>(url);
22+
const res = await Get<NodeResponse>(url);
1823
return res.data;
1924
};
2025

frontend/src/api/page.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,46 @@ import { JSONContent } from "novel";
22

33
import { Get, Post, Delete, Patch } from "@/lib/axios";
44

5-
export type Page = {
5+
export interface Page {
66
id: number;
77
title: string;
88
content: JSONContent;
9-
};
9+
}
1010

11-
export type CreatePageRequest = {
11+
export interface CreatePageRequest {
1212
title: string;
1313
content: JSONContent;
1414
x: number;
1515
y: number;
16-
};
16+
}
1717

18-
export type PageRequest = {
18+
export interface PageRequest {
1919
title: string;
2020
content: JSONContent;
21-
};
21+
}
22+
23+
export interface PageResponse {
24+
message: string;
25+
page: Page;
26+
}
27+
28+
export interface PagesResponse {
29+
message: string;
30+
pages: Omit<Page, "content">[];
31+
}
2232

2333
export const getPage = async (id: number) => {
2434
const url = `/page/${id}`;
2535

26-
const res = await Get<Page>(url);
27-
return res.data;
36+
const res = await Get<PageResponse>(url);
37+
return res.data.page;
2838
};
2939

3040
export const getPages = async () => {
3141
const url = "/page";
3242

33-
const res = await Get<Page[]>(url);
34-
return res.data;
43+
const res = await Get<PagesResponse>(url);
44+
return res.data.pages;
3545
};
3646

3747
export const createPage = async (pageData: CreatePageRequest) => {

frontend/src/components/EditorView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { usePage } from "@/hooks/usePages";
44

55
export default function EditorView() {
66
const { currentPage } = usePageStore();
7-
const { data } = usePage(currentPage);
7+
const { page } = usePage(currentPage);
88

9-
if (!data) {
9+
if (!page) {
1010
return <div></div>;
1111
}
1212

13-
return <Editor key={data.id} initialValue={data.content} pageId={data.id} />;
13+
return (
14+
<Editor key={page.id} initialContent={page.content} pageId={page.id} />
15+
);
1416
}

frontend/src/components/canvas/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function Canvas({ className }: CanvasProps) {
3131
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);
3232
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
3333

34-
const { data: pages } = usePages();
34+
const { pages } = usePages();
3535

3636
useEffect(() => {
3737
if (!pages) {

frontend/src/components/editor/EditorView.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { useDebouncedCallback } from "use-debounce";
1414

1515
export default function EditorView() {
1616
const { currentPage } = usePageStore();
17-
const { data, isLoading } = usePage(currentPage);
18-
const pageTitle = data?.title ?? "제목없음";
19-
const pageContent = data?.content ?? {};
17+
const { page, isLoading } = usePage(currentPage);
18+
const pageTitle = page?.title ?? "제목없음";
19+
const pageContent = page?.content ?? {};
2020

2121
const updatePageMutation = useUpdatePage();
2222
const optimisticUpdatePageMutation = useOptimisticUpdatePage({
@@ -59,8 +59,14 @@ export default function EditorView() {
5959
500,
6060
);
6161

62-
if (isLoading || !data || currentPage === null) {
63-
return <div>로딩 중,,</div>;
62+
if (isLoading || !page || currentPage === null) {
63+
return (
64+
<div>
65+
{isLoading && <div>"isLoading"</div>}
66+
{!page && <div>"!page"</div>}
67+
{currentPage === null && <div>"currrentPage === null"</div>}
68+
</div>
69+
);
6470
}
6571

6672
return (

frontend/src/components/sidebar/NoteList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ interface NoteListProps {
1212

1313
export default function NoteList({ className }: NoteListProps) {
1414
const {
15-
data,
15+
pages,
1616
isModalOpen,
1717
handleNoteClick,
1818
openModal,
1919
onConfirm,
2020
onCloseModal,
2121
} = useNoteList();
2222

23-
if (!data) {
23+
if (!pages) {
2424
return <div>로딩중</div>;
2525
}
2626

@@ -31,7 +31,7 @@ export default function NoteList({ className }: NoteListProps) {
3131
onConfirm={onConfirm}
3232
onCloseModal={onCloseModal}
3333
/>
34-
{data.map(({ id, title }) => (
34+
{pages.map(({ id, title }) => (
3535
<Button
3636
onClick={() => handleNoteClick(id)}
3737
key={id}

frontend/src/components/sidebar/Tools.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import Button from "../commons/button";
77
// TODO: 에디터 렌더링할 때 필요한 id 받아오는 방법 수정 해야할듯
88
export default function Tools() {
99
const { setCurrentPage } = usePageStore();
10-
const { data } = usePages();
10+
const { pages } = usePages();
1111
const createMutation = useCreatePage();
1212

13-
if (!data) {
13+
if (!pages) {
1414
return <div>로딩중...</div>;
1515
}
1616

@@ -32,7 +32,7 @@ export default function Tools() {
3232
x: 0,
3333
y: 0,
3434
});
35-
setCurrentPage(data[data.length - 1].id);
35+
setCurrentPage(pages[pages.length - 1].id);
3636
}}
3737
>
3838
<div>

frontend/src/hooks/useNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
// queryFn: () => getNodeCoors(id),
1313
// });
1414

15-
// return { data, isError };
15+
// return { coors:data?.coordinates, isError };
1616
// };
1717

1818
export const useCreateNode = () => {

frontend/src/hooks/useNoteList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useDeletePage, usePages } from "./usePages";
55

66
export const useNoteList = () => {
77
const { setCurrentPage } = usePageStore();
8-
const { data } = usePages();
8+
const { pages } = usePages();
99

1010
const [noteIdToDelete, setNoteIdToDelete] = useState<number | null>(null);
1111
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -36,7 +36,7 @@ export const useNoteList = () => {
3636
};
3737

3838
return {
39-
data,
39+
pages,
4040
isModalOpen,
4141
handleNoteClick,
4242
openModal,

frontend/src/hooks/usePages.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ import {
1616
} from "@/api/page";
1717

1818
export const usePage = (currentPage: number | null) => {
19-
const { data, isError, isLoading } = useQuery({
19+
const {
20+
data: page,
21+
isError,
22+
isLoading,
23+
} = useQuery({
2024
queryKey: ["page", currentPage],
2125
queryFn: currentPage ? () => getPage(currentPage) : skipToken,
2226
});
2327

24-
return { data, isError, isLoading };
28+
return { page, isError, isLoading };
2529
};
2630

2731
export const useCreatePage = () => {
@@ -48,12 +52,12 @@ export const useDeletePage = () => {
4852
};
4953

5054
export const usePages = () => {
51-
const { data, isError } = useQuery({
55+
const { data: pages, isError } = useQuery({
5256
queryKey: ["pages"],
5357
queryFn: getPages,
5458
});
5559

56-
return { data, isError };
60+
return { pages, isError };
5761
};
5862

5963
export const useUpdatePage = () => {
@@ -90,7 +94,7 @@ export const useOptimisticUpdatePage = ({ id }: { id: number }) => {
9094
rollback?.();
9195
},
9296
onSettled: () => {
93-
queryClient.invalidateQueries({ queryKey: ["page", id] });
97+
// queryClient.invalidateQueries({ queryKey: ["page", id] });
9498
queryClient.invalidateQueries({ queryKey: ["pages"] });
9599
},
96100
});

0 commit comments

Comments
 (0)