Skip to content
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

feat: 가장 최근 활동 파트 default 설정 구현 #1089

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import { UploadFeedDataType } from '@/components/feed/upload/types';
import { textStyles } from '@/styles/typography';

interface CategorySelectOptionsProp {
onNext: () => void;
onSave: (categoryId: number) => void;
feedData: UploadFeedDataType;
}

export default function CategorySelectOptions({ onSave, onNext, feedData }: CategorySelectOptionsProp) {
export default function CategorySelectOptions({ onSave, feedData }: CategorySelectOptionsProp) {
const handleSelectCategory = (categoryId: number) => {
onSave(categoryId);
onNext();
};

const { data: categories } = useQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export const Default = {
<Button onClick={onOpen}>클릭하여 셀렉터 열기</Button>
<CategorySelector
isOpen={isOpen}
onNext={onClose}
onClose={onClose}
onSave={onClose}
onSelect={onClose}
feedData={{
mainCategoryId: 0,
categoryId: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ import { textStyles } from '@/styles/typography';

interface CategorySelectorProps {
isOpen?: boolean;
onNext: () => void;
onClose: () => void;
onSave: (categoryId: number) => void;
onSelect: (categoryId: number) => void;
feedData: UploadFeedDataType;
}

export default function CategorySelector({ isOpen, onNext, onClose, onSave, feedData }: CategorySelectorProps) {
export default function CategorySelector({ isOpen, onClose, onSelect, feedData }: CategorySelectorProps) {
return (
<>
<Responsive only='desktop'>
<DropDown isOpen={isOpen} onClose={onClose} className='category-drop' header={<Title>어디에 올릴까요?</Title>}>
<CategorySelectOptions onNext={onNext} onSave={onSave} feedData={feedData} />
<CategorySelectOptions onSave={onSelect} feedData={feedData} />
</DropDown>
</Responsive>
<Responsive only='mobile'>
Expand All @@ -31,7 +30,7 @@ export default function CategorySelector({ isOpen, onNext, onClose, onSave, feed
className='category-drop'
header={<Title>어디에 올릴까요?</Title>}
>
<CategorySelectOptions onNext={onNext} onSave={onSave} feedData={feedData} />
<CategorySelectOptions onSave={onSelect} feedData={feedData} />
</BottomSheet>
</Responsive>
</>
Expand Down
64 changes: 51 additions & 13 deletions src/components/feed/upload/Category/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<>
<CategorySelector
isOpen={isDropDown === 'openCategory'}
onNext={openTag}
onClose={openUsingRules}
onSave={handleSaveMainCategory}
onSelect={handleSaveMainCategory}
feedData={feedData}
/>
<TagSelector
Expand Down
Loading