File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import { create } from 'zustand'
2+ import type { Room } from '../services/room/room.service'
3+
4+ interface RoomsState {
5+ activeRoom : Room | null
6+ rooms : Room [ ]
7+ setActiveRoom : ( room : Room | null ) => void
8+ addRoom : ( room : Room ) => void
9+ removeRoom : ( roomId : string ) => void
10+ clearActiveRoom : ( ) => void
11+ }
12+
13+ export const useRoomsStore = create < RoomsState > ( ( set ) => ( {
14+ activeRoom : null ,
15+ rooms : [ ] ,
16+
17+ setActiveRoom : ( room ) => set ( { activeRoom : room } ) ,
18+
19+ addRoom : ( room ) =>
20+ set ( ( state ) => ( {
21+ rooms : [ ...state . rooms , room ] ,
22+ activeRoom : room ,
23+ } ) ) ,
24+
25+ removeRoom : ( roomId ) =>
26+ set ( ( state ) => ( {
27+ rooms : state . rooms . filter ( ( r ) => r . id !== roomId ) ,
28+ activeRoom : state . activeRoom ?. id === roomId ? null : state . activeRoom ,
29+ } ) ) ,
30+
31+ clearActiveRoom : ( ) => set ( { activeRoom : null } ) ,
32+ } ) )
You can’t perform that action at this time.
0 commit comments