continue dispatch-server
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
7
apps/dispatch/app/(dispatch)/socket.ts
Normal file
7
apps/dispatch/app/(dispatch)/socket.ts
Normal 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" });
|
||||
},
|
||||
});
|
||||
16
apps/dispatch/app/_store/connectionStore.ts
Normal file
16
apps/dispatch/app/_store/connectionStore.ts
Normal 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 });
|
||||
});
|
||||
9
apps/dispatch/app/_store/stationsStore.ts
Normal file
9
apps/dispatch/app/_store/stationsStore.ts
Normal 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 }),
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user