This commit is contained in:
Bilal
2024-04-05 21:01:52 +02:00
parent 3cf55ab609
commit 5bd7ac1951
11 changed files with 206 additions and 23 deletions

View File

@@ -2,37 +2,60 @@ import { useAuth } from "../../hooks";
import "./NavBar.scss";
import { logout } from "../../api";
import { Link } from "react-router-dom/";
import { getRoomsLength } from "../../api";
import { useEffect } from "react";
import { useState } from "react";
import refresh from "../../services/pageManagement";
export default function NavBar() {
const { user } = useAuth();
const [roomsLength, setRoomsLength] = useState(null);
const onLogout = () => {
logout().then((res) => {
if (res === "Ok") {
window.location.reload();
refresh();
}
});
};
const refreshAllDatas = async () => {
const roomsLen = await getRoomsLength();
if (!roomsLen) {
return;
}
setRoomsLength(roomsLen);
};
useEffect(() => {
refreshAllDatas();
}, []);
return (
<nav id="nav-container">
<ul id="leafs-container">
{user && (
<li className="leaf">
<Link to="/">Accueil</Link>
<Link onClick={refreshAllDatas} to="/">
Accueil
</Link>
</li>
)}
{user && (
<li className="leaf">
<Link to="rooms">Pieces</Link>
<Link onClick={refreshAllDatas} to="rooms">
Pieces {roomsLength ? `(${roomsLength})` : "(██)"}
</Link>
</li>
)}
{user ? (
<div className="leaf-into">
<li className="leaf">
<Link to="profile">Profil</Link>
<Link onClick={refreshAllDatas} to="profile">
Profil
</Link>
</li>
<button className="leaf-btn" onClick={onLogout}>