finished conenct modal
This commit is contained in:
@@ -3,17 +3,39 @@ import { socket } from "../(dispatch)/socket";
|
||||
|
||||
interface ConnectionStore {
|
||||
isConnected: boolean;
|
||||
connect: (uid: string) => Promise<void>;
|
||||
selectedZone: string;
|
||||
connect: (
|
||||
uid: string,
|
||||
selectedZone: string,
|
||||
logoffTime: string,
|
||||
) => Promise<void>;
|
||||
disconnect: () => void;
|
||||
}
|
||||
|
||||
export const connectionStore = create<ConnectionStore>((set) => ({
|
||||
isConnected: false,
|
||||
connect: async (uid: string) => {
|
||||
socket.auth = { uid };
|
||||
socket.connect();
|
||||
selectedZone: "LST_01",
|
||||
connect: async (uid, selectedZone, logoffTime) =>
|
||||
new Promise((resolve) => {
|
||||
socket.auth = { uid };
|
||||
set({ selectedZone });
|
||||
socket.connect();
|
||||
socket.once("connect", () => {
|
||||
socket.emit("connect-dispatch", {
|
||||
logoffTime,
|
||||
selectedZone,
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
disconnect: () => {
|
||||
socket.disconnect();
|
||||
},
|
||||
}));
|
||||
|
||||
socket.on("connect", () => {
|
||||
connectionStore.setState({ isConnected: true });
|
||||
});
|
||||
socket.on("disconnect", () => {
|
||||
connectionStore.setState({ isConnected: false });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user