From 581907a5f07954e2ed9658b815e9474ed865ce21 Mon Sep 17 00:00:00 2001 From: Jeon Jinho Date: Mon, 19 Feb 2024 16:09:47 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=ED=95=9C=20=ED=86=A0=ED=94=BD=EC=9D=B8=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=A1=B0=ED=9A=8C=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: get method to throw error * fix: check if member created topic * fiX: remove console.log * refactor: remove another console.logs --- src/apis/fetch.ts | 11 ++++++++--- src/components/Home/TopicCard/TopicCard.tsx | 11 ++++++++--- src/hooks/useOAuth/useOAuth.ts | 1 - src/utils/scrollLock.ts | 1 - 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/apis/fetch.ts b/src/apis/fetch.ts index 47791e9..ce20ac7 100644 --- a/src/apis/fetch.ts +++ b/src/apis/fetch.ts @@ -17,7 +17,7 @@ class Fetch { this.baseURL = import.meta.env.VITE_API_BASE_URL; } - async get(path: string, qs?: Record): Promise { + async get(path: string, qs?: Record) { const queryString = qs ? `?${new URLSearchParams(qs).toString()}` : ''; const response = await fetch(`${this.baseURL}${path}${queryString}`, { method: 'GET', @@ -26,8 +26,13 @@ class Fetch { ...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }), }, }); - const data: T = await response.json(); - return data; + const data = await response.json(); + + if (!response.ok) { + throw new ResponseError(data); + } + + return data as TData; } async post({ diff --git a/src/components/Home/TopicCard/TopicCard.tsx b/src/components/Home/TopicCard/TopicCard.tsx index b3cd450..977f694 100644 --- a/src/components/Home/TopicCard/TopicCard.tsx +++ b/src/components/Home/TopicCard/TopicCard.tsx @@ -15,6 +15,8 @@ import useBottomSheet from '@hooks/useBottomSheet/useBottomSheet'; import { LatestComment } from '@interfaces/api/comment'; import { Choice, TopicResponse } from '@interfaces/api/topic'; +import { useAuthStore } from '@store/auth'; + import { colors } from '@styles/theme'; import { LeftDoubleArrowIcon, RightDoubleArrowIcon } from '@icons/index'; @@ -38,12 +40,15 @@ interface TopicCardProps { const TopicCard = ({ topic }: TopicCardProps) => { const [, setSearchParams] = useSearchParams(); + const memberId = useAuthStore((store) => store.memberId); + const isMyTopic = topic.author.id === memberId; + const swiperSlide = useSwiperSlide(); const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({}); const voteMutation = useVoteTopic(); const { data: latestCommentData, isSuccess } = useLatestComment( topic.topicId, - topic.selectedOption !== null + topic.selectedOption !== null || isMyTopic ); const [latestComment, setLatestComment] = useState(); @@ -65,7 +70,7 @@ const TopicCard = ({ topic }: TopicCardProps) => { }, [isSuccess]); const handleOnClickCommentBox = () => { - if (topic.selectedOption !== null) { + if (isMyTopic || topic.selectedOption !== null) { toggleSheet(); } }; @@ -137,7 +142,7 @@ const TopicCard = ({ topic }: TopicCardProps) => { { // 슀크둀 잠금 ν•΄μ œ export const disableScrollLock = () => { const { body } = document; - console.log('πŸš€ ~ disableScrollLock ~ body:', body.getAttribute('scrollY')); if (body.getAttribute('scrollY')) { body.style.removeProperty('overflow');