From e68643bedef0f339ce113ab5ec17ddc017942428 Mon Sep 17 00:00:00 2001 From: Seojisoo20191941 Date: Sun, 19 Nov 2023 23:43:39 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EA=B0=80=EC=9E=A5=20=EC=B5=9C?= =?UTF-8?q?=EA=B7=BC=20=ED=99=9C=EB=8F=99=20=ED=8C=8C=ED=8A=B8=20default?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Category/TagSelector/TagSelectOptions.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/feed/upload/Category/TagSelector/TagSelectOptions.tsx b/src/components/feed/upload/Category/TagSelector/TagSelectOptions.tsx index 7dbf0ea51..3cb2a9809 100644 --- a/src/components/feed/upload/Category/TagSelector/TagSelectOptions.tsx +++ b/src/components/feed/upload/Category/TagSelector/TagSelectOptions.tsx @@ -1,5 +1,7 @@ import styled from '@emotion/styled'; +import { useEffect, useMemo } from 'react'; +import { useGetMemberProfileOfMe } from '@/api/endpoint_LEGACY/hooks'; import Responsive from '@/components/common/Responsive'; import SquareLink from '@/components/common/SquareLink'; import { categories } from '@/components/feed/upload/Category/constants'; @@ -36,6 +38,27 @@ export default function TagSelectOptions({ onClose, onSave, feedData }: TagSelec category.id === feedData.mainCategoryId && category.children.some((tag) => tag.id === feedData.categoryId), ) ?? null; + const { data: myProfile } = useGetMemberProfileOfMe(); + + const sortedSoptActivities = useMemo(() => { + if (!myProfile?.soptActivities) { + return []; + } + const sorted = [...myProfile.soptActivities]; + sorted.sort((a, b) => b.generation - a.generation); + return sorted; + }, [myProfile?.soptActivities]); + + const partCategory = + parentCategory && parentCategory.children.find((category) => category.name === sortedSoptActivities[0]?.part); + + useEffect(() => { + if (feedData.mainCategoryId !== feedData.categoryId) return; + if (parentCategory?.name === '파트') { + onSave(partCategory ? partCategory.id : feedData.mainCategoryId); + } + }, [sortedSoptActivities]); + return ( <> diff --git a/src/components/feed/upload/Category/index.tsx b/src/components/feed/upload/Category/index.tsx index 0237a297a..f45e62495 100644 --- a/src/components/feed/upload/Category/index.tsx +++ b/src/components/feed/upload/Category/index.tsx @@ -1,5 +1,8 @@ -import { useEffect } from 'react'; +import { useQuery } from '@tanstack/react-query'; +import { useMemo } from 'react'; +import { getCategory } from '@/api/endpoint/feed/getCategory'; +import { useGetMemberProfileOfMe } from '@/api/endpoint_LEGACY/hooks'; import CategoryHeader from '@/components/feed/upload/Category/CategoryHeader'; import CategorySelector from '@/components/feed/upload/Category/CategorySelector'; import TagSelector from '@/components/feed/upload/Category/TagSelector'; @@ -24,30 +27,65 @@ export default function Category({ openCategory, openTag, openUsingRules, - checkIsOpenCategorys, }: CateogryProps) { - useEffect(() => { - if (feedData.categoryId === 0) return; - if (checkIsOpenCategorys) return; - if (feedData.categoryId === 1) { - openUsingRules(); - } else { - openTag(); + const { data: categories } = useQuery({ + queryKey: getCategory.cacheKey(), + queryFn: getCategory.request, + }); + + const { data: myProfile } = useGetMemberProfileOfMe(); + + const latestSoptPart = useMemo(() => { + if (!myProfile?.soptActivities || myProfile.soptActivities.length === 0) { + return null; } - }, [feedData]); + + return myProfile.soptActivities.reduce((latestActivity, activity) => { + if (latestActivity.generation < activity.generation) { + return activity; + } + return latestActivity; + }, myProfile.soptActivities[0]).part; + }, [myProfile?.soptActivities]); const handleSaveMainCategory = (categoryId: number) => { - onSaveCategory(categoryId); + const selectedMainCategory = categories?.find((category) => category.id === categoryId); + + if (selectedMainCategory == null) { + return; + } + onSaveMainCategory(categoryId); + + if (selectedMainCategory.children.length === 0) { + onSaveCategory(categoryId); + return; + } + + openTag(); + + if (selectedMainCategory.hasAll) { + onSaveCategory(categoryId); + return; + } + + if (selectedMainCategory.name === '파트') { + onSaveCategory( + selectedMainCategory.children.find((category) => category.name === latestSoptPart)?.id ?? + selectedMainCategory.children[0].id, + ); + return; + } + + onSaveCategory(selectedMainCategory.children[0].id); }; return ( <> Date: Mon, 20 Nov 2023 03:18:32 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EB=B9=8C=EB=93=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feed/upload/Category/CategorySelector/index.stories.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/feed/upload/Category/CategorySelector/index.stories.tsx b/src/components/feed/upload/Category/CategorySelector/index.stories.tsx index bd29bcd8b..c637eed64 100644 --- a/src/components/feed/upload/Category/CategorySelector/index.stories.tsx +++ b/src/components/feed/upload/Category/CategorySelector/index.stories.tsx @@ -17,7 +17,6 @@ export const Default = {