.
This commit is contained in:
25
app/stores/private-channels-store.ts
Normal file
25
app/stores/private-channels-store.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { create } from 'zustand'
|
||||
import { immer } from 'zustand/middleware/immer'
|
||||
import type { ChannelId, RecipientChannel } from '~/lib/api/types'
|
||||
|
||||
type PrivateChannelsStore = {
|
||||
channels: Record<ChannelId, RecipientChannel>
|
||||
addChannels: (channels: RecipientChannel[]) => void
|
||||
addChannel: (channel: RecipientChannel) => void
|
||||
removeChannel: (channelId: ChannelId) => void
|
||||
}
|
||||
|
||||
export const usePrivateChannelsStore = create<PrivateChannelsStore>()(
|
||||
immer(
|
||||
(set) => ({
|
||||
channels: {},
|
||||
addChannels: (channels: RecipientChannel[]) => set((state) => {
|
||||
for (const channel of channels) {
|
||||
state.channels[channel.id] = channel
|
||||
}
|
||||
}),
|
||||
addChannel: (channel: RecipientChannel) => set((state) => { state.channels[channel.id] = channel }),
|
||||
removeChannel: (channelId: ChannelId) => set((state) => { delete state.channels[channelId] }),
|
||||
})
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user