Skip to content

Commit 51b70e8

Browse files
chore: add missing room store
1 parent c4a9be6 commit 51b70e8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

apps/client/src/store/rooms.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}))

0 commit comments

Comments
 (0)