continue dispatch-server

This commit is contained in:
PxlLoewe
2025-03-14 00:18:06 -07:00
parent ec335ce489
commit 05b7d0fd39
14 changed files with 179 additions and 22 deletions

View File

@@ -3,8 +3,13 @@ import { ToggleTalkButton } from "../_components/ToggleTalkButton";
import { ChangeRufgruppe } from "../_components/ChangeRufgruppe";
import { Notifications } from "../_components/Notifications";
import Link from "next/link";
import { connectionStore } from "../../_store/connectionStore";
import { useEffect } from "react";
import { socket } from "../socket";
export default function Navbar() {
const connected = connectionStore((state) => state);
return (
<div className="navbar bg-base-100 shadow-sm">
<div className="flex-1">

View File

@@ -1,6 +1,5 @@
import type { Metadata } from "next";
import Navbar from "./_components/Navbar";
import { useSession } from "next-auth/react";
import { redirect } from "next/navigation";
import { getServerSession } from "../api/auth/[...nextauth]/auth";

View File

@@ -0,0 +1,7 @@
import { io } from "socket.io-client";
export const socket = io(process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL, {
auth: (cb) => {
cb({ token: "jwt" });
},
});

View File

@@ -0,0 +1,16 @@
import { create } from "zustand";
import { socket } from "../(dispatch)/socket";
console.log("connectionStore");
export const connectionStore = create((set) => ({
isConnected: false,
connect: async (jwt: string) => {
socket.auth = { token: "jwt" };
socket.connect();
},
}));
socket.on("connect", () => {
connectionStore.setState({ isConnected: true });
});

View File

@@ -0,0 +1,9 @@
import { create } from "zustand";
import { socket } from "../(dispatch)/socket";
export const stationStore = create((set) => {
return {
stations: [],
setStations: (stations: any) => set({ stations }),
};
});