-
Notifications
You must be signed in to change notification settings - Fork 4
๐ ์ต๊ทผ 5๊ฐ ์ด์ ์์ (#405-#409) #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e5b4f9a
88c6168
94a1a84
4a3ec54
b684ca9
fc19a1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,26 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { AxiosError } from "axios"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import useAuthStore from "@/lib/zustand/useAuthStore"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { toast } from "@/lib/zustand/useToastStore"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CommunityQueryKeys, communityApi, type PostIdResponse, type PostUpdateRequest } from "./api"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface UpdatePostVariables { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| postId: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: PostUpdateRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boardCode?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @description ISR ํ์ด์ง๋ฅผ revalidateํ๋ ํจ์ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param boardCode - ๊ฒ์ํ ์ฝ๋ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param accessToken - ์ฌ์ฉ์ ์ธ์ฆ ํ ํฐ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const revalidateCommunityPage = async (boardCode: string, accessToken: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!accessToken) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("Revalidation skipped: No access token available"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await fetch("/api/revalidate", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: "POST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Content-Type": "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Authorization: `Bearer ${accessToken}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: JSON.stringify({ boardCode }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฌ๊ธฐ๋ revalidate ์คํจ๊ฐ ์จ๊ฒจ์ง ์ ์์ด์. ๐ง ์์ ์ ์- await fetch("/api/revalidate", {
+ const response = await fetch("/api/revalidate", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ boardCode }),
});
+ if (!response.ok) {
+ throw new Error(`Revalidate failed: ${response.status}`);
+ }๐ Committable suggestion
Suggested change
๐ค Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Revalidate failed:", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @description ๊ฒ์๊ธ ์์ ์ ์ํ useMutation ์ปค์คํ ํ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const useUpdatePost = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const queryClient = useQueryClient(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { accessToken } = useAuthStore(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return useMutation<PostIdResponse, AxiosError, UpdatePostVariables>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: ({ postId, data }) => communityApi.updatePost(postId, data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: (_result, variables) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: async (_result, variables) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ํด๋น ๊ฒ์๊ธ ์์ธ ์ฟผ๋ฆฌ์ ๋ชฉ๋ก ์ฟผ๋ฆฌ๋ฅผ ๋ฌดํจํ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts, variables.postId] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: [CommunityQueryKeys.posts] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ISR ํ์ด์ง revalidate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (variables.boardCode && accessToken) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await revalidateCommunityPage(variables.boardCode, accessToken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success("๊ฒ์๊ธ์ด ์์ ๋์์ต๋๋ค."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onError: (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISR revalidate๊ฐ โ์กฐ์ฉํ ์คํจโํ ์ ์์ด์.
fetch๋ 4xx/5xx์์๋ ์์ธ๋ฅผ ๋์ง์ง ์์์, ํ์ฌ๋ ์คํจ๊ฐ ๋ก๊ทธ ์์ด ํต๊ณผ๋ ์ ์์ต๋๋ค. ์๋ต ok ์ฒดํฌ๋ฅผ ์ถ๊ฐํด ์ฃผ์ธ์.
๐ง ์์ ์ ์
๐ค Prompt for AI Agents