From 0df6460ae502aa338cd29d7341374021bccd86c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=EC=A7=84=ED=98=B8?= Date: Fri, 5 Jan 2024 20:16:29 +0900 Subject: [PATCH 1/3] feat: add delete method --- src/apis/fetch.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/apis/fetch.ts b/src/apis/fetch.ts index 264df23..29b3576 100644 --- a/src/apis/fetch.ts +++ b/src/apis/fetch.ts @@ -61,6 +61,18 @@ class Fetch { return data as TData; } + async delete(path: string): Promise { + const response = await fetch(`${this.baseURL}${path}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }), + }, + }); + const data: T = await response.json(); + return data; + } + setAccessToken(token: string) { this.accessToken = token; } From dbadffd7f6111ebaa772399d476f7e23dd67475a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=EC=A7=84=ED=98=B8?= Date: Fri, 5 Jan 2024 20:17:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EA=B0=9C=EB=B0=9C=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=EC=84=9C=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=20?= =?UTF-8?q?=ED=88=AC=ED=91=9C=20=EC=B7=A8=EC=86=8C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index 58c5998..abf2d7f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,14 +1,25 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import React from 'react'; +import React, { useEffect } from 'react'; import { StyleSheetManager, ThemeProvider } from 'styled-components'; import GlobalStyle from '@styles/global'; import { theme } from '@styles/theme'; +import client from '@apis/fetch'; + import Router from './routes'; const App = () => { const queryClient = new QueryClient(); + const isDev = import.meta.env.DEV; + + useEffect(() => { + if (isDev) { + [...Array.from({ length: 20 }, (_, i) => i + 1)].map((topicId) => { + client.delete(`topics/${topicId}/vote`); + }); + } + }, []); return ( true}> From 84b00d66b9ac337020aa26dca70b72ed56be0832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=84=EC=A7=84=ED=98=B8?= Date: Fri, 5 Jan 2024 20:17:23 +0900 Subject: [PATCH 3/3] fix: enable useLatestComment only has voted --- src/apis/comment/useComment.ts | 3 ++- src/components/Home/TopicCard/TopicCard.tsx | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/apis/comment/useComment.ts b/src/apis/comment/useComment.ts index 7698366..12e9420 100644 --- a/src/apis/comment/useComment.ts +++ b/src/apis/comment/useComment.ts @@ -48,10 +48,11 @@ const useComments = (topicId: number, enabled: boolean) => { }); }; -const useLatestComment = (topicId: number) => { +const useLatestComment = (topicId: number, enabled: boolean) => { return useQuery({ queryKey: [COMMENT_KEY, 'latest', topicId], queryFn: () => getComments({ topicId: topicId, page: 0, size: 1 }), + enabled: enabled, }); }; diff --git a/src/components/Home/TopicCard/TopicCard.tsx b/src/components/Home/TopicCard/TopicCard.tsx index c158820..40c6a48 100644 --- a/src/components/Home/TopicCard/TopicCard.tsx +++ b/src/components/Home/TopicCard/TopicCard.tsx @@ -55,7 +55,10 @@ const TopicCard = ({ topic }: TopicCardProps) => { const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({}); const voteMutation = useVoteTopic(); - const { data: latestCommentData, isSuccess } = useLatestComment(topic.topicId); + const { data: latestCommentData, isSuccess } = useLatestComment( + topic.topicId, + topic.selectedOption !== null + ); const [latestComment, setLatestComment] = useState(); useEffect(() => {