Skip to content

Commit

Permalink
fix(error): filter user is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Sep 24, 2024
1 parent 447cbb2 commit 83b4031
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions apps/renderer/src/store/user/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useUserStore = createZustandStore<UserStoreState>("user")(() => ({
const { getState: _get, setState: set } = useUserStore
class UserActions {
upsert(user: UserModel | UserModel[] | Record<string, UserModel>) {
if (!user) return
if (Array.isArray(user)) {
set((state) =>
produce(state, (state) => {
Expand All @@ -24,24 +25,24 @@ class UserActions {
}
}),
)
return
}
const idKeyValue = user.id
if (typeof idKeyValue === "string") {
set((state) => ({
users: {
...state.users,
[idKeyValue]: user as UserModel,
},
}))
} else {
const idKeyValue = user.id
if (typeof idKeyValue === "string") {
for (const id in user) {
set((state) => ({
users: {
...state.users,
[idKeyValue]: user as UserModel,
[id]: user[id],
},
}))
} else {
for (const id in user) {
set((state) => ({
users: {
...state.users,
[id]: user[id],
},
}))
}
}
}
}
Expand Down

0 comments on commit 83b4031

Please sign in to comment.