-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathuseSocket.tsx
More file actions
41 lines (34 loc) · 1014 Bytes
/
useSocket.tsx
File metadata and controls
41 lines (34 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useSocketContext } from '@/context/SocketContext';
import { useEffect } from 'react';
import { GroupInfo, GroupPanelType } from 'tailchat-shared';
import { resetGroupPreviewState, useGroupPreviewStore } from './store';
export function useSocket(groupId: string) {
const socket = useSocketContext();
useEffect(() => {
socket.request('group.preview.joinGroupRooms', {
groupId,
});
socket
.request<GroupInfo>('group.preview.getGroupInfo', {
groupId,
})
.then((groupInfo) => {
console.log('groupInfo', groupInfo);
useGroupPreviewStore.setState({
groupInfo,
});
if (Array.isArray(groupInfo.panels)) {
const textPanels = groupInfo.panels.map(
(p) => p.type === GroupPanelType.TEXT
);
// TODO
}
});
return () => {
socket.request('group.preview.leaveGroupRooms', {
groupId,
});
resetGroupPreviewState();
};
}, [groupId]);
}