mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-11-12 07:59:17 +00:00
feat: reimplement punishments
This commit is contained in:
parent
7bd84ea454
commit
77828653ba
34 changed files with 1229 additions and 1068 deletions
|
|
@ -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 />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue