finished conenct modal

This commit is contained in:
PxlLoewe
2025-03-15 20:40:40 -07:00
parent 2ecc91adb9
commit cf61740698
8 changed files with 147 additions and 95 deletions

View File

@@ -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 });
});