Merge branch 'main' into 3-fix-aircraftmarkers-missionmarkers
This commit is contained in:
@@ -21,7 +21,7 @@ interface ChatStore {
|
||||
addMessage: (userId: string, message: ChatMessage) => void;
|
||||
}
|
||||
|
||||
export const useChatStore = create<ChatStore>((set, get) => ({
|
||||
export const useLeftMenuStore = create<ChatStore>((set, get) => ({
|
||||
reportTabOpen: false,
|
||||
setReportTabOpen: (open: boolean) => set({ reportTabOpen: open }),
|
||||
ownId: null,
|
||||
@@ -99,7 +99,7 @@ export const useChatStore = create<ChatStore>((set, get) => ({
|
||||
socket.on(
|
||||
"chat-message",
|
||||
({ userId, message }: { userId: string; message: ChatMessage }) => {
|
||||
const store = useChatStore.getState();
|
||||
const store = useLeftMenuStore.getState();
|
||||
console.log("chat-message", userId, message);
|
||||
// Update the chat store with the new message
|
||||
store.addMessage(userId, message);
|
||||
@@ -1,24 +0,0 @@
|
||||
import { Prisma, prisma } from "@repo/db";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
console.log(req.body);
|
||||
const body = await req.json();
|
||||
console.log(body);
|
||||
|
||||
const missions = await prisma.mission.findMany({
|
||||
where: (body.filter as Prisma.MissionWhereInput) || {},
|
||||
});
|
||||
|
||||
return NextResponse.json(missions);
|
||||
};
|
||||
|
||||
export const PUT = async (req: NextRequest) => {
|
||||
const body = await req.json();
|
||||
|
||||
const newMission = await prisma.mission.create({
|
||||
data: body,
|
||||
});
|
||||
|
||||
return NextResponse.json(newMission);
|
||||
};
|
||||
@@ -1,22 +1,15 @@
|
||||
"use client";
|
||||
import { ChatBubbleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
||||
import { useChatStore } from "_store/chatStore";
|
||||
import { useLeftMenuStore } from "_store/leftMenuStore";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { Fragment, useEffect, useRef, useState } from "react";
|
||||
import { Dispatcher } from "dispatch/_components/navbar/_components/action";
|
||||
import { cn } from "helpers/cn";
|
||||
|
||||
export const getDispatcher = async () => {
|
||||
const res = await fetch(`
|
||||
${process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL}/dispatcher`);
|
||||
const data = await res.json();
|
||||
return data as Dispatcher[];
|
||||
};
|
||||
import { getDispatcher } from "pilot/_components/navbar/action";
|
||||
|
||||
export const Chat = () => {
|
||||
const {
|
||||
setReportTabOpen,
|
||||
reportTabOpen,
|
||||
chatOpen,
|
||||
setChatOpen,
|
||||
sendMessage,
|
||||
@@ -26,7 +19,7 @@ export const Chat = () => {
|
||||
selectedChat,
|
||||
setSelectedChat,
|
||||
setChatNotification,
|
||||
} = useChatStore();
|
||||
} = useLeftMenuStore();
|
||||
const [sending, setSending] = useState(false);
|
||||
const session = useSession();
|
||||
const [addTabValue, setAddTabValue] = useState<string>("");
|
||||
@@ -37,7 +30,7 @@ export const Chat = () => {
|
||||
useEffect(() => {
|
||||
if (!session.data?.user.id) return;
|
||||
setOwnId(session.data.user.id);
|
||||
}, [session]);
|
||||
}, [session, setOwnId]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDispatcher = async () => {
|
||||
@@ -56,7 +49,7 @@ export const Chat = () => {
|
||||
|
||||
timeout.current = setInterval(() => {
|
||||
fetchDispatcher();
|
||||
}, 1000000);
|
||||
}, 1000);
|
||||
fetchDispatcher();
|
||||
|
||||
return () => {
|
||||
@@ -93,6 +86,9 @@ export const Chat = () => {
|
||||
className="dropdown-content card bg-base-200 w-150 shadow-md z-[1100] ml-2 border-1 border-primary"
|
||||
>
|
||||
<div className="card-body">
|
||||
<h2 className="inline-flex items-center gap-2 text-lg font-bold mb-2">
|
||||
<ChatBubbleIcon /> Chat
|
||||
</h2>
|
||||
<div className="join">
|
||||
<select
|
||||
className="select select-sm w-full"
|
||||
@@ -207,7 +203,7 @@ export const Chat = () => {
|
||||
}}
|
||||
disabled={sending}
|
||||
role="button"
|
||||
onSubmit={(e) => false}
|
||||
onSubmit={() => false} // prevent submit event for react hook form
|
||||
>
|
||||
{sending ? (
|
||||
<span className="loading loading-spinner loading-sm"></span>
|
||||
|
||||
@@ -5,7 +5,9 @@ import { useEffect, useRef, useState } from "react";
|
||||
import { Dispatcher } from "dispatch/_components/navbar/_components/action";
|
||||
import { cn } from "helpers/cn";
|
||||
import { useChatStore } from "_store/chatStore";
|
||||
import { getDispatcher } from "dispatch/_components/left/Chat";
|
||||
import {} from "dispatch/_components/left/Chat";
|
||||
import { serverApi } from "helpers/axios";
|
||||
import { getDispatcher } from "pilot/_components/navbar/action";
|
||||
|
||||
export const Report = () => {
|
||||
const { setChatOpen, setReportTabOpen, reportTabOpen, setOwnId } =
|
||||
@@ -43,10 +45,9 @@ export const Report = () => {
|
||||
if (timeout.current) {
|
||||
clearInterval(timeout.current);
|
||||
timeout.current = null;
|
||||
console.log("cleared");
|
||||
}
|
||||
};
|
||||
}, [selectedPlayer]);
|
||||
}, [selectedPlayer, session.data?.user.id]);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -72,6 +73,9 @@ export const Report = () => {
|
||||
className="dropdown-content card bg-base-200 w-150 shadow-md z-[1100] ml-2 border-1 border-error"
|
||||
>
|
||||
<div className="card-body">
|
||||
<h2 className="inline-flex items-center gap-2 text-lg font-bold mb-2">
|
||||
<ExclamationTriangleIcon /> Report senden
|
||||
</h2>
|
||||
<div className="join">
|
||||
<select
|
||||
className="select select-sm w-full"
|
||||
@@ -107,15 +111,12 @@ export const Report = () => {
|
||||
e.preventDefault();
|
||||
if (message.length < 1 || !selectedPlayer) return;
|
||||
setSending(true);
|
||||
fetch("/api/dispatch/report", {
|
||||
serverApi("/report", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
data: {
|
||||
message,
|
||||
to: selectedPlayer,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userId: selectedPlayer,
|
||||
message: message,
|
||||
}),
|
||||
})
|
||||
.then(() => {
|
||||
setMessage("");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import { ChatBubbleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
||||
import { useChatStore } from "_store/chatStore";
|
||||
import { leftMenuStore } from "_store/leftMenuStore";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { Fragment, useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
@@ -20,7 +20,7 @@ export const Chat = () => {
|
||||
selectedChat,
|
||||
setSelectedChat,
|
||||
setChatNotification,
|
||||
} = useChatStore();
|
||||
} = leftMenuStore();
|
||||
const [sending, setSending] = useState(false);
|
||||
const session = useSession();
|
||||
const [addTabValue, setAddTabValue] = useState<string>("");
|
||||
|
||||
Reference in New Issue
Block a user