feat: reimplement punishments

This commit is contained in:
trafficlunar 2026-04-21 13:22:46 +01:00
parent 7bd84ea454
commit 77828653ba
34 changed files with 1229 additions and 1068 deletions

View file

@ -1,9 +1,18 @@
import { useStore } from "@nanostores/react";
import AdminBanner from "./components/admin/banner";
import Footer from "./components/footer";
import Header from "./components/header";
import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router";
import { session } from "./session";
export default function Layout({ children }: { children: React.ReactNode }) {
const $session = useStore(session);
const navigate = useNavigate();
const location = useLocation();
const API_URL = import.meta.env.VITE_API_URL;
// Calculate header height
useEffect(() => {
const header = document.querySelector("header");
@ -25,6 +34,24 @@ export default function Layout({ children }: { children: React.ReactNode }) {
};
}, []);
// Check for punishment on every page navigation
useEffect(() => {
if (!$session) return;
if (["/punished", "/terms-of-service", "/privacy"].includes(location.pathname)) return;
fetch(`${API_URL}/api/is-punished`, { credentials: "include" })
.then((res) => {
if (!res.ok) return null;
return res.json();
})
.then((data) => {
if (data.isPunished) navigate("/punished", { replace: true });
})
.catch((err) => {
console.error("Failed to check punishment status:", err);
});
}, [$session, location.pathname]);
return (
<>
<Header />