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

refactor: mypage 리팩토링 #178

Merged
merged 11 commits into from
Oct 14, 2024
Merged

Conversation

hakyoung12
Copy link
Contributor

@hakyoung12 hakyoung12 commented Oct 11, 2024

✏️ 작업 내용

  • 초기데이터 SSR로 받아오기
  • 나의 모임 참여취소 기능 구현 및 데이터 바로 반영

📷 스크린샷

모임취소시 즉시 반영

Oct-11-2024.16-44-34.mov

close #179

@hakyoung12 hakyoung12 added the 🧩 Refactor 리팩토링 label Oct 11, 2024
@hakyoung12 hakyoung12 self-assigned this Oct 11, 2024
Comment on lines +29 to +38
// QueryClient 인스턴스 생성
const queryClient = new QueryClient();

// QueryClientProvider로 감싸주는 헬퍼 함수 정의
const renderWithQueryClient = (ui: ReactNode, options?: RenderOptions) =>
render(
<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>,
options,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

myGatherings의 쿼리키관리를 위해 useParticipation함수에 queryClient를 추가했더니 테스트 오류가 났습니다.
useQueryClient를 사용하려면 QueryClientProvider로 감싸줘야 하는데, 현재 테스트에서 이를 설정하지 않아서 발생한 문제였습니다.
그래서 테스트코드에 QueryClientProvider를 추가하였습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

호민님께서 만든 그라데이션을 적용했습니다.

Comment on lines +53 to +66
const handleWithdrawClickWithId = async (id: number, queryKey: string[]) => {
const { success, message } = await deleteGatheringToWithdraw(id);

if (!success) {
toast.error(message);
return;
}
// 쿼리 무효화 함수
await queryClient.invalidateQueries({ queryKey }); // querykey 무효화시켜서 취소한 모임 반영하여 최신화

toast.success(message);
setHasParticipated(false);
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

모임의 id값을 받아와서 모임취소 요청을 하는 함수입니다.
모임을 취소하면 목록에서 바로 반영이 되는 것이 사용자경험에서 좋을 것 같아서
요청이 성공했을 때 캐싱된 데이터를 무효화시켜 최신 데이터를 받아오게 만들었습니다.

Comment on lines 54 to 61
initialData: {
pages: [
{
hasNextPage: initData.length === DEFAULT_LIMIT,
offset: DEFAULT_OFFSET,
data: initData,
},
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

useInfiniteQuery 훅에서 서버사이드로 받아온 초기데이터를 initialData로 적용했습니다.
처음 받아온 데이터의 길이가 DEFAULT_LIMIT과 같다면 다음 데이터를 받아올 수 있게 됩니다.

@hakyoung12 hakyoung12 added the ✨ Feat 기능 추가 label Oct 11, 2024
Copy link
Contributor

@HMRyu HMRyu 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 +11 to +14
const Mygatherings = async () => {
const myGatherings = await getMyGatherings();
const user = await getUserData();
return <MyGatheringList initData={myGatherings} user={user} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 7 to 8
offset = DEFAULT_OFFSET,
limit = DEFAULT_LIMIT,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

P4) 개인적인 의견인데, 조금 더 구체적으로 네이밍을 하면 더 직관적인 것 같긴 합니다..!

ex)

  • DEFAULT_GATHERINGS_OFFSET
  • DEFAULT_GATHERINGS_LIMIT
  • ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

저도 더 구체적으로 짜는게 직관적일 것 같아 반영했습니다 감사합니다!

Comment on lines +33 to +38
const renderWithQueryClient = (ui: ReactNode, options?: RenderOptions) =>
render(
<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>,
options,
);

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// QueryClientProvider로 감싸주는 헬퍼 함수 정의
const renderWithQueryClient = (ui: ReactNode, options?: RenderOptions) =>
render(
<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>,
Copy link
Contributor

Choose a reason for hiding this comment

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

P4) 궁금해서 여쭤봅니다..!

혹시 {ui} 라고 이름 지으신 이유가 있으실까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

큰 의미는 없습니다 사용하려는 테스트 컴포넌트에 기능 없이 ui만 구현해놔서 직관적으로 ui라고 지었습니다!

Copy link
Contributor

@yunchaeney yunchaeney left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 👍
invalidateQueries 저도 써먹어야겠어요...!

Comment on lines +60 to +61
// 쿼리 무효화 함수
await queryClient.invalidateQueries({ queryKey }); // querykey 무효화시켜서 취소한 모임 반영하여 최신화
Copy link
Contributor

@BeMatthewsong BeMatthewsong Oct 14, 2024

Choose a reason for hiding this comment

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

👏

Copy link
Contributor

@BeMatthewsong BeMatthewsong left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! LGTM 👍

@hakyoung12 hakyoung12 merged commit 5649456 into develop Oct 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feat 기능 추가 🧩 Refactor 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: mypage 리팩토링
4 participants