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:
co-authored by
Claude Opus 5.5
parent
f84ba061a8
commit
15b0bfc69c
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user