-
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: 화면 전환 시 선택된 카테고리 유지 및 스크롤 유지 #621
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8249b39
feat: 메뉴 유지되도록 수정
xodms0309 2f9aa30
feat: 화면 전환이 되었을 때 스크롤 위치를 기억하는 기능 추가
xodms0309 6b2f282
refactor: hook 불러오는 위치 변경
xodms0309 3d935a6
feat: 스크롤 이벤트에 디바운스 적용
xodms0309 420c5c4
feat: spacing 크기 변경
xodms0309 91fe906
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-f…
xodms0309 bc8bb76
refactor: default layout의 위아래 padding 제거
xodms0309 40954dc
refactor: ref에 스크롤 이벤트를 거는 방식으로 변경
xodms0309 a80dfed
refactor: CategoryContext를 Action과 Value Context로 분리
xodms0309 fe60442
refactor: 스크롤 로직을 ProductList 컴포넌트로 이동
xodms0309 ad80ff8
style: 중괄호 추가
xodms0309 34cd9fc
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-f…
xodms0309 5b5942a
feat: CategoryProvider로 감싸기
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
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
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,36 @@ | ||
import type { RefObject } from 'react'; | ||
import { useEffect } from 'react'; | ||
|
||
import useTimeout from './useTimeout'; | ||
import { useCategoryActionContext, useCategoryValueContext } from '../context'; | ||
|
||
const useScrollRestoration = (currentCategoryId: number, ref: RefObject<HTMLElement>) => { | ||
const { saveCurrentTabScroll } = useCategoryActionContext(); | ||
const { currentTabScroll } = useCategoryValueContext(); | ||
|
||
const handleScroll = () => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
saveCurrentTabScroll(currentCategoryId, ref.current.scrollTop); | ||
}; | ||
|
||
const [timeoutFn] = useTimeout(handleScroll, 300); | ||
|
||
useEffect(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
ref.current.addEventListener('scroll', timeoutFn); | ||
|
||
const scrollY = currentTabScroll[currentCategoryId]; | ||
ref.current.scrollTo(0, scrollY); | ||
|
||
return () => { | ||
ref.current?.removeEventListener('scroll', timeoutFn); | ||
}; | ||
}, [currentCategoryId]); | ||
}; | ||
|
||
export default useScrollRestoration; |
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,14 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { CategoryActionContext } from '@/contexts/CategoryContext'; | ||
|
||
const useCategoryActionContext = () => { | ||
const categoryAction = useContext(CategoryActionContext); | ||
if (categoryAction === null || categoryAction === undefined) { | ||
throw new Error('useCategoryActionContext는 Category Provider 안에서 사용해야 합니다.'); | ||
} | ||
|
||
return categoryAction; | ||
}; | ||
|
||
export default useCategoryActionContext; |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { CategoryValueContext } from '@/contexts/CategoryContext'; | ||
|
||
const useCategoryValueContext = () => { | ||
const categoryValue = useContext(CategoryValueContext); | ||
if (categoryValue === null || categoryValue === undefined) { | ||
throw new Error('useCategoryValueContext는 Category Provider 안에서 사용해야 합니다.'); | ||
} | ||
|
||
return categoryValue; | ||
}; | ||
|
||
export default useCategoryValueContext; |
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 |
---|---|---|
|
@@ -22,24 +22,20 @@ import SearchPage from '@/pages/SearchPage'; | |
const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: <App />, | ||
element: ( | ||
<CategoryProvider> | ||
<App /> | ||
</CategoryProvider> | ||
Comment on lines
+27
to
+29
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. 상세 페이지에 접속해도 컨텍스트를 유지하기 위해 옮긴건가요? 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. 네 |
||
), | ||
errorElement: <NotFoundPage />, | ||
children: [ | ||
{ | ||
index: true, | ||
element: ( | ||
<CategoryProvider> | ||
<HomePage /> | ||
</CategoryProvider> | ||
), | ||
element: <HomePage />, | ||
}, | ||
{ | ||
path: `${PATH.PRODUCT_LIST}/:category`, | ||
element: ( | ||
<CategoryProvider> | ||
<ProductListPage /> | ||
</CategoryProvider> | ||
), | ||
element: <ProductListPage />, | ||
}, | ||
{ | ||
path: PATH.RECIPE, | ||
|
@@ -108,7 +104,11 @@ const router = createBrowserRouter([ | |
}, | ||
{ | ||
path: '/', | ||
element: <App layout="headerOnly" />, | ||
element: ( | ||
<CategoryProvider> | ||
<App layout="headerOnly" /> | ||
</CategoryProvider> | ||
), | ||
errorElement: <NotFoundPage />, | ||
children: [ | ||
{ | ||
|
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.
네!