Navigation: Seitenleiste auf dem Desktop, Kopf- und TabBar mobil

Desktop: feste Seitenleiste mit allen Zielen (Icon + Titel). Mobil: Kopfleiste
mit Menü, Titel und Einstellungen, unten die TabBar mit Feed, Suche,
Benachrichtigungen, Chats und Profil; das Menü blendet die Seitenleiste als
Schublade ein. Suche, Benachrichtigungen, Chats und Einstellungen sind
Platzhalter, /me leitet aufs eigene Profil bzw. zum Login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
irrlicht
2026-10-09 21:48:30 +02:00
co-authored by Claude Opus 5.5
parent f84ba061a8
commit 15b0bfc69c
8 changed files with 451 additions and 53 deletions
+46 -44
View File
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { Link, Outlet, useLocation } from "react-router";
import { api } from "./api";
import { useAuthChanged, useMe } from "./auth";
import { MenuIcon, SettingsIcon } from "./icons";
import { Sidebar, TabBar } from "./Nav";
// Tage ohne Datenverlust (fester Startpunkt, Kontinuität seit der alten
// Version).
@@ -10,58 +11,59 @@ function plural(n: number, one: string, many: string) {
return `${n} ${n === 1 ? one : many}`;
}
// Layout ist der gemeinsame Seitenrahmen: die Startseite hat Tagline und
// Headerbar, alle anderen Seiten den "zurück zum Feed"-Knopf.
// Layout ist der gemeinsame Seitenrahmen. Desktop: Seitenleiste links mit
// allen Zielen. Mobil: Kopfleiste (Menü, Titel, Einstellungen), unten die
// TabBar mit den fünf wichtigsten Zielen; das Menü blendet dieselbe
// Seitenleiste als Schublade ein. Umgeschaltet wird nur per CSS (app.css).
export function Layout() {
const path = useLocation().pathname;
const isHome = path === "/";
const [menuOpen, setMenuOpen] = useState(false);
const days = Math.floor((Date.now() - dataLossStart) / 86400000);
const close = () => setMenuOpen(false);
useEffect(() => {
if (!menuOpen) return;
const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMenuOpen(false);
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [menuOpen]);
return (
<>
<header>
<nav id="legal">
<a href="/static/docs/impressum.html">Impressum</a> -{" "}
<a href="/static/docs/datenschutz.html">Datenschutz</a> -{" "}
<a href="/static/docs/beitragsordnung.html">Beitragsordnung</a> -{" "}
<Link to="/stats">Statistik</Link>
</nav>
<Link to="/"><h1>Kontrollverlust</h1></Link>
{isHome ? (
<>
<div className="shell">
<Sidebar open={menuOpen} onNavigate={close} />
{menuOpen && <div className="backdrop" onClick={close} />}
<div className="page">
<header>
<div id="topbar">
<button
className="icon-btn mobile-only"
aria-label="Menü"
aria-expanded={menuOpen}
aria-controls="sidebar"
onClick={() => setMenuOpen(!menuOpen)}
>
<MenuIcon />
</button>
<Link to="/"><h1>Kontrollverlust</h1></Link>
<Link className="icon-btn mobile-only" to="/settings" aria-label="Einstellungen">
<SettingsIcon />
</Link>
</div>
{path === "/" && (
<p id="stats" className="tagline">
Ohne Datenverlust seit {plural(days, "Tag", "Tagen")}
</p>
<Headerbar />
</>
) : (
<div id="headerbar"><Link className="button" to="/">zurück zum Feed</Link></div>
)}
</header>
)}
</header>
{/* Die Statistik-Seite darf auf breiten Bildschirmen breiter werden. */}
<main className={path === "/stats" ? "wide" : undefined}>
<Outlet />
</main>
</>
);
}
{/* Die Statistik-Seite darf auf breiten Bildschirmen breiter werden. */}
<main className={path === "/stats" ? "wide" : undefined}>
<Outlet />
</main>
</div>
// Headerbar der Startseite: angemeldet Profil-Link und Logout, sonst leer.
function Headerbar() {
const me = useMe().data;
const authChanged = useAuthChanged();
if (!me) return <div id="headerbar"></div>;
// POST statt GET: als GET wäre Logout per fremdem Link auslösbar (CSRF).
const logout = async () => {
await api.post("/auth/logout").catch(() => undefined);
await authChanged();
};
return (
<div id="headerbar">
<Link className="button" to={`/u/${encodeURIComponent(me.username)}`}>mein Profil</Link>{" "}
<button id="logout-btn" onClick={logout}>Logout</button>
<TabBar />
</div>
);
}
+97
View File
@@ -0,0 +1,97 @@
import type { ReactNode } from "react";
import { NavLink } from "react-router";
import { api } from "./api";
import { useAuthChanged, useMe } from "./auth";
import {
BellIcon, ChatIcon, FeedIcon, ImprintIcon, LogoutIcon, PrivacyIcon,
ProfileIcon, RulesIcon, SearchIcon, SettingsIcon, StatsIcon,
} from "./icons";
type Target = { title: string; icon: ReactNode; to: string; end?: boolean };
// useMainTargets liefert die fünf wichtigsten Ziele (TabBar, Kopf der
// Seitenleiste). Das Profil zeigt angemeldet aufs eigene Profil, sonst auf
// /me mit dem Login.
function useMainTargets(): Target[] {
const me = useMe().data;
const profile = me ? `/u/${encodeURIComponent(me.username)}` : "/me";
return [
{ title: "Feed", icon: <FeedIcon />, to: "/", end: true },
{ title: "Suche", icon: <SearchIcon />, to: "/search" },
{ title: "Benachrichtigungen", icon: <BellIcon />, to: "/notifications" },
{ title: "Chats", icon: <ChatIcon />, to: "/chats" },
{ title: "Profil", icon: <ProfileIcon />, to: profile },
];
}
const moreTargets: Target[] = [
{ title: "Einstellungen", icon: <SettingsIcon />, to: "/settings" },
{ title: "Statistik", icon: <StatsIcon />, to: "/stats" },
];
// Die Rechtstexte sind statische Seiten außerhalb der App (kein Client-Routing).
const docs: Target[] = [
{ title: "Datenschutz", icon: <PrivacyIcon />, to: "/static/docs/datenschutz.html" },
{ title: "Beitragsordnung", icon: <RulesIcon />, to: "/static/docs/beitragsordnung.html" },
{ title: "Impressum", icon: <ImprintIcon />, to: "/static/docs/impressum.html" },
];
// Sidebar: alle Ziele mit Icon und Titel. Auf dem Desktop immer sichtbar,
// mobil die Schublade hinter dem Menü (open).
export function Sidebar({ open, onNavigate }: { open: boolean; onNavigate: () => void }) {
const main = useMainTargets();
return (
<nav id="sidebar" className={open ? "open" : undefined} aria-label="Navigation">
<ul>
{[...main, ...moreTargets].map((t) => (
<li key={t.title}>
<NavLink to={t.to} end={t.end} onClick={onNavigate}>
{t.icon}<span>{t.title}</span>
</NavLink>
</li>
))}
</ul>
<ul>
{docs.map((t) => (
<li key={t.title}>
<a href={t.to}>{t.icon}<span>{t.title}</span></a>
</li>
))}
</ul>
<Logout onDone={onNavigate} />
</nav>
);
}
// Logout steht nur angemeldet unten in der Seitenleiste. POST statt GET: als
// GET wäre Logout per fremdem Link auslösbar (CSRF).
function Logout({ onDone }: { onDone: () => void }) {
const me = useMe().data;
const authChanged = useAuthChanged();
if (!me) return null;
const logout = async () => {
await api.post("/auth/logout").catch(() => undefined);
await authChanged();
onDone();
};
return (
<ul>
<li>
<button id="logout-btn" onClick={logout}><LogoutIcon /><span>Logout</span></button>
</li>
</ul>
);
}
// TabBar: mobil unten die fünf wichtigsten Ziele, nur Icons.
export function TabBar() {
return (
<nav id="tabbar" aria-label="Hauptnavigation">
{useMainTargets().map((t) => (
<NavLink key={t.title} to={t.to} end={t.end} aria-label={t.title} title={t.title}>
{t.icon}
</NavLink>
))}
</nav>
);
}
+148 -6
View File
@@ -52,7 +52,8 @@ header {
padding: 0.5rem 0;
}
/* Rechtliche Links über der Überschrift. */
/* Rechtliche Links über der Überschrift (nur noch die statischen Rechtstexte,
die App hat die Seitenleiste). */
#legal {
margin-bottom: 0.3rem;
}
@@ -62,7 +63,8 @@ header {
}
/* Klick auf die Überschrift führt zurück zum Feed. */
header > a {
header > a,
#topbar > a {
text-decoration: none;
}
@@ -102,13 +104,153 @@ h2 {
width: auto;
}
#headerbar {
background-color: white;
text-align: center;
/* --- Navigation ---
Desktop (ab 900 px): Seitenleiste fest links, Inhalt rechts daneben.
Mobil: Kopfleiste oben (Menü, Titel, Einstellungen), TabBar unten, die
Seitenleiste ist eine Schublade hinter dem Menü. */
.icon {
flex: 0 0 auto;
vertical-align: middle;
}
#headerbar a {
#topbar {
display: flex;
align-items: center;
justify-content: center;
}
.icon-btn {
display: inline-flex;
padding: 0.4rem;
margin: 0;
border: none;
background-color: white;
color: black;
}
#sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 30;
width: 15rem;
overflow-y: auto;
background-color: white;
border-right: 1px solid black;
}
#sidebar ul {
list-style: none;
margin: 0;
padding: 0.5rem 0;
}
#sidebar ul + ul {
border-top: 1px solid black;
}
#sidebar a,
#sidebar button {
display: flex;
align-items: center;
gap: 0.6rem;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0.4rem 1rem;
border: none;
text-align: left;
text-decoration: none;
color: black;
background-color: white;
}
#sidebar button span {
font-size: 1.2rem;
}
#sidebar a:hover,
#sidebar button:hover {
text-decoration: underline;
}
/* Aktuelles Ziel invertiert (NavLink setzt .active). */
#sidebar a.active,
#tabbar a.active {
background-color: black;
color: white;
}
#tabbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 20;
display: flex;
background-color: white;
border-top: 1px solid black;
}
#tabbar a {
flex: 1;
display: flex;
justify-content: center;
padding: 0.6rem 0;
}
.backdrop {
position: fixed;
inset: 0;
z-index: 25;
background-color: rgba(0, 0, 0, 0.4);
}
@media (max-width: 899px) {
header {
position: sticky;
top: 0;
z-index: 10;
padding: 0;
border-bottom: 1px solid black;
}
#topbar {
justify-content: space-between;
}
#topbar h1 {
font-size: 1.6rem;
}
/* Geschlossen: aus dem Bild und aus der Tab-Reihenfolge. */
#sidebar {
visibility: hidden;
transform: translateX(-100%);
}
#sidebar.open {
visibility: visible;
transform: none;
}
/* Platz für die TabBar, damit das Seitenende nicht darunter liegt. */
.page {
padding-bottom: 3.5rem;
}
}
@media (min-width: 900px) {
.page {
margin-left: 15rem;
}
.mobile-only,
#tabbar,
.backdrop {
display: none;
}
}
/* --- Inhaltsspalte --- */
+112
View File
@@ -0,0 +1,112 @@
import type { ReactNode } from "react";
// Strichicons als Inline-SVG (keine Icon-Bibliothek): 24er Raster, schwarze
// Linie, eckige Enden -- passend zur rohen Optik.
function Svg({ children }: { children: ReactNode }) {
return (
<svg
className="icon"
viewBox="0 0 24 24"
width="24"
height="24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="square"
strokeLinejoin="miter"
aria-hidden="true"
focusable="false"
>
{children}
</svg>
);
}
export const FeedIcon = () => (
<Svg>
<path d="M3 11l9-8 9 8M5 9v12h14V9M10 21v-6h4v6" />
</Svg>
);
export const SearchIcon = () => (
<Svg>
<circle cx="10" cy="10" r="6" />
<path d="M15 15l5 5" />
</Svg>
);
export const BellIcon = () => (
<Svg>
<path d="M6 17V10a6 6 0 0 1 12 0v7M4 17h16M10 21h4" />
</Svg>
);
export const ChatIcon = () => (
<Svg>
<path d="M4 4h16v12H10l-4 4v-4H4z" />
</Svg>
);
export const ProfileIcon = () => (
<Svg>
<circle cx="12" cy="8" r="4" />
<path d="M4 21c0-4 4-6 8-6s8 2 8 6" />
</Svg>
);
export const StatsIcon = () => (
<Svg>
<path d="M4 20h16M7 20v-6M12 20V6M17 20v-10" />
</Svg>
);
export const PrivacyIcon = () => (
<Svg>
<rect x="5" y="11" width="14" height="10" />
<path d="M8 11V7a4 4 0 0 1 8 0v4" />
</Svg>
);
export const RulesIcon = () => (
<Svg>
<path d="M6 3h12v18H6zM9 8h6M9 12h6M9 16h4" />
</Svg>
);
export const ImprintIcon = () => (
<Svg>
<circle cx="12" cy="12" r="9" />
<path d="M12 11v6M12 7v1" />
</Svg>
);
export const SettingsIcon = () => (
<Svg>
<circle cx="12" cy="12" r="6" />
<circle cx="12" cy="12" r="2" />
{/* Zähne: kurze, dicke Striche direkt am Ring (sonst sieht es nach Sonne aus). */}
<path
d="M12 2.5v4M12 17.5v4M2.5 12h4M17.5 12h4M5.3 5.3l2.8 2.8M15.9 15.9l2.8 2.8M5.3 18.7l2.8-2.8M15.9 8.1l2.8-2.8"
strokeWidth="3.5"
strokeLinecap="butt"
/>
</Svg>
);
export const LogoutIcon = () => (
<Svg>
<path d="M10 4H4v16h6M14 8l4 4-4 4M18 12H9" />
</Svg>
);
export const MenuIcon = () => (
<Svg>
<path d="M3 6h18M3 12h18M3 18h18" />
</Svg>
);
export const CloseIcon = () => (
<Svg>
<path d="M5 5l14 14M19 5L5 19" />
</Svg>
);
+6
View File
@@ -9,6 +9,7 @@ import { EntryPage } from "./pages/EntryPage";
import { UserPage } from "./pages/UserPage";
import { StatsPage } from "./pages/StatsPage";
import { ResetPage } from "./pages/ResetPage";
import { MePage, Placeholder } from "./pages/Placeholder";
import "./app.css";
const queryClient = new QueryClient({
@@ -33,6 +34,11 @@ const router = createBrowserRouter([
{ path: "/u/:username", element: <UserPage /> },
{ path: "/stats", element: <StatsPage /> },
{ path: "/reset", element: <ResetPage /> },
{ path: "/me", element: <MePage /> },
{ path: "/search", element: <Placeholder title="Suche" /> },
{ path: "/notifications", element: <Placeholder title="Benachrichtigungen" /> },
{ path: "/chats", element: <Placeholder title="Chats" /> },
{ path: "/settings", element: <Placeholder title="Einstellungen" /> },
],
},
]);
+23
View File
@@ -0,0 +1,23 @@
import { Navigate } from "react-router";
import { useMe } from "../auth";
import { AuthBox } from "../components/AuthBox";
// Placeholder steht für Bereiche, die noch eigene Projekte sind (Suche,
// Benachrichtigungen, Chats, Einstellungen).
export function Placeholder({ title }: { title: string }) {
return (
<section>
<h2>{title}</h2>
<p className="muted">Kommt noch.</p>
</section>
);
}
// MePage ist das Profil-Ziel der Navigation: angemeldet weiter zum eigenen
// Profil, sonst der Login.
export function MePage() {
const me = useMe();
if (!me.isSuccess) return null;
if (me.data) return <Navigate to={`/u/${encodeURIComponent(me.data.username)}`} replace />;
return <AuthBox />;
}