From 726f5491ff02efa50182a8b12b5c074e65534937 Mon Sep 17 00:00:00 2001 From: irrlicht Date: Sat, 10 Oct 2026 20:15:47 +0200 Subject: [PATCH] Profil: Header-Bild, Beschreibung, eigene Einstellungsseite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Das Profil zeigt ein Header-Bild (ohne Bild ein schwarzer Balken), den überlappenden Avatar, Name, Beschreibung mit klickbaren Links und die Beitragszahl. Der Eigentümer bearbeitet Bilder und Beschreibung direkt auf dem Profil; Name ändern und Konto löschen liegen jetzt unter /settings, das in der Navigation eingeblendet ist. Backend: Spalten bio und header in account, neue Endpunkte /api/user/bio, /api/user/header und /api/user/header/remove; /u/{name}/info liefert header, bio und entries. Kontolöschung räumt das Header-Bild mit ab. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q --- frontend/src/Nav.tsx | 2 +- frontend/src/app.css | 66 ++++++++++-- frontend/src/main.tsx | 3 +- frontend/src/pages/Placeholder.tsx | 2 +- frontend/src/pages/SettingsPage.tsx | 66 ++++++++++++ frontend/src/pages/UserPage.tsx | 162 +++++++++++++--------------- frontend/src/types.ts | 5 + frontend/src/useFormAction.ts | 16 +++ internal/database/schema.sql | 3 + internal/httpapi/profile_test.go | 133 +++++++++++++++++++++++ internal/httpapi/server.go | 3 + internal/httpapi/users.go | 94 ++++++++++++---- notes/api.md | 7 +- notes/frontend.md | 7 +- 14 files changed, 452 insertions(+), 117 deletions(-) create mode 100644 frontend/src/pages/SettingsPage.tsx create mode 100644 frontend/src/useFormAction.ts create mode 100644 internal/httpapi/profile_test.go diff --git a/frontend/src/Nav.tsx b/frontend/src/Nav.tsx index 35a236c..5447df6 100644 --- a/frontend/src/Nav.tsx +++ b/frontend/src/Nav.tsx @@ -8,7 +8,7 @@ type Target = { title: string; icon?: ReactNode; to: string; end?: boolean }; // Bereiche, die es noch nicht gibt: Route und Platzhalter-Seite bestehen, // in der Navigation sind sie bis dahin ausgeblendet. -const unfinished = new Set(["/search", "/notifications", "/chats", "/settings"]); +const unfinished = new Set(["/search", "/notifications", "/chats"]); export const isReady = (to: string) => !unfinished.has(to); diff --git a/frontend/src/app.css b/frontend/src/app.css index 864699f..0d970c8 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -408,7 +408,6 @@ img.avatar { } img.avatar-sm { width: var(--avatar-sm); height: var(--avatar-sm); } -img.avatar-lg { width: 72px; height: 72px; } /* Byline mit kleinem Avatar neben Name + Zeitstempel. Einheitliche 1rem für die ganze Meta-Zeile (Name, Datum, Repost-Cooldown), damit nichts größer rausfällt @@ -430,13 +429,68 @@ img.avatar-lg { width: 72px; height: 72px; } /* Melden steht rechts in der Byline. */ .byline .report { margin-left: auto; } -/* Profilkopf: großer Avatar links neben Name und "Mitglied seit". */ -.profile-head { - display: flex; - align-items: center; - gap: 0.75rem; +/* --- Profil --- + Header-Bild im Format 3:1 über die ganze Spalte; ohne Bild ein schwarzer + Balken. Der Avatar ragt zur Hälfte in den Header hinein, ein weißer Rand + mit schwarzer Kante trennt ihn vom Bild. */ +#profile { padding: 0; } + +.profile-header { + aspect-ratio: 3 / 1; + background-color: black; } +.profile-header img { + display: block; + width: 100%; + height: 100%; + object-fit: cover; + margin: 0; + max-width: none; +} + +.profile-body { padding: 0 0.5rem 0.5rem; } + +.profile-top { + --avatar-xl: 112px; + display: flex; + justify-content: space-between; + align-items: flex-end; + margin-top: calc(var(--avatar-xl) / -2); +} + +img.avatar-xl { + width: var(--avatar-xl); + height: var(--avatar-xl); + border: 4px solid white; + outline: 1px solid black; +} + +#profile-name { + display: block; + margin: 0.4rem 0 0; + padding: 0; +} + +.bio { + margin: 0.4rem 0; + font-size: 1.2rem; + line-height: 1.4; + overflow-wrap: anywhere; +} + +#profile-info { margin: 0.4rem 0 0; } + +/* Bearbeiten-Bereich des Eigentümers unter dem Profilkopf. */ +.profile-edit { + border-top: 1px solid black; + margin-top: 0.5rem; +} + +.profile-edit h3, #settings h3 { margin: 0.8rem 0 0; } +.profile-edit form { display: inline-block; width: 100%; } +.counter { margin-left: auto; font-size: 1rem; } + /* --- Thread-Strich --- Der Strich ist ein eigenes Flex-Geschwister links neben dem Inhalt, nicht eine Border am Inhalt selbst. align-self: stretch macht ihn exakt so hoch diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 8ff1495..3a0b51f 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -11,6 +11,7 @@ import { StatsPage } from "./pages/StatsPage"; import { ResetPage } from "./pages/ResetPage"; import { MePage, Placeholder } from "./pages/Placeholder"; import { DocPage } from "./pages/DocPage"; +import { SettingsPage } from "./pages/SettingsPage"; import "./app.css"; const queryClient = new QueryClient({ @@ -39,7 +40,7 @@ const router = createBrowserRouter([ { path: "/search", element: }, { path: "/notifications", element: }, { path: "/chats", element: }, - { path: "/settings", element: }, + { path: "/settings", element: }, { path: "/impressum", element: }, { path: "/datenschutz", element: }, { path: "/beitragsordnung", element: }, diff --git a/frontend/src/pages/Placeholder.tsx b/frontend/src/pages/Placeholder.tsx index 0208f19..2287f05 100644 --- a/frontend/src/pages/Placeholder.tsx +++ b/frontend/src/pages/Placeholder.tsx @@ -3,7 +3,7 @@ import { useMe } from "../auth"; import { AuthBox } from "../components/AuthBox"; // Placeholder steht für Bereiche, die noch eigene Projekte sind (Suche, -// Benachrichtigungen, Chats, Einstellungen). +// Benachrichtigungen, Chats). export function Placeholder({ title }: { title: string }) { return (
diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx new file mode 100644 index 0000000..258a2a2 --- /dev/null +++ b/frontend/src/pages/SettingsPage.tsx @@ -0,0 +1,66 @@ +import { useNavigate } from "react-router"; +import { useQueryClient } from "@tanstack/react-query"; +import { useAuthChanged, useMe } from "../auth"; +import { useFormAction } from "../useFormAction"; +import { AuthBox } from "../components/AuthBox"; + +// SettingsPage: Kontoeinstellungen (Name, Löschen). Profilbild, Header und +// Beschreibung bearbeitet man auf dem eigenen Profil. +export function SettingsPage() { + const me = useMe(); + if (!me.isSuccess) return null; + if (!me.data) return ; + return ; +} + +function Settings() { + const qc = useQueryClient(); + const navigate = useNavigate(); + const authChanged = useAuthChanged(); + + // Der neue Name taucht auch in den Beitragskarten auf -> Feeds, Profile und + // das eigene Konto neu laden. + const refresh = () => { + qc.invalidateQueries({ queryKey: ["feed"] }); + qc.invalidateQueries({ queryKey: ["thread"] }); + qc.invalidateQueries({ queryKey: ["profile"] }); + return authChanged(); + }; + + const rename = useFormAction<{ username: string }>("/user/rename", "Umbenennen fehlgeschlagen.", async (form) => { + form.reset(); + await refresh(); + }); + const del = useFormAction("/user/delete", "Löschen fehlgeschlagen.", async () => { + await refresh(); + navigate("/"); + }); + + return ( +
+

Einstellungen

+ +

Name ändern

+
+ {" "} + +
+

{rename.msg}

+ {rename.ok &&

Name geändert.

} + +

Konto löschen

+
{ + if (confirm("Konto wirklich unwiderruflich löschen?")) del.onSubmit(e); + else e.preventDefault(); + }} + > +

Löscht dein Konto samt Beiträgen und Votes unwiderruflich.

{" "} + {" "} + +
+

{del.msg}

+
+ ); +} diff --git a/frontend/src/pages/UserPage.tsx b/frontend/src/pages/UserPage.tsx index 2200262..ee2f126 100644 --- a/frontend/src/pages/UserPage.tsx +++ b/frontend/src/pages/UserPage.tsx @@ -1,27 +1,33 @@ -import { useState, type FormEvent } from "react"; -import { useNavigate, useParams } from "react-router"; -import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { useState } from "react"; +import { useParams } from "react-router"; +import { useQuery, useQueryClient } from "@tanstack/react-query"; import { api, errMsg } from "../api"; import { useAuthChanged, useMe } from "../auth"; -import { avatarUrl } from "../format"; +import { avatarUrl, linkify } from "../format"; +import { useFormAction } from "../useFormAction"; import { Feed } from "../components/Feed"; import type { Profile } from "../types"; +// Muss zu maxBioRunes im Server passen (internal/httpapi/users.go). +const maxBio = 300; + // Beim Wechsel zu einem anderen Profil frisch anfangen (Meldungen, Formulare). export function UserPage() { const { username = "" } = useParams(); return ; } +// ProfileView: Header-Bild (ohne Bild ein schwarzer Balken), darauf +// überlappend der Avatar, darunter Name, Beschreibung, Meta-Zeile und die +// Beiträge. Der Eigentümer bearbeitet Bilder und Beschreibung direkt hier; +// Name und Konto stehen unter /settings. function ProfileView({ username }: { username: string }) { const profile = useQuery({ queryKey: ["profile", username], queryFn: () => api.get(`/u/${encodeURIComponent(username)}/info`), }); const me = useMe().data; - // Nach einem Upload das neue Bild sofort zeigen: Zeitstempel am URL - // umgeht den Browser-Cache. - const [avatarBust, setAvatarBust] = useState(""); + const [editing, setEditing] = useState(false); const info = profile.data; let name = ""; @@ -32,23 +38,26 @@ function ProfileView({ username }: { username: string }) { return (
-
- -
-

{name}

-

- {info && `Mitglied seit ${new Date(info.created_at * 1000).toLocaleDateString("de-DE")}`} -

-
+
+ {info?.header && }
- -