diff --git a/traque-front/app/team/components/loginForm.jsx b/traque-front/app/team/components/loginForm.jsx
deleted file mode 100644
index 6688c8a..0000000
--- a/traque-front/app/team/components/loginForm.jsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { useState } from "react";
-import { BlueButton } from "@/components/button";
-import { TextInput } from "@/components/input";
-
-export default function LoginForm({ onSubmit, title, placeholder, buttonText}) {
- const [value, setValue] = useState("");
- function handleSubmit(e) {
- e.preventDefault();
- setValue("");
- onSubmit(value);
- }
- return (
-
- )
-}
diff --git a/traque-front/app/team/layout.js b/traque-front/app/team/layout.js
deleted file mode 100644
index 0d97272..0000000
--- a/traque-front/app/team/layout.js
+++ /dev/null
@@ -1,13 +0,0 @@
-"use client";
-import { TeamConnexionProvider } from "@/context/teamConnexionContext";
-import { TeamProvider } from "@/context/teamContext";
-
-export default function AdminLayout({ children }) {
- return (
-
-
- {children}
-
-
- )
-}
\ No newline at end of file
diff --git a/traque-front/app/team/page.js b/traque-front/app/team/page.js
deleted file mode 100644
index 27200d7..0000000
--- a/traque-front/app/team/page.js
+++ /dev/null
@@ -1,13 +0,0 @@
-"use client"
-import { useTeamConnexion } from "@/context/teamConnexionContext";
-import LoginForm from "./components/loginForm";
-
-export default function Home() {
- const { login,useProtect } = useTeamConnexion();
- useProtect();
- return (
-
- login(parseInt(value))}/>
-
- );
-}
diff --git a/traque-front/app/team/track/components/actionDrawer.jsx b/traque-front/app/team/track/components/actionDrawer.jsx
deleted file mode 100644
index 04491fb..0000000
--- a/traque-front/app/team/track/components/actionDrawer.jsx
+++ /dev/null
@@ -1,75 +0,0 @@
-import { useEffect, useState } from "react"
-import { BlueButton, GreenButton } from "@/components/button";
-import { TextInput } from "@/components/input";
-import useTeamConnexion from "@/context/teamConnexionContext";
-import useGame from "@/hook/useGame";
-import EnemyTeamModal from "./enemyTeamModal";
-
-export default function ActionDrawer() {
- const [visible, setVisible] = useState(false);
- const [enemyCaptureCode, setEnemyCaptureCode] = useState("");
- const { sendCurrentPosition, name, captureCode, capture, locationSendDeadline, penalties } = useGame();
- const {logout} = useTeamConnexion();
- const [timeLeftBeforePenalty, setTimeLeftBeforePenalty] = useState(0);
- const [enemyModalVisible, setEnemyModalVisible] = useState(false);
-
- useEffect(() => {
- const interval = setInterval(() => {
- console.log(locationSendDeadline)
- const timeLeft = locationSendDeadline - Date.now();
- setTimeLeftBeforePenalty(Math.floor(timeLeft / 1000 / 60));
- }, 1000);
- return () => clearInterval(interval);
- }, [locationSendDeadline]);
-
- function handleCapture() {
- capture(enemyCaptureCode);
- setEnemyCaptureCode("");
- }
-
- return (
-
-

setVisible(!visible)} />
- {visible &&
-
-

-
-
-
- {name}
-
-
- Capture code
- {String(captureCode).padStart(4,"0")}
-
-
- {timeLeftBeforePenalty}min
- before penalty
-
-
- {Array.from({ length: penalties }).map((_, i) =>
)}
- {Array.from({ length: 3-penalties }).map((_, i) =>
)}
-
-
-
- Update position
-
-
-
Target
-
- setEnemyModalVisible(true)}>See target info
-
-
- setEnemyCaptureCode(e.target.value)} />
- Capture target
-
-
- {/*
- Signal emergency
-
*/}
-
- }
-
setEnemyModalVisible(false)} />
-
- )
-}
diff --git a/traque-front/app/team/track/components/enemyTeamModal.jsx b/traque-front/app/team/track/components/enemyTeamModal.jsx
deleted file mode 100644
index b65dd5b..0000000
--- a/traque-front/app/team/track/components/enemyTeamModal.jsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import { useEffect, useRef } from "react";
-import { env } from 'next-runtime-env';
-import { RedButton } from "@/components/button";
-import useGame from "@/hook/useGame";
-
-
-export default function EnemyTeamModal({ visible, onClose }) {
- const { teamId, enemyName } = useGame();
- const imageRef = useRef(null);
-
- useEffect(() => {
- if (visible) {
- refreshImage();
- }
- }, [visible]);
-
- function refreshImage() {
- imageRef.current.src = SERVER_URL + "/photo/enemy?team=" + teamId.toString() + "&t=" + new Date().getTime();
- }
-
- var protocol = "https://";
- const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST");
- if (NEXT_PUBLIC_SOCKET_HOST == "localhost") {
- protocol = "http://";
- }
- const SERVER_URL = protocol + NEXT_PUBLIC_SOCKET_HOST + "/back";
- console.log(SERVER_URL);
- return (visible &&
- <>
-
-
-
{enemyName}
-

-
- Close
-
-
- >
- )
-}
diff --git a/traque-front/app/team/track/components/map.jsx b/traque-front/app/team/track/components/map.jsx
deleted file mode 100644
index 6172cfc..0000000
--- a/traque-front/app/team/track/components/map.jsx
+++ /dev/null
@@ -1,105 +0,0 @@
-import React, { useEffect, useState } from 'react'
-import { Circle, MapContainer, Marker, Popup, TileLayer, useMap } from 'react-leaflet'
-import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css'
-import "leaflet-defaulticon-compatibility";
-import "leaflet/dist/leaflet.css";
-import useTeamContext from '@/context/teamContext';
-import useGame from '@/hook/useGame';
-
-const DEFAULT_ZOOM = 14;
-
-// Pan to the center of the map when the position of the user is updated for the first time
-function MapPan(props) {
- const map = useMap();
- const [initialized, setInitialized] = useState(false);
-
- useEffect(() => {
- if (!initialized && props.center) {
- map.flyTo(props.center, DEFAULT_ZOOM, { animate: false });
- setInitialized(true)
- }
- }, [props.center]);
-
- return null;
-}
-
-function LiveZone() {
- const { zone } = useTeamContext();
- console.log('Zone', zone);
- return zone &&
-}
-
-function ZoneExtremities() {
- const { zoneExtremities } = useTeamContext();
- console.log('Zone extremities', zoneExtremities);
- return zoneExtremities?.begin && zoneExtremities?.end && <>
- {/* */}
-
- >
-
-}
-
-export function LiveMap({ ...props }) {
- const { currentPosition, enemyPosition } = useGame();
- useEffect(() => {
- console.log('Current position', currentPosition);
- }, [currentPosition]);
- return (
-
-
- {currentPosition &&
-
- Votre position
-
- }
- {enemyPosition &&
-
- Position de l'ennemi
-
- }
-
-
-
-
- )
-}
-
-export function PlacementMap({ ...props }) {
- const { currentPosition, startingArea } = useGame();
- return (
-
-
- {currentPosition &&
-
- Votre position
-
- }
-
- {startingArea && }
-
- )
-}
diff --git a/traque-front/app/team/track/components/notification.jsx b/traque-front/app/team/track/components/notification.jsx
deleted file mode 100644
index 50e0a26..0000000
--- a/traque-front/app/team/track/components/notification.jsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { useEffect, useState } from "react";
-import { useSocketListener } from "@/hook/useSocketListener";
-
-export default function Notification({ socket }) {
- const [visible, setVisible] = useState(false);
- const [timeoutId, setTimeoutId] = useState(null);
- const [notification, setNotification] = useState(null);
-
- useSocketListener(socket, "error", (notification) => {
- console.log("error", notification);
- setNotification({ type: "error", text: notification });
- setVisible(true);
- });
-
- useSocketListener(socket, "success", (notification) => {
- console.log("success", notification);
- setNotification({ type: "success", text: notification });
- setVisible(true);
- });
-
- useSocketListener(socket, "warning", (notification) => {
- console.log("warning", notification);
- setNotification({ type: "warning", text: notification });
- setVisible(true);
- });
-
- // Hide the notification after 5 seconds
- useEffect(() => {
- console.log({ visible });
- if (visible && notification?.text != undefined) {
- clearTimeout(timeoutId);
- if (notification?.type == "success") {
- setTimeoutId(setTimeout(() => {
- setVisible(false);
- }, 3000));
- }
- }
- }, [visible]);
-
- const bgColorMap = {
- error: "bg-red-500 text-white",
- success: "bg-green-500",
- warning: "bg-yellow-500"
- }
-
- const classNames = 'fixed relative w-11/12 p-5 z-30 mx-auto inset-x-0 flex justify-center rounded-xl transition-all shadow-xl ' + (visible ? "top-5 " : "-translate-y-full ");
-
- return (
- Object.keys(bgColorMap).map((key) =>
- notification?.type == key &&
- setVisible(false)}>
-
x
-
{notification?.text}
-
- ));
-}
diff --git a/traque-front/app/team/track/components/placementOverlay.jsx b/traque-front/app/team/track/components/placementOverlay.jsx
deleted file mode 100644
index 07684f4..0000000
--- a/traque-front/app/team/track/components/placementOverlay.jsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import useTeamConnexion from "@/context/teamConnexionContext";
-import useGame from "@/hook/useGame";
-
-export default function PlacementOverlay() {
- const { name, ready } = useGame();
- const {logout} = useTeamConnexion();
- return (
- <>
-
-
-
Placement
-
{name}
- {!ready &&
Positionez vous dans le cercle
}
- {ready &&
Restez dans le cercle en attendant que la partie commence
}
-
-
- >
- )
-}
\ No newline at end of file
diff --git a/traque-front/app/team/track/components/waitingScreen.jsx b/traque-front/app/team/track/components/waitingScreen.jsx
deleted file mode 100644
index 36615bf..0000000
--- a/traque-front/app/team/track/components/waitingScreen.jsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { useRef } from "react";
-import { env } from 'next-runtime-env';
-import { GreenButton, LogoutButton } from "@/components/button";
-import useTeamContext from "@/context/teamContext";
-import useGame from "@/hook/useGame"
-
-export default function WaitingScreen() {
- const { name, teamId } = useGame();
- const { gameSettings } = useTeamContext();
- const imageRef = useRef(null);
- const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST");
- var protocol = "https://";
- if (NEXT_PUBLIC_SOCKET_HOST == "localhost") {
- protocol = "http://";
- }
- const SERVER_URL = protocol + NEXT_PUBLIC_SOCKET_HOST + "/back";
- console.log(SERVER_URL);
-
- function sendImage() {
- let data = new FormData();
- data.append('file', document.querySelector('input[type="file"]').files[0]);
-
- fetch(SERVER_URL + "/upload?team=" + teamId.toString() , {
- method: 'POST',
- body: data
- }).then((response) => {
- console.log(response);
- refreshImage();
- });
- }
-
- function refreshImage() {
- imageRef.current.src = SERVER_URL + "/photo/my?team=" + teamId.toString() + "&t=" + new Date().getTime();
- }
-
-
- return (
-
-
-
- Equipe : {name}
-
-
- {gameSettings?.waitingMessage}
-
-
-
Uploadez une photo où tous les membres de l'équipe sont visibles
-
-
- Envoyer
-
-
- {teamId &&

}
-
- )
-}
\ No newline at end of file
diff --git a/traque-front/app/team/track/page.js b/traque-front/app/team/track/page.js
deleted file mode 100644
index 774f1b5..0000000
--- a/traque-front/app/team/track/page.js
+++ /dev/null
@@ -1,55 +0,0 @@
-"use client";
-import React from 'react';
-import dynamic from 'next/dynamic';
-import { LogoutButton } from '@/components/button';
-import { useSocket } from '@/context/socketContext';
-import { useTeamConnexion } from '@/context/teamConnexionContext';
-import { useTeamContext } from '@/context/teamContext';
-import useGame from '@/hook/useGame';
-import { GameState } from '@/util/gameState';
-import ActionDrawer from './components/actionDrawer';
-import Notification from './components/notification';
-import PlacementOverlay from './components/placementOverlay';
-import WaitingScreen from './components/waitingScreen';
-
-//Load the map without SSR
-const LiveMap = dynamic(() => import('./components/map').then((mod) => mod.LiveMap), {
- ssr: false
-});
-const PlacementMap = dynamic(() => import('./components/map').then((mod) => mod.PlacementMap), {
- ssr: false
-});
-
-export default function Track() {
- const { gameState, captured } = useGame();
- const { gameSettings} = useTeamContext()
- const { useProtect } = useTeamConnexion();
- const { teamSocket: socket } = useSocket();
- useProtect();
- return <>
-
- {gameState == GameState.SETUP && }
- {gameState == GameState.PLAYING && !captured &&
- }
- {gameState == GameState.PLAYING && captured &&
-
Vous avez été capturé
-
{gameSettings?.capturedMessage}
-
}
- {gameState == GameState.PLACEMENT &&
-
- }
- {gameState == GameState.FINISHED &&
-
-
Partie terminée
- {captured &&
{gameSettings?.loserEndGameMessage}
}
- {!captured &&
{gameSettings?.winnerEndGameMessage}
}
-
- }
- >
-}
diff --git a/traque-front/components/button.jsx b/traque-front/components/button.jsx
index c4b8307..2d4f279 100644
--- a/traque-front/components/button.jsx
+++ b/traque-front/components/button.jsx
@@ -1,5 +1,3 @@
-import { useTeamConnexion } from "@/context/teamConnexionContext";
-
export function BlueButton({ children, ...props }) {
return ()
}
-
-export function LogoutButton() {
- const { logout } = useTeamConnexion();
- return
-}
diff --git a/traque-front/context/socketContext.jsx b/traque-front/context/socketContext.jsx
index 7413ed5..4b55452 100644
--- a/traque-front/context/socketContext.jsx
+++ b/traque-front/context/socketContext.jsx
@@ -5,13 +5,8 @@ import { io } from 'socket.io-client';
const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST");
const SOCKET_URL = (NEXT_PUBLIC_SOCKET_HOST == "localhost" ? "ws://" : "wss://") + NEXT_PUBLIC_SOCKET_HOST;
-const USER_SOCKET_URL = SOCKET_URL + "/player";
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
-export const teamSocket = io(USER_SOCKET_URL, {
- path: "/back/socket.io",
-});
-
export const adminSocket = io(ADMIN_SOCKET_URL, {
path: "/back/socket.io",
});
@@ -19,7 +14,8 @@ export const adminSocket = io(ADMIN_SOCKET_URL, {
export const SocketContext = createContext();
export default function SocketProvider({ children }) {
- const value = useMemo(() => ({ teamSocket, adminSocket }), [teamSocket, adminSocket]);
+ const value = useMemo(() => ({ adminSocket }), [adminSocket]);
+
return (
{children}
);
diff --git a/traque-front/context/teamConnexionContext.jsx b/traque-front/context/teamConnexionContext.jsx
deleted file mode 100644
index 09be1c6..0000000
--- a/traque-front/context/teamConnexionContext.jsx
+++ /dev/null
@@ -1,25 +0,0 @@
-"use client";
-import { createContext, useContext, useMemo } from "react";
-import { useSocket } from "./socketContext";
-import useSocketAuth from "@/hook/useSocketAuth";
-import usePasswordProtect from "@/hook/usePasswordProtect";
-
-const teamConnexionContext = createContext();
-
-export function TeamConnexionProvider({ children }) {
- const { teamSocket } = useSocket();
- const { login, password: teamId, loggedIn, loading, logout } = useSocketAuth(teamSocket, "team_password");
- const useProtect = () => usePasswordProtect("/team", "/team/track", loading, loggedIn);
-
- const value = useMemo(() => ({ teamId, login, logout, loggedIn, loading, useProtect}), [teamId, login, loggedIn, loading]);
-
- return (
-
- {children}
-
- );
-}
-
-export function useTeamConnexion() {
- return useContext(teamConnexionContext);
-}
diff --git a/traque-front/context/teamContext.jsx b/traque-front/context/teamContext.jsx
deleted file mode 100644
index 30af732..0000000
--- a/traque-front/context/teamContext.jsx
+++ /dev/null
@@ -1,48 +0,0 @@
-"use client";
-import useLocation from "@/hook/useLocation";
-import useSocketListener from "@/hook/useSocketListener";
-import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
-import { useSocket } from "./socketContext";
-import { useTeamConnexion } from "./teamConnexionContext";
-import { GameState } from "@/util/gameState";
-
-const teamContext = createContext();
-
-export function TeamProvider({children}) {
- const [teamInfos, setTeamInfos] = useState({});
- const [gameState, setGameState] = useState(GameState.SETUP);
- const [gameSettings, setGameSettings] = useState(null);
- const [zone, setZone] = useState(null);
- const [zoneExtremities, setZoneExtremities] = useState(null);
- const measuredLocation = useLocation(5000);
- const {teamSocket} = useSocket();
- const {loggedIn} = useTeamConnexion();
- const teamInfosRef = useRef();
-
- teamInfosRef.current = teamInfos;
-
- useSocketListener(teamSocket, "update_team", (newTeamInfos) => setTeamInfos({...teamInfosRef.current, ...newTeamInfos}) );
- useSocketListener(teamSocket, "game_state", setGameState);
- useSocketListener(teamSocket, "zone", setZone);
- useSocketListener(teamSocket, "new_zone", setZoneExtremities);
- useSocketListener(teamSocket, "game_settings", setGameSettings);
-
- //Send the current position to the server when the user is logged in
- useEffect(() => {
- console.log("sending position", measuredLocation);
- if(loggedIn) {
- teamSocket.emit("update_position", measuredLocation);
- }
- }, [loggedIn, measuredLocation]);
-
- const value = useMemo(() => ({teamInfos, gameState, zone, zoneExtremities, gameSettings}), [gameSettings, teamInfos, gameState, zone, zoneExtremities]);
- return (
-
- {children}
-
- );
-}
-
-export function useTeamContext() {
- return useContext(teamContext);
-}
diff --git a/traque-front/hook/useGame.jsx b/traque-front/hook/useGame.jsx
deleted file mode 100644
index a6b3831..0000000
--- a/traque-front/hook/useGame.jsx
+++ /dev/null
@@ -1,20 +0,0 @@
-"use client";
-import { useSocket } from "@/context/socketContext";
-import { useTeamConnexion } from "@/context/teamConnexionContext";
-import { useTeamContext } from "@/context/teamContext";
-
-export default function useGame() {
- const { teamSocket } = useSocket();
- const { teamId } = useTeamConnexion();
- const { teamInfos, gameState } = useTeamContext();
-
- function sendCurrentPosition() {
- teamSocket.emit("send_position");
- }
-
- function capture(captureCode) {
- teamSocket.emit("capture", captureCode);
- }
-
- return {...teamInfos, sendCurrentPosition, capture, teamId, gameState};
-}
diff --git a/traque-front/next.config.mjs b/traque-front/next.config.mjs
index f75af37..1068432 100644
--- a/traque-front/next.config.mjs
+++ b/traque-front/next.config.mjs
@@ -1,4 +1,5 @@
/** @type {import('next').NextConfig} */
+
const nextConfig = {
output: 'standalone',
@@ -7,14 +8,12 @@ const nextConfig = {
return [
{
source: '/',
- destination: '/team',
- permanent: true,
+ destination: '/admin',
+ permanent: true, // The browser will save the redirect in its cache, empty the cache to change the redirect
},
]
},
};
-
-
export default nextConfig;