From bb96bd5582442664c841b361ebedec63d0cf1ace Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 15 Oct 2023 10:39:40 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=EB=AC=B8=EC=A0=9C=EC=88=98=20UI=20?= =?UTF-8?q?=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages-edit/home/components/MakeOfficial.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages-edit/home/components/MakeOfficial.tsx b/src/pages-edit/home/components/MakeOfficial.tsx index 91a5c28..86b15b3 100644 --- a/src/pages-edit/home/components/MakeOfficial.tsx +++ b/src/pages-edit/home/components/MakeOfficial.tsx @@ -140,11 +140,11 @@ const MakeOfficial = (props: QuestionProps) => { {QSet.questionCursor[0].currentQ} - 아직 - {QSet.questionCursor[0].QsetLength - - QSet.questionCursor[0].cursor + - 1} - 문제 남았어요! + 아직 + + {10 - QSet.questionCursor[0].cursor + 1} + 문제 남았어요! + Date: Sun, 15 Oct 2023 10:42:29 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20=EB=AC=B8=EC=A0=9C=EC=88=98=20UI=20?= =?UTF-8?q?=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages-edit/home/components/MakeOfficial.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages-edit/home/components/MakeOfficial.tsx b/src/pages-edit/home/components/MakeOfficial.tsx index 86b15b3..76ba699 100644 --- a/src/pages-edit/home/components/MakeOfficial.tsx +++ b/src/pages-edit/home/components/MakeOfficial.tsx @@ -142,7 +142,9 @@ const MakeOfficial = (props: QuestionProps) => { 아직 - {10 - QSet.questionCursor[0].cursor + 1} + {QSet.questionCursor[0].QsetLength - + QSet.questionCursor[0].cursor + + 1} 문제 남았어요! From 7c2e923881d14ca6f65b63975acdbee21692514e Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 29 Oct 2023 06:01:55 +0900 Subject: [PATCH 3/7] =?UTF-8?q?design:=20isChoiced=20&&=20isViewed=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EC=97=90=EC=84=9C=EC=9D=98=20UI=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages-edit/home/components/QfeedFrame.tsx | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/pages-edit/home/components/QfeedFrame.tsx b/src/pages-edit/home/components/QfeedFrame.tsx index ea41441..4053066 100644 --- a/src/pages-edit/home/components/QfeedFrame.tsx +++ b/src/pages-edit/home/components/QfeedFrame.tsx @@ -50,10 +50,17 @@ const QfeedFrame = ({ idx, colorIdx, feed, detail }: FeedProps) => { { - {feed.isChoiced ? undefined : ( - - {feed.isViewed && !detail ? ( - - ) : imageurl ? ( - - ) : ( - - )} - - )} + + {feed.isChoiced && !detail ? ( + + ) : imageurl ? ( + + ) : ( + + )} + + {imageurl && ( { placeholder="blur" blurDataURL="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAECAQAAADhJE2MAAAAEElEQVR42mMs/c8ABIzYKABcTgXVauTJNQAAAABJRU5ErkJggg==" backgroundcolor={ - feed.isViewed && !detail + feed.isChoiced && !detail ? colors.light_gray2 : colors[getAppStateColor(colorIdx)] } @@ -127,13 +130,17 @@ const QFeedWrapper = styled.div` bottom: 28px; `; -const QfeedFrameInner = styled.div<{ imageurl: string; backgroundcolor: any }>` +const QfeedFrameInner = styled.div<{ + imageurl: string; + backgroundcolor: any; + border: string; +}>` padding: 28px 20px; overflow: hidden; text-align: left; border-radius: 10px; - border: 3px solid ${({ backgroundcolor }) => backgroundcolor}; + border: ${({ border }) => border}; color: ${({ imageurl }) => imageurl ? colors.light_qwhite : colors.light_qblack}; background-color: ${({ imageurl, backgroundcolor }) => From d5b4fc22de3eb9110a2829894f11e6c9bf7c3386 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 29 Oct 2023 06:32:58 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/questions/index.ts | 5 + src/app/(padding)/question/[id]/page.tsx | 164 ++++++++++-------- .../questions/useDeleteQuestionMutation.ts | 19 ++ src/hooks/questions/useGetQuestionId.ts | 3 +- src/models/questions.ts | 31 ++++ 5 files changed, 152 insertions(+), 70 deletions(-) create mode 100644 src/hooks/questions/useDeleteQuestionMutation.ts diff --git a/src/apis/questions/index.ts b/src/apis/questions/index.ts index 92a65de..81a4a8e 100644 --- a/src/apis/questions/index.ts +++ b/src/apis/questions/index.ts @@ -20,6 +20,11 @@ export const postQuestions = async (body: any) => .then(({ data }) => data) .catch((err) => err.response); +export const deleteQuestions = async (questionId: number) => { + const response = await qFeedAxios.patch(`/questions/${questionId}`); + return response.data; +}; + export const postQuestionsIdChoices = async (questionId: any, choice: string) => await qFeedAxios .post(`/questions/${questionId}/choices`, { value: choice }) diff --git a/src/app/(padding)/question/[id]/page.tsx b/src/app/(padding)/question/[id]/page.tsx index 0fd5a28..ee87aec 100644 --- a/src/app/(padding)/question/[id]/page.tsx +++ b/src/app/(padding)/question/[id]/page.tsx @@ -6,16 +6,19 @@ import Text from "src/components/common/Text"; import NavigationTopBack from "src/components/navigations/NavigationTopBack"; import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; import { useAppDispatch, useAppSelector } from "src/hooks/useReduxHooks"; import { changeAction, changeVisibleType } from "src/reducer/slices/bottomSheet/bottomSheetSlice"; import Image from "src/components/Image"; + import { useGetQuestionsId } from "src/hooks/questions/useGetQuestionId"; import VoteButton from "src/components/Button/VoteButton"; import { useUserQuery } from "src/hooks/account/useUserQuery"; import useQChoiceMutation from "src/hooks/questions/useQChoiceMutation"; +import useDeleteQuestionMutation from "src/hooks/questions/useDeleteQuestionMutation"; import Loading from "src/components/common/Loading"; import Icon from "src/components/Icon"; @@ -23,15 +26,17 @@ export default function Page({ params }: { params: { id: number } }) { const { data: questionData, isLoading } = useGetQuestionsId({ questionId: params.id }); - console.log(questionData); - const { user } = useUserQuery(); + const user = useUserQuery(); const { mutate } = useQChoiceMutation(params.id); + const { deleteQMutation } = useDeleteQuestionMutation(); const dispatch = useAppDispatch(); + const router = useRouter(); + // choices에 본인이 있는지 확인 const checkName = (el: any) => { - if (el?.user?.id === user?.id) { + if (el?.user?.id === user?.user?.id) { return true; } }; @@ -40,13 +45,20 @@ export default function Page({ params }: { params: { id: number } }) { const checkBest = () => { const choices = questionData?.choiceList; let best = []; - for (let i = 0; i < questionData?.choiceList?.length; i++) { + for ( + let i = 0; + i < + (questionData?.choiceList?.length + ? questionData?.choiceList?.length + : 0); + i++ + ) { const value = questionData?.choices?.filter( (data: any, idx: number) => { - return data?.value == choices[i]; + return choices && data?.value == choices[i]; } ); - best.push(value.length); + value && best.push(value.length); } setBest(best); }; @@ -67,18 +79,18 @@ export default function Page({ params }: { params: { id: number } }) { useEffect(() => { setTypeNum( questionData?.choices.some(checkName) || - questionData?.owner?.id === user?.id + questionData?.owner?.id === user?.user?.id ? 2 : 0 ); const s = questionData?.choices?.filter( - (data: any) => data?.user?.id === user?.id + (data: any) => data?.user?.id === user?.user?.id ); setSelected(s?.length !== 0 ? Number(s?.[0]?.value) : -1); checkBest(); }, [questionData]); - return isLoading ? ( + return isLoading || user.isLoading ? ( ) : ( @@ -104,21 +116,32 @@ export default function Page({ params }: { params: { id: number } }) { {questionData?.choices?.length}명 응답 - - dispatch( - changeVisibleType({ - type: "bottomSheet", - value: [ - 1, - "reportBlock", - questionData?.owner?.id - ] - }) - ) - } - /> + {questionData?.owner?.id === user?.user?.id ? ( + { + questionData && + deleteQMutation.mutate(questionData.id); + router.back(); + }} + /> + ) : ( + + dispatch( + changeVisibleType({ + type: "bottomSheet", + value: [ + 1, + "reportBlock", + questionData?.owner?.id + ] + }) + ) + } + /> + )} } transparent @@ -135,51 +158,54 @@ export default function Page({ params }: { params: { id: number } }) { - - - {questionData.choiceList?.map( - (choice: string, idx: number) => { - return ( - - data2.value == - questionData?.choiceList[idx] - ).length === Math.max(...best) // best - ? 2 - : idx === selected - ? 1 - : 0 - } // 0 1 2 - selected={selected} - onClick={ - typeNum === 2 - ? () => {} - : () => clickChoice(idx, choice) - } - count={ - questionData?.choices?.filter( - (choiceItem: any) => - choiceItem.value == choice - ).length - } - > - {choice} - - ); - } - )} - + {questionData && ( + + {questionData.choiceList?.map( + (choice: string, idx: number) => { + return ( + + data2.value == + questionData?.choiceList[ + idx + ] + ).length === Math.max(...best) // best + ? 2 + : idx === selected + ? 1 + : 0 + } // 0 1 2 + selected={selected} + onClick={ + typeNum === 2 + ? () => {} + : () => clickChoice(idx, choice) + } + count={ + questionData?.choices?.filter( + (choiceItem: any) => + choiceItem.value == choice + ).length + } + > + {choice} + + ); + } + )} + + )} ); diff --git a/src/hooks/questions/useDeleteQuestionMutation.ts b/src/hooks/questions/useDeleteQuestionMutation.ts new file mode 100644 index 0000000..a9b23f2 --- /dev/null +++ b/src/hooks/questions/useDeleteQuestionMutation.ts @@ -0,0 +1,19 @@ +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { deleteQuestions } from "src/apis/questions"; +import { questionKeys } from "src/constants/queryKeys/questionKeys"; + +const useDeleteQuestionMutation = () => { + const queryClient = useQueryClient(); + const deleteQMutation = useMutation( + (questionId: number) => deleteQuestions(questionId), + { + onSuccess: () => { + queryClient.invalidateQueries(questionKeys.all); + }, + onError: () => {} + } + ); + return { deleteQMutation }; +}; + +export default useDeleteQuestionMutation; diff --git a/src/hooks/questions/useGetQuestionId.ts b/src/hooks/questions/useGetQuestionId.ts index f182e63..9b222e9 100644 --- a/src/hooks/questions/useGetQuestionId.ts +++ b/src/hooks/questions/useGetQuestionId.ts @@ -1,9 +1,10 @@ import { useQuery } from "@tanstack/react-query"; import { getQuestionsId } from "src/apis/questions"; import { questionKeys } from "src/constants/queryKeys/questionKeys"; +import { QuestionById } from "src/models/questions"; export const useGetQuestionsId = ({ questionId }: { questionId: number }) => { - const { data, isLoading, error, refetch } = useQuery( + const { data, isLoading, error, refetch } = useQuery( questionKeys.detail(questionId), async () => { const result = getQuestionsId(questionId); diff --git a/src/models/questions.ts b/src/models/questions.ts index 0a635d5..4c28286 100644 --- a/src/models/questions.ts +++ b/src/models/questions.ts @@ -1,3 +1,5 @@ +import { User } from "./account"; + export type Qtype = "official" | "personal"; export interface Questions { @@ -57,3 +59,32 @@ export interface Question { backgroundImage: string; isBlind: boolean; } + +export interface QuestionById { + id: number; + owner: Partial; + title: string; + choiceList: string[]; + backgroundImage: string; + Qtype: Qtype; + isBlind: boolean; + viewHistories: [ + { + id: number; + user: Partial; + createdAt: string; + updatedAt: string; + } + ]; + choices: [ + { + id: number; + user: Partial; + value: string; + createdAt: string; + updatedAt: string; + } + ]; + createdAt: string; + updatedAt: string; +} From d2f4375de32dd367065657105c5a048f8bb0a205 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 29 Oct 2023 06:36:28 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=ED=94=BC=EB=93=9C=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=2024=EC=8B=9C=EA=B0=84=20=EC=9D=B4=EC=83=81=EC=9D=80?= =?UTF-8?q?=20=EC=9D=BC=EB=8B=A8=EC=9C=84=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages-edit/home/components/QfeedFrame.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages-edit/home/components/QfeedFrame.tsx b/src/pages-edit/home/components/QfeedFrame.tsx index 4053066..9e89d00 100644 --- a/src/pages-edit/home/components/QfeedFrame.tsx +++ b/src/pages-edit/home/components/QfeedFrame.tsx @@ -34,7 +34,9 @@ const QfeedFrame = ({ idx, colorIdx, feed, detail }: FeedProps) => { ); return pastMin ? `${pastMin}분 전` : "방금 전"; } else { - return `${pastTime}시간 전`; + return pastTime < 24 + ? `${pastTime}시간 전` + : `${Math.floor(pastTime / 24)}일 전`; } }; From 195fe527d931cc6a6c8e2335e6a0fafb50fe3d52 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 29 Oct 2023 06:38:23 +0900 Subject: [PATCH 6/7] =?UTF-8?q?design:=20=EC=B0=A8=EB=8B=A8=20=EC=9B=8C?= =?UTF-8?q?=EB=94=A9=20=EC=9E=84=EC=8B=9C=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(padding)/friend/[id]/@modal/block/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/(padding)/friend/[id]/@modal/block/page.tsx b/src/app/(padding)/friend/[id]/@modal/block/page.tsx index b583010..897f87b 100644 --- a/src/app/(padding)/friend/[id]/@modal/block/page.tsx +++ b/src/app/(padding)/friend/[id]/@modal/block/page.tsx @@ -12,7 +12,7 @@ export default function BlockModal({ params }: { params: { id: number } }) { router.back()} title="차단하시겠어요?" - detail="쪽지 수신 및 발신이 모두 차단되며,\n다시 해제하실 수 있습니다." + detail="해당 유저의 질문을 볼 수 없으며,\n다시 해제하실 수 있습니다." rightText="차단" rightClick={() => { blockFriend.mutate(params.id); From bc353d6284cfbde1423fdb0d9982af12df6eabf6 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 29 Oct 2023 07:08:02 +0900 Subject: [PATCH 7/7] fix: questionById undefined --- src/pages-edit/mypage/SelectDetailPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages-edit/mypage/SelectDetailPage.tsx b/src/pages-edit/mypage/SelectDetailPage.tsx index 35fc57b..561ecf9 100644 --- a/src/pages-edit/mypage/SelectDetailPage.tsx +++ b/src/pages-edit/mypage/SelectDetailPage.tsx @@ -43,9 +43,9 @@ const SelectDetailPage = ({ params }: { params: { id: number } }) => { ) : ( <> - {data.title} + {data?.title} - {data.choices.map((choice: any) => ( + {data?.choices.map((choice: any) => (