-
Notifications
You must be signed in to change notification settings - Fork 1
[Refactor] 전역 상태(isAuthenticated) Context API → Zustand Store 전환 #393
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
6 commits
Select commit
Hold shift + click to select a range
7548ad2
feat: zustand 설치
Chiman2937 885fd63
fix: 전역상태 3종 store로 전환
Chiman2937 fdf1e4a
fix: AuthProvider - context 관리 구문 삭제, zustand store로 상태 관리 전환
Chiman2937 6d34e3c
fix: NotificationStore - 인터페이스 명 수정
Chiman2937 0e4c4f5
fix: useNotificationUnreadCount - useAuthStore 호출로 수정
Chiman2937 e4774f3
fix: AuthProvider - use client 지시어 추가
Chiman2937 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -1,29 +1,19 @@ | ||
| import React, { createContext, SetStateAction, useContext, useState } from 'react'; | ||
| 'use client'; | ||
| import { useEffect } from 'react'; | ||
|
|
||
| interface AuthContextType { | ||
| isAuthenticated: boolean; | ||
| setIsAuthenticated: React.Dispatch<SetStateAction<boolean>>; | ||
| } | ||
|
|
||
| const AuthContext = createContext<AuthContextType | null>(null); | ||
|
|
||
| export const useAuth = () => { | ||
| const context = useContext(AuthContext); | ||
| if (!context) throw new Error('useAuth must be used in AuthProvider'); | ||
| return context; | ||
| }; | ||
| import { useAuthStore } from '@/stores'; | ||
|
|
||
| interface Props { | ||
| children: React.ReactNode; | ||
| hasRefreshToken: boolean; | ||
| } | ||
|
|
||
| export const AuthProvider = ({ children, hasRefreshToken }: Props) => { | ||
| const [isAuthenticated, setIsAuthenticated] = useState(hasRefreshToken); | ||
| const { setIsAuthenticated } = useAuthStore(); | ||
|
|
||
| useEffect(() => { | ||
| setIsAuthenticated(hasRefreshToken); | ||
| }, [hasRefreshToken, setIsAuthenticated]); | ||
|
|
||
| return ( | ||
| <AuthContext.Provider value={{ isAuthenticated, setIsAuthenticated }}> | ||
| {children} | ||
| </AuthContext.Provider> | ||
| ); | ||
| return <>{children}</>; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
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,2 @@ | ||
| export { useAuthStore } from './useAuthStore'; | ||
| export { useNotificationStore } from './useNotificationStore'; |
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,11 @@ | ||
| import { create } from 'zustand'; | ||
|
|
||
| interface AuthState { | ||
| isAuthenticated: boolean; | ||
| setIsAuthenticated: (value: boolean) => void; | ||
| } | ||
|
|
||
| export const useAuthStore = create<AuthState>((set) => ({ | ||
| isAuthenticated: false, | ||
| setIsAuthenticated: (value) => set({ isAuthenticated: value }), | ||
| })); |
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,17 @@ | ||
| import { create } from 'zustand'; | ||
|
|
||
| import { NotificationItem } from '@/types/service/notification'; | ||
|
|
||
| interface NotificationState { | ||
| receivedData: NotificationItem | null; | ||
| setReceivedData: (value: NotificationItem | null) => void; | ||
| hasNewNotification: boolean; | ||
| setHasNewNotification: (value: boolean) => void; | ||
| } | ||
|
|
||
| export const useNotificationStore = create<NotificationState>((set) => ({ | ||
| receivedData: null, | ||
| setReceivedData: (value) => set({ receivedData: value }), | ||
| hasNewNotification: false, | ||
| setHasNewNotification: (value) => set({ hasNewNotification: value }), | ||
| })); |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
rg -n --type=ts --type=tsx "useGetNotificationUnreadCount" -C3Repository: WeGo-Together/WeGo_FrontEnd
Length of output: 98
🏁 Script executed:
rg -n "useGetNotificationUnreadCount" -C3Repository: WeGo-Together/WeGo_FrontEnd
Length of output: 2441
🏁 Script executed:
Repository: WeGo-Together/WeGo_FrontEnd
Length of output: 873
🏁 Script executed:
Repository: WeGo-Together/WeGo_FrontEnd
Length of output: 487
useGetNotificationUnreadCount훅의 반환 필드 정책 통일 필요훅이 이제 명시적인
unReadCount필드를 제공하므로, 기존data필드를 사용하던 소비자는 새로운 필드로 업데이트해야 합니다.src/providers/provider-notification/index.tsx라인 24에서const { data: unReadCount = 0 }를const { unReadCount }로 변경해 주세요.🤖 Prompt for AI Agents
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.
unReadCount는 React Query로만 관리하고, 전역상태에 저장하지 않을 예정입니다.
사용되는 컴포넌트 마다 api를 호출하는 형태이지만, 캐시된 데이터를 호출하기 때문에 문제가 없습니다.
주요 포인트는 "서버상태는 React Query 로만 관리한다" 입니다.
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 772
@Chiman2937, 설명 감사합니다! React Query로 서버 상태를 관리하는 아키텍처 결정에 동의합니다. 이는 서버 상태와 클라이언트 상태를 명확하게 분리하는 좋은 패턴입니다.제 코멘트는
unReadCount를 Zustand로 옮기자는 의도가 아니었고, 단순히 필드명 일관성에 관한 것이었습니다. 현재 훅이 명시적으로unReadCount필드를 반환하는데,provider-notification/index.tsx의 24번째 라인에서 여전히const { data: unReadCount = 0 }로 사용하고 있어서요.const { unReadCount }로 변경하면 훅의 의도가 더 명확해집니다.다만 큰 이슈는 아니므로, 팀의 판단에 맡기겠습니다. 아키텍처 원칙 잘 이해했습니다! 👍
✏️ Learnings added
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.
@Chiman2937, 알겠습니다! 해당 코드가 후속 PR에서 삭제될 예정이라면 지금 수정할 필요가 없네요. 말씀해주셔서 감사합니다. 👍🧠 Learnings used