diff --git a/frontend/src/Layout.tsx b/frontend/src/Layout.tsx index 7c805a5..3956037 100644 --- a/frontend/src/Layout.tsx +++ b/frontend/src/Layout.tsx @@ -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 ( - <> -
- -

Kontrollverlust

- {isHome ? ( - <> +
+ + {menuOpen &&
} + +
+
+
+ +

Kontrollverlust

+ + + +
+ {path === "/" && (

Ohne Datenverlust seit {plural(days, "Tag", "Tagen")}

- - - ) : ( -
zurück zum Feed
- )} -
+ )} +
- {/* Die Statistik-Seite darf auf breiten Bildschirmen breiter werden. */} -
- -
- - ); -} + {/* Die Statistik-Seite darf auf breiten Bildschirmen breiter werden. */} +
+ +
+ -// Headerbar der Startseite: angemeldet Profil-Link und Logout, sonst leer. -function Headerbar() { - const me = useMe().data; - const authChanged = useAuthChanged(); - if (!me) return
; - - // 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 ( -
- mein Profil{" "} - +
); } diff --git a/frontend/src/Nav.tsx b/frontend/src/Nav.tsx new file mode 100644 index 0000000..d051dfc --- /dev/null +++ b/frontend/src/Nav.tsx @@ -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: , to: "/", end: true }, + { title: "Suche", icon: , to: "/search" }, + { title: "Benachrichtigungen", icon: , to: "/notifications" }, + { title: "Chats", icon: , to: "/chats" }, + { title: "Profil", icon: , to: profile }, + ]; +} + +const moreTargets: Target[] = [ + { title: "Einstellungen", icon: , to: "/settings" }, + { title: "Statistik", icon: , to: "/stats" }, +]; + +// Die Rechtstexte sind statische Seiten außerhalb der App (kein Client-Routing). +const docs: Target[] = [ + { title: "Datenschutz", icon: , to: "/static/docs/datenschutz.html" }, + { title: "Beitragsordnung", icon: , to: "/static/docs/beitragsordnung.html" }, + { title: "Impressum", icon: , 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 ( + + ); +} + +// 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 ( +
    +
  • + +
  • +
+ ); +} + +// TabBar: mobil unten die fünf wichtigsten Ziele, nur Icons. +export function TabBar() { + return ( + + ); +} diff --git a/frontend/src/app.css b/frontend/src/app.css index 7decff0..760dfc3 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -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 --- */ diff --git a/frontend/src/icons.tsx b/frontend/src/icons.tsx new file mode 100644 index 0000000..3d13ab6 --- /dev/null +++ b/frontend/src/icons.tsx @@ -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 ( + + ); +} + +export const FeedIcon = () => ( + + + +); + +export const SearchIcon = () => ( + + + + +); + +export const BellIcon = () => ( + + + +); + +export const ChatIcon = () => ( + + + +); + +export const ProfileIcon = () => ( + + + + +); + +export const StatsIcon = () => ( + + + +); + +export const PrivacyIcon = () => ( + + + + +); + +export const RulesIcon = () => ( + + + +); + +export const ImprintIcon = () => ( + + + + +); + +export const SettingsIcon = () => ( + + + + {/* Zähne: kurze, dicke Striche direkt am Ring (sonst sieht es nach Sonne aus). */} + + +); + +export const LogoutIcon = () => ( + + + +); + +export const MenuIcon = () => ( + + + +); + +export const CloseIcon = () => ( + + + +); diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 6590852..964de47 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -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: }, { path: "/stats", element: }, { path: "/reset", element: }, + { path: "/me", element: }, + { path: "/search", element: }, + { path: "/notifications", element: }, + { path: "/chats", element: }, + { path: "/settings", element: }, ], }, ]); diff --git a/frontend/src/pages/Placeholder.tsx b/frontend/src/pages/Placeholder.tsx new file mode 100644 index 0000000..0208f19 --- /dev/null +++ b/frontend/src/pages/Placeholder.tsx @@ -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 ( +
+

{title}

+

Kommt noch.

+
+ ); +} + +// 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 ; + return ; +} diff --git a/internal/httpapi/server.go b/internal/httpapi/server.go index eb731ae..9667ddd 100644 --- a/internal/httpapi/server.go +++ b/internal/httpapi/server.go @@ -129,6 +129,10 @@ func (s *Server) pageRoutes(r chi.Router) { // Das Reset-Token steht im Fragment (#...) und erreicht den Server über // diese Route nie, siehe account/reset.go. r.Get("/reset", serveApp) + // Navigationsziele: Profil-Weiche und Platzhalter für kommende Bereiche. + for _, p := range []string{"/me", "/search", "/notifications", "/chats", "/settings"} { + r.Get(p, serveApp) + } // Alte Adresse der Statistik-Seite (Lesezeichen, Links von außen). r.Get("/stats.html", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/stats", http.StatusMovedPermanently) diff --git a/notes/frontend.md b/notes/frontend.md index 5deaded..ee62e12 100644 --- a/notes/frontend.md +++ b/notes/frontend.md @@ -44,13 +44,25 @@ githooks` läuft das nach jedem Commit automatisch im Hintergrund (Log: | `src/types.ts` | Typen der API-Antworten (Referenz: `notes/api.md`) | | `src/auth.ts` | `useMe()` (eigenes Konto oder `null`), `useAuthChanged()` | | `src/main.tsx` | Router, QueryClient | -| `src/Layout.tsx` | Header, Headerbar | -| `src/pages/*` | Startseite, Thread, Profil, Statistik | +| `src/Layout.tsx` | Seitenrahmen: Kopf (mobil mit Menü und Einstellungen), Schublade | +| `src/Nav.tsx` | Seitenleiste (alle Ziele) und mobile TabBar (fünf wichtigste) | +| `src/icons.tsx` | Strichicons als Inline-SVG (keine Icon-Bibliothek) | +| `src/pages/*` | Startseite, Thread, Profil, Statistik; `Placeholder.tsx` für Suche, Benachrichtigungen, Chats, Einstellungen und die Profil-Weiche `/me` | | `src/components/*` | Feed, Beitragskarte, Votes, Repost, Login, Beitrag verfassen | -Seitenrouten des Clients (`/`, `/e/:pid`, `/u/:username`, `/stats`) müssen +Seitenrouten des Clients (`/`, `/e/:pid`, `/u/:username`, `/stats`, `/reset`, +`/me`, `/search`, `/notifications`, `/chats`, `/settings`) müssen auch in `pageRoutes()` (`internal/httpapi/server.go`) stehen, sonst liefert ein direkter Aufruf 404. +## Navigation + +Ab 900 px Fensterbreite steht links die Seitenleiste mit allen Zielen (Icon + +Titel). Darunter: Kopfleiste mit Menü, Titel und Einstellungsrad, unten die +TabBar mit Feed, Suche, Benachrichtigungen, Chats und Profil; das Menü blendet +die Seitenleiste als Schublade ein. Umgeschaltet wird nur per CSS +(`app.css`, Abschnitt Navigation). Die Rechtstexte sind statische Seiten +ohne JS und behalten ihre Linkzeile (`#legal`). + ## Impressions Das Backend zählt Seitenaufrufe beim Ausliefern der `index.html`. Navigation