-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FE] feat: 홈에서 카테고리 눌렀을 때 context에 저장하는 방식으로 변경 #732
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d063d7e
refactor: 불필요한 코드 제거
xodms0309 95e2924
refactor: 카테고리 이동 방식을 context에 저장하는 방식으로 변경
xodms0309 e37098c
feat: 스토리북에 CategoryProvider 추가
xodms0309 e19943c
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-f…
xodms0309 66c4391
feat: categoryItem에 GA 이벤트 추가
xodms0309 7b251d5
style: 사용하지 않는 코드 제거
xodms0309 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
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
35 changes: 7 additions & 28 deletions
35
frontend/src/components/Common/CategoryFoodList/CategoryFoodList.tsx
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,6 +1,4 @@ | ||
import { Button, theme } from '@fun-eat/design-system'; | ||
import { useEffect } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
|
||
import { CATEGORY_TYPE } from '@/constants'; | ||
|
@@ -9,29 +7,20 @@ import { useCategoryActionContext, useCategoryValueContext } from '@/hooks/conte | |
import { useCategoryFoodQuery } from '@/hooks/queries/product/useCategoryQuery'; | ||
import { getTargetCategoryName } from '@/utils/category'; | ||
|
||
const category = CATEGORY_TYPE.FOOD; | ||
const categoryType = CATEGORY_TYPE.FOOD; | ||
|
||
const CategoryFoodTab = () => { | ||
const { data: categories } = useCategoryFoodQuery(category); | ||
const { data: categories } = useCategoryFoodQuery(categoryType); | ||
|
||
const { categoryIds } = useCategoryValueContext(); | ||
const { selectCategory } = useCategoryActionContext(); | ||
const currentCategoryId = categoryIds[category]; | ||
|
||
const location = useLocation(); | ||
const queryParams = new URLSearchParams(location.search); | ||
const categoryIdFromURL = queryParams.get('category'); | ||
const currentCategoryId = categoryIds[categoryType]; | ||
|
||
const { gaEvent } = useGA(); | ||
|
||
useEffect(() => { | ||
if (categoryIdFromURL) { | ||
selectCategory(category, parseInt(categoryIdFromURL)); | ||
} | ||
}, [category]); | ||
|
||
const handleCategoryButtonClick = (menuId: number) => { | ||
selectCategory(category, menuId); | ||
selectCategory(categoryType, menuId); | ||
gaEvent({ | ||
category: 'button', | ||
action: `${getTargetCategoryName(categories, menuId)} 카테고리 버튼 클릭`, | ||
|
@@ -41,10 +30,10 @@ const CategoryFoodTab = () => { | |
|
||
return ( | ||
<CategoryMenuContainer> | ||
{categories.map((menu) => { | ||
const isSelected = menu.id === currentCategoryId; | ||
{categories.map(({ id, name }) => { | ||
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. 👍 |
||
const isSelected = id === currentCategoryId; | ||
return ( | ||
<li key={menu.id}> | ||
<li key={id}> | ||
<CategoryButton | ||
type="button" | ||
customHeight="30px" | ||
|
@@ -53,10 +42,10 @@ const CategoryFoodTab = () => { | |
weight="bold" | ||
variant={isSelected ? 'filled' : 'outlined'} | ||
isSelected={isSelected} | ||
onClick={() => handleCategoryButtonClick(menu.id)} | ||
onClick={() => handleCategoryButtonClick(id)} | ||
aria-pressed={isSelected} | ||
> | ||
{menu.name} | ||
{name} | ||
</CategoryButton> | ||
</li> | ||
); | ||
|
@@ -81,10 +70,9 @@ const CategoryMenuContainer = styled.ul` | |
const CategoryButton = styled(Button)<{ isSelected: boolean }>` | ||
padding: 6px 12px; | ||
${({ isSelected }) => | ||
isSelected | ||
? ` | ||
isSelected && | ||
` | ||
background: ${theme.colors.gray5}; | ||
color: ${theme.textColors.white}; | ||
` | ||
: ''} | ||
`} | ||
`; |
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
35 changes: 26 additions & 9 deletions
35
frontend/src/components/Common/CategoryItem/CategoryItem.tsx
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,30 +1,47 @@ | ||
import { Button } from '@fun-eat/design-system'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
|
||
import { PATH } from '@/constants/path'; | ||
import { useGA } from '@/hooks/common'; | ||
import { useCategoryActionContext } from '@/hooks/context'; | ||
|
||
interface CategoryItemProps { | ||
categoryId: number; | ||
name: string; | ||
image: string; | ||
categoryType: 'food' | 'store'; | ||
} | ||
|
||
const CategoryItem = ({ name, image }: CategoryItemProps) => { | ||
const CategoryItem = ({ categoryId, name, image, categoryType }: CategoryItemProps) => { | ||
const navigate = useNavigate(); | ||
const { selectCategory } = useCategoryActionContext(); | ||
|
||
const { gaEvent } = useGA(); | ||
|
||
const handleCategoryItemClick = (categoryId: number) => { | ||
selectCategory(categoryType, categoryId); | ||
navigate(PATH.PRODUCT_LIST + '/' + categoryType); | ||
|
||
gaEvent({ | ||
category: 'button', | ||
action: `${name} 카테고리 링크 클릭`, | ||
label: '카테고리', | ||
}); | ||
}; | ||
|
||
return ( | ||
<CategoryItemContainer variant="transparent"> | ||
<Button type="button" variant="transparent" customHeight="auto" onClick={() => handleCategoryItemClick(categoryId)}> | ||
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. 👍 |
||
<ImageWrapper> | ||
<img src={image} width={60} height={60} alt={name} /> | ||
</ImageWrapper> | ||
<CategoryName>{name}</CategoryName> | ||
</CategoryItemContainer> | ||
</Button> | ||
); | ||
}; | ||
|
||
export default CategoryItem; | ||
|
||
const CategoryItemContainer = styled(Button)` | ||
width: 60px; | ||
height: 100px; | ||
text-align: center; | ||
`; | ||
|
||
const ImageWrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
|
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
35 changes: 7 additions & 28 deletions
35
frontend/src/components/Common/CategoryStoreList/CategoryStoreList.tsx
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.
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.
👍