-
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
Conversation
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.
숙원 사업 카테고리 유지... 타미 고생했습니다!
몇 개 수정해 볼 만한 부분 코멘트로 남겼는데 확인해주세요
저는 그 때 잘 동작한거 봤으니.. 배포해도 잘 동작 무조건입니다 👍
const saveCurrentTabScroll = (categoryId: number, scrollY: number) => { | ||
setCurrentTabScroll((prevState) => ({ ...prevState, [categoryId]: scrollY })); | ||
}; |
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.
네!
import useTimeout from './useTimeout'; | ||
import { useCategoryContext } from '../context'; | ||
|
||
const useScrollRestoration = (currentCategoryId: number) => { |
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.
이 훅은 main 엘리먼트를 찾는 대신 리스트 컨테이너에 ref를 걸어서 넘겨주어도 되지 않을까요..?
상태를 저장할 때 dom api로 직접 요소를 가져오는게 좋아보이진 않네요 🥲
같이 한 번 시도해봅시다.!
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.
수정했읍니다. 짱짱
useEffect(() => { | ||
const mainElement = document.getElementById('main'); | ||
if (!mainElement) return; | ||
|
||
if (!isCategoryVariant(category)) { | ||
return null; | ||
} | ||
const scrollY = currentTabScroll[currentCategoryId]; | ||
mainElement.scrollTo(0, scrollY); | ||
}, [currentCategoryId]); |
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.
그럼 이 친구도 약간의 수정이 필요해보여요
if (!category || !isCategoryVariant(category)) { | ||
return null; | ||
} |
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.
근데 이렇게 되면 밑의 hook에서 저 category
값을 참조를 못하게 되는데 어떻게 할까요?
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.
fe60442
아예 로직을 컴포넌트안으로 이동하는 것으로 바꿨습니다
</Suspense> | ||
<ErrorBoundary fallback={ErrorComponent} handleReset={reset}> | ||
<Suspense fallback={<Loading />}> | ||
<div style={{ position: 'fixed', background: 'white', top: '60px', width: 'calc(100% - 40px)' }}> |
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.
오 타이틀과 정렬 버튼을 고정하는 친구인가요??
특별히 인라인으로 작성한 이유가 없다면 스타일드로 작성갑시다!
아 그리고 정렬버튼과 리스트 묶어준 이유가 에러나 로딩인 경우 정렬 버튼을 안 보이게 해서 정렬 상태 변경을 방지하기 위함인데 타미는 어떻게 생각하나요??
<CategoryProvider> | ||
<App /> | ||
</CategoryProvider> |
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.
네
const { categoryIds, selectCategory, currentTabScroll, saveCurrentTabScroll } = useContext(CategoryContext); | ||
|
||
return { categoryIds, selectCategory }; | ||
return { categoryIds, selectCategory, currentTabScroll, saveCurrentTabScroll }; |
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.
수정했습니다! 다른 context와 동일하게 Value와 Action에 대해 나눴습니다
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.
타미 수고했읍니다
중간에 중괄호 빠진것만 넣어주세욤
롤백은 안돼~~
const { saveCurrentTabScroll } = useCategoryActionContext(); | ||
|
||
const handleScroll = () => { | ||
if (!ref.current) return; |
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.
중괄호!
const [timeoutFn] = useTimeout(handleScroll, 300); | ||
|
||
useEffect(() => { | ||
if (!ref.current) return; |
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.
수고했어요 타미킴 👍
Issue
✨ 구현한 기능
📢 논의하고 싶은 내용
🎸 기타
x
⏰ 일정