-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-client): migrate from recoil to zustand
- Migrate from recoil to zustand - Bump react to v19
- Loading branch information
Showing
21 changed files
with
563 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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,52 @@ | ||
import { isEqual } from 'lodash'; | ||
import { groupByDate } from 'src/utils/group'; | ||
import { create } from 'zustand'; | ||
|
||
import { IAuthConfig, IUser, ThreadHistory } from '..'; | ||
|
||
interface AuthState { | ||
authConfig?: IAuthConfig; | ||
user?: IUser | null; | ||
|
||
threadHistory?: ThreadHistory; | ||
|
||
setAuthConfig: (authConfig?: IAuthConfig) => void; | ||
setUser: (user?: IUser | null) => void; | ||
setThreadHistory: (threadHistory?: ThreadHistory) => void; | ||
} | ||
|
||
export const useAuthStore = create<AuthState>((set, get) => ({ | ||
threadHistory: { | ||
threads: undefined, | ||
currentThreadId: undefined, | ||
timeGroupedThreads: undefined, | ||
pageInfo: undefined | ||
}, | ||
|
||
setAuthConfig: (authConfig?: IAuthConfig) => { | ||
set({ authConfig }); | ||
}, | ||
|
||
setUser: (user?: IUser | null) => { | ||
set({ user }); | ||
}, | ||
|
||
setThreadHistory: (threadHistory?: ThreadHistory) => { | ||
const oldValue = get().threadHistory; | ||
|
||
let timeGroupedThreads = threadHistory?.timeGroupedThreads; | ||
if ( | ||
threadHistory?.threads && | ||
!isEqual(threadHistory.threads, oldValue?.timeGroupedThreads) | ||
) { | ||
timeGroupedThreads = groupByDate(threadHistory.threads); | ||
} | ||
|
||
set({ | ||
threadHistory: { | ||
...threadHistory, | ||
timeGroupedThreads | ||
} | ||
}); | ||
} | ||
})); |
Oops, something went wrong.