Typed enriched users
This commit is contained in:
parent
16fac7022d
commit
430431203b
|
@ -1,7 +1,7 @@
|
|||
import { writable, get, derived, Writable, Readable } from "svelte/store"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
import { Store as StoreContext } from "."
|
||||
import { UIUser } from "@budibase/types"
|
||||
import { UIEnrichedUser, UIUser } from "@budibase/types"
|
||||
|
||||
interface UsersStore {
|
||||
users: Writable<UIUser[]>
|
||||
|
@ -12,21 +12,22 @@ interface DerivedUsersStore {
|
|||
}
|
||||
|
||||
interface ActionUserStore {
|
||||
users: UsersStore["users"] & {
|
||||
actions: {
|
||||
updateUser: (user: UIUser) => void
|
||||
removeUser: (sessionId: string) => void
|
||||
users: UsersStore["users"] &
|
||||
Readable<UIEnrichedUser[]> & {
|
||||
actions: {
|
||||
updateUser: (user: UIUser) => void
|
||||
removeUser: (sessionId: string) => void
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Store = UsersStore & DerivedUsersStore
|
||||
export type Store = DerivedUsersStore & ActionUserStore
|
||||
|
||||
export const createStores = (): UsersStore => {
|
||||
const users = writable<UIUser[]>([])
|
||||
|
||||
const enrichedUsers = derived(users, $users => {
|
||||
return $users.map(user => ({
|
||||
return $users.map<UIEnrichedUser>(user => ({
|
||||
...user,
|
||||
color: helpers.getUserColor(user),
|
||||
label: helpers.getUserLabel(user),
|
||||
|
|
|
@ -4,3 +4,8 @@ export interface UIUser extends User {
|
|||
sessionId: string
|
||||
gridMetadata?: { focusedCellId?: string }
|
||||
}
|
||||
|
||||
export interface UIEnrichedUser extends UIUser {
|
||||
color: string
|
||||
label: string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue