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

[FE] feat: 화면 전환 시 선택된 카테고리 유지 및 스크롤 유지 #621

Merged
merged 13 commits into from
Sep 14, 2023

Conversation

xodms0309
Copy link
Collaborator

@xodms0309 xodms0309 commented Sep 13, 2023

Issue

✨ 구현한 기능

  • 선택된 카테고리 유지
  • 스크롤 위치 유지

📢 논의하고 싶은 내용

  • 실제 개발서버에 올라가서 무한스크롤이랑 합쳐졌을 때 잘 작동할지는 아직... 모르겠읍니다 ^_^ 안되면 롤백해야지 뭐~~~~ 스크롤 이벤트 안주고 intersection observer을 활용해보고 싶었는데 안되네요..

🎸 기타

x

⏰ 일정

  • 추정 시간 :
  • 걸린 시간 : 3일

@github-actions
Copy link

github-actions bot commented Sep 13, 2023

Unit Test Results

5 tests   5 ✔️  5s ⏱️
2 suites  0 💤
1 files    0

Results for commit 5b5942a.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@Leejin-Yang Leejin-Yang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

숙원 사업 카테고리 유지... 타미 고생했습니다!
몇 개 수정해 볼 만한 부분 코멘트로 남겼는데 확인해주세요
저는 그 때 잘 동작한거 봤으니.. 배포해도 잘 동작 무조건입니다 👍

Comment on lines +37 to +39
const saveCurrentTabScroll = (categoryId: number, scrollY: number) => {
setCurrentTabScroll((prevState) => ({ ...prevState, [categoryId]: scrollY }));
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈 객체로 두고 카테고리마다 하나씩 저장해두는거군요 👍

Copy link
Collaborator Author

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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 훅은 main 엘리먼트를 찾는 대신 리스트 컨테이너에 ref를 걸어서 넘겨주어도 되지 않을까요..?
상태를 저장할 때 dom api로 직접 요소를 가져오는게 좋아보이진 않네요 🥲
같이 한 번 시도해봅시다.!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정했읍니다. 짱짱

Comment on lines 40 to 46
useEffect(() => {
const mainElement = document.getElementById('main');
if (!mainElement) return;

if (!isCategoryVariant(category)) {
return null;
}
const scrollY = currentTabScroll[currentCategoryId];
mainElement.scrollTo(0, scrollY);
}, [currentCategoryId]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼 이 친구도 약간의 수정이 필요해보여요

Comment on lines 29 to 31
if (!category || !isCategoryVariant(category)) {
return null;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 훅들이 있어서 이 친구는 모든 훅 아래로 내려가야겠어요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 이렇게 되면 밑의 hook에서 저 category 값을 참조를 못하게 되는데 어떻게 할까요?

Copy link
Collaborator Author

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)' }}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 타이틀과 정렬 버튼을 고정하는 친구인가요??
특별히 인라인으로 작성한 이유가 없다면 스타일드로 작성갑시다!

아 그리고 정렬버튼과 리스트 묶어준 이유가 에러나 로딩인 경우 정렬 버튼을 안 보이게 해서 정렬 상태 변경을 방지하기 위함인데 타미는 어떻게 생각하나요??

Comment on lines +26 to +28
<CategoryProvider>
<App />
</CategoryProvider>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상세 페이지에 접속해도 컨텍스트를 유지하기 위해 옮긴건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 6 to 8
const { categoryIds, selectCategory, currentTabScroll, saveCurrentTabScroll } = useContext(CategoryContext);

return { categoryIds, selectCategory };
return { categoryIds, selectCategory, currentTabScroll, saveCurrentTabScroll };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그대로 반환하니 구조 분해 하지 않아도 되겠네요!
그리고 다른 컨텍스트 훅처럼 예외처리도 있으면 더 좋아보여요.!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정했습니다! 다른 context와 동일하게 Value와 Action에 대해 나눴습니다

Copy link
Collaborator

@hae-on hae-on left a 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;
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 중괄호!

Copy link
Collaborator

@Leejin-Yang Leejin-Yang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고했어요 타미킴 👍

@xodms0309 xodms0309 merged commit 8b7aa91 into develop Sep 14, 2023
3 checks passed
@xodms0309 xodms0309 deleted the feat/issue-575 branch September 14, 2023 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FE] 메뉴 선택 유지 기능 추가
3 participants