Skip to content

Commit 7a67d66

Browse files
committed
feat: query를 이용한 페이지 업데이트
1 parent 31d1768 commit 7a67d66

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

frontend/src/components/editor/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TextButtons } from "./selectors/text-buttons";
2323
import { ColorSelector } from "./selectors/color-selector";
2424

2525
import { useDebouncedCallback } from "use-debounce";
26+
import { useUpdatePage } from "@/hooks/usePages";
2627

2728
const extensions = [...defaultExtensions, slashCommand];
2829

@@ -32,10 +33,12 @@ interface EditorProp {
3233
onChange?: (value: JSONContent) => void;
3334
}
3435

36+
// TODO: 나중에 title input 추가해야함
3537
const Editor = ({ pageId, initialValue }: EditorProp) => {
3638
const [initialContent, setInitialContent] = useState<null | JSONContent>(
3739
initialValue === undefined ? null : initialValue,
3840
);
41+
const updateMutation = useUpdatePage(pageId);
3942

4043
const [openNode, setOpenNode] = useState(false);
4144
const [openColor, setOpenColor] = useState(false);
@@ -56,6 +59,13 @@ const Editor = ({ pageId, initialValue }: EditorProp) => {
5659
if (pageId === undefined) return;
5760

5861
const json = editor.getJSON();
62+
updateMutation.mutate({
63+
id: pageId,
64+
pageData: {
65+
title: "제목 없음",
66+
content: json,
67+
},
68+
});
5969
window.localStorage.setItem(
6070
"html-content",
6171
highlightCodeblocks(editor.getHTML()),

frontend/src/hooks/usePages.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ export const useDeletePage = () => {
5656
});
5757
};
5858

59-
export const useUpdatePage = () => {
59+
export const useUpdatePage = (pageId: number) => {
60+
const queryClient = useQueryClient();
61+
6062
return useMutation({
6163
mutationFn: ({ id, pageData }: { id: number; pageData: PageRequest }) =>
6264
updatePage(id, pageData),
65+
onSuccess: () => {
66+
queryClient.invalidateQueries({ queryKey: ["page", pageId] });
67+
},
6368
});
6469
};

0 commit comments

Comments
 (0)