-
Notifications
You must be signed in to change notification settings - Fork 0
[refactor] user 정보 관련된 Header에 render 관련 리팩터링 #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bad35fd
#22 refactor: fetcher 함수에 cookie를 받는 경우 추가
altmit 0660ecc
#22 refactor: Dynamic import로 인한 레이아웃 쉬프트 해결
altmit 959fb4e
#22 feat: SSR에서 로그인 여부 판단하여 렌더링하도록 개선
altmit 742e190
#22 refactor: Header에서 App 컴포넌트에서 프리패칭한 로그인 상태여부를 캐싱 데이터로 사용하도록 수정
altmit 2b86997
#22 refactor: staleTime 삭제
altmit 0127df2
#22 refactor: QueryKey를 조금 더 명확한 이름으로 변경
altmit 1919145
#22 refactor: getUser api에서 cookies를 받아 사용하도록 수정
altmit fd89f8c
#22 refactor: getUser 요청을 tanstack query hook 추가
altmit e426f89
#22 refactor: user 사용처 변경
altmit 105368a
#22 refactor: user prefetchQuery 추가 및 prefetchQuery 조건문 수정 캐싱 시간 변경
altmit b8bb1a4
#22 refactor: 불필요한 console.log와 변수 삭제
altmit 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| import { clientFetcher } from "@/api/fetcher"; | ||
| import { Response } from "@/api/types"; | ||
|
|
||
| export const getAuthStatus = async (cookies?: Record<string, string>) => { | ||
| const res = await clientFetcher.get<Response<boolean>>("/authStatus", { | ||
| cookies, | ||
| }); | ||
| return res.data; | ||
| }; |
This file contains hidden or 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,5 @@ | ||
| import { createQueryKeys } from "@lukemorales/query-key-factory"; | ||
|
|
||
| export const authKeys = createQueryKeys("auth", { | ||
| authStatus: null, | ||
| }); |
This file contains hidden or 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 { useSuspenseQuery } from "@tanstack/react-query"; | ||
| import { getAuthStatus } from "../apiRoutes"; | ||
| import { authKeys } from "./queryKeys"; | ||
|
|
||
| export default function useAuthStatusQuery(cookies?: Record<string, string>) { | ||
| return useSuspenseQuery({ | ||
| queryKey: authKeys.authStatus.queryKey, | ||
| queryFn: () => getAuthStatus(cookies), | ||
| select: (res) => res.data, | ||
| retry: 0, | ||
| gcTime: Infinity, | ||
| staleTime: Infinity, | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| import { createQueryKeys } from "@lukemorales/query-key-factory"; | ||
|
|
||
| export const userKeys = createQueryKeys("user", { | ||
| userInfo: null, | ||
| }); |
This file contains hidden or 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 { useQuery } from "@tanstack/react-query"; | ||
| import { getUser } from ".."; | ||
| import { userKeys } from "./queryKeys"; | ||
|
|
||
| export default function useUserQuery(cookies?: Record<string, string>) { | ||
| return useQuery({ | ||
| queryKey: userKeys.userInfo.queryKey, | ||
| queryFn: () => getUser(cookies), | ||
| select: (res) => res.data.user, | ||
| retry: 0, | ||
| gcTime: Infinity, | ||
| staleTime: Infinity, | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,13 +6,13 @@ import designSystem, { parseFontString } from "@/styles/designSystem"; | |
| import { Divider } from "@mui/material"; | ||
| import Image from "next/image"; | ||
| import Link from "next/link"; | ||
| import { MouseEvent, useContext } from "react"; | ||
| import { MouseEvent } from "react"; | ||
| import styled from "styled-components"; | ||
| import { UserContext } from "../../context/UserContext"; | ||
| import useUserQuery from "../../api/queries/useUserQuery"; | ||
| import UserProfileButton from "../UserProfileButton"; | ||
|
|
||
| export default function UserDropdown() { | ||
| const { user } = useContext(UserContext); | ||
| const { data: user } = useUserQuery(); | ||
|
Member
Author
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. 당장에 구현에는 설계한 방향으로 진행되고 있으나, tanstack query 캐싱이 아닌 브라우저의 http 캐싱으로 캐싱되어 이루어지고 있는 것 같음. 이 부분 다음 이슈 또는 추후에 개선이필요함 |
||
|
|
||
| const { mutate: signOutMutate } = useSignOutMutation(); | ||
|
|
||
|
|
||
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.
useSuspensequery를 사용했을 때 문제가 있었는데 정확한 이유를 추후 찾아 수정할 필요있음