-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor(toks-main): 카테고리 기능 리팩토링 및 Bug Fixed #402
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
671c0b0
refactor: 카테고리 기능 리팩토링 및 Bug Fixed
minsgy 718dad3
fix: order lint fix
minsgy 1c5aee3
fix: template.tsx에서 RecoilRoot 리렌더링되어 상태 초기화되는 이슈 fixed
minsgy dee97c3
fix: category 가나다라 순으로 프론트에서 처리
minsgy c769985
fix: image url public 안들어가는 이슈 fix
minsgy 18411a2
fix: category flow 주석 추가
minsgy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
const Provider = ({ children }: StrictPropsWithChildren) => { | ||
return <RecoilRoot>{children}</RecoilRoot>; | ||
}; | ||
|
||
export default Provider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import React, { useState } from 'react'; | ||
import { useRecoilState, useSetRecoilState } from 'recoil'; | ||
import React, { useEffect, useLayoutEffect, useState } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { BottomSheet, Button, ICON_URL, Tab, Text } from '@/common'; | ||
import { useAuth, usePreventScroll } from '@/common/hooks'; | ||
|
@@ -16,27 +16,55 @@ import { CategoryButtonGroups } from './CategoryButtonGroups'; | |
import { useCategoryUpdateMutation } from '../hooks/useCategoryUpdateMutation'; | ||
|
||
export const CategoryBottomSheet = () => { | ||
const { isLogin } = useAuth(); | ||
const [isShow, setIsShow] = useRecoilState(isVisibleCategoryBottomSheetAtom); | ||
const { mutate: updateCategories } = useCategoryUpdateMutation(); | ||
const { data: selectedCategory = [] } = useSelectedCategoriesQuery(); | ||
const { isLogin } = useAuth(); | ||
|
||
const { data: selectedLoginCategory = [] } = useSelectedCategoriesQuery(); | ||
const [selectedLocalCategory, setSelectedLocalCategories] = useState< | ||
string[] | ||
>(selectedCategory ?? []); | ||
>([]); | ||
|
||
const [selectedTemporaryCategory, setSelectedTemporaryCategory] = | ||
useRecoilState(selectedTemporaryCategoryAtom); | ||
|
||
const setSelectedTemporaryCategory = useSetRecoilState( | ||
selectedTemporaryCategoryAtom | ||
); | ||
const { data: categoryQuery } = useCategoriesQuery(); | ||
const [isShow, setIsShow] = useRecoilState(isVisibleCategoryBottomSheetAtom); | ||
const [selectedTab, setSelectedTab] = useState(0); | ||
usePreventScroll(isShow); | ||
|
||
const panel = categoryQuery?.panels[selectedTab]; | ||
const buttons = panel?.map(({ id, name }) => ({ | ||
const [selectedTab, setSelectedTab] = useState(0); | ||
const { data: categoryQuery } = useCategoriesQuery(); | ||
const selectedPanel = categoryQuery?.panels[selectedTab]; | ||
const buttons = selectedPanel?.map(({ id, name }) => ({ | ||
label: name, | ||
value: id, | ||
})); | ||
|
||
const tabs = categoryQuery?.tabs.map(({ name }) => name) ?? []; | ||
|
||
/** | ||
* useLayoutEffect(동기) -> useEffect(비동기) 순으로 렌더링된다. | ||
* STEP1. BottomSheet가 열릴 때마다 selectedTab, selectedLocalCategories를 초기화한다. | ||
* STEP2. 로그인 상태일 때, 로그인한 사용자의 관심 카테고리를 selectedLocalCategories에 저장한다. | ||
* STEP3. 로그인 상태가 아니고, selectedTemporaryCategory가 존재할 때, selectedLocalCategories에 저장한다. | ||
* | ||
* 이를 통해 BottomSheet가 열릴 때마다 초기화되고, 저장한 카테고리/로그인 정보 카테고리를 불러온다. | ||
*/ | ||
useLayoutEffect(() => { | ||
setSelectedTab(0); | ||
setSelectedLocalCategories([]); | ||
}, [isShow]); | ||
|
||
useEffect(() => { | ||
if (isLogin && isShow && selectedLoginCategory.length > 0) { | ||
setSelectedLocalCategories(selectedLoginCategory); | ||
} | ||
}, [isLogin, isShow, selectedLoginCategory]); | ||
|
||
useEffect(() => { | ||
if (selectedTemporaryCategory.length > 0 && isShow) { | ||
setSelectedLocalCategories(selectedTemporaryCategory); | ||
} | ||
}, [isShow, selectedTemporaryCategory]); | ||
Comment on lines
+51
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 민석님 혹시 여기 각 useEffect가 어떤 목적으로 작성되었는지 간단한 주석 추가되면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 18411a2 반영했습니다! |
||
|
||
return ( | ||
<BottomSheet | ||
className="flex h-categoryBottomSheet flex-col " | ||
|
@@ -55,7 +83,7 @@ export const CategoryBottomSheet = () => { | |
</div> | ||
<Tab | ||
activeIndex={selectedTab} | ||
tabs={categoryQuery?.tabs ?? []} | ||
tabs={tabs} | ||
onTabChange={(index) => { | ||
setSelectedTab(index); | ||
}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client'; | ||
|
||
import { getCookie } from 'cookies-next'; | ||
import React, { memo } from 'react'; | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
|
||
import { Categories } from '@/common/components/Categories'; | ||
import { useSelectedCategoriesQuery } from '@/queries'; | ||
import { useCategoriesQuery } from '@/queries/useCategoriesQuery'; | ||
import { | ||
isVisibleCategoryBottomSheetAtom, | ||
selectedTemporaryCategoryAtom, | ||
} from '@/store'; | ||
|
||
import { isSameCategory } from '../utils'; | ||
|
||
const QuizCategory = () => { | ||
const accessToken = getCookie('accessToken'); | ||
const { data: categoryQuery } = useCategoriesQuery(); | ||
const { data: selectedLoginCategory } = useSelectedCategoriesQuery(); | ||
const selectedTemporaryCategory = useRecoilValue( | ||
selectedTemporaryCategoryAtom | ||
); | ||
|
||
const setIsOpenCategoryBottomSheet = useSetRecoilState( | ||
isVisibleCategoryBottomSheetAtom | ||
); | ||
|
||
const selectedCategory = Boolean(accessToken) | ||
? selectedLoginCategory | ||
: selectedTemporaryCategory; | ||
|
||
const categories = categoryQuery?.tabs.map(({ name, id }) => { | ||
const isSelected = | ||
selectedCategory?.filter((categoryId) => | ||
isSameCategory(categoryId, id) | ||
) ?? []; | ||
|
||
return { | ||
categoryName: `${name} ${isSelected.length}`, | ||
isSelected: isSelected.length > 0, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Categories | ||
categories={categories ?? []} | ||
onClick={() => { | ||
setIsOpenCategoryBottomSheet(true); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default memo(QuizCategory); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isSameCategory = (a: string, b: string) => { | ||
return a.slice(0, 2) === b.slice(0, 2); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리코일 루트 위치가 에러와 연관이 있었군요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 몰랐네요 ㄷㄷ templates 시급하게 때야할듯요