20 lines
439 B
TypeScript
20 lines
439 B
TypeScript
import { create } from "zustand";
|
|
import { socket } from "../(dispatch)/socket";
|
|
|
|
interface ConnectionStore {
|
|
isConnected: boolean;
|
|
connect: (uid: string) => Promise<void>;
|
|
}
|
|
|
|
export const connectionStore = create<ConnectionStore>((set) => ({
|
|
isConnected: false,
|
|
connect: async (uid: string) => {
|
|
socket.auth = { uid };
|
|
socket.connect();
|
|
},
|
|
}));
|
|
|
|
socket.on("connect", () => {
|
|
connectionStore.setState({ isConnected: true });
|
|
});
|