Profil: Header-Bild, Beschreibung, eigene Einstellungsseite
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f8cd808c2d
commit
726f5491ff
@@ -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);
|
||||
|
||||
|
||||
+60
-6
@@ -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
|
||||
|
||||
@@ -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: <Placeholder title="Suche" /> },
|
||||
{ path: "/notifications", element: <Placeholder title="Benachrichtigungen" /> },
|
||||
{ path: "/chats", element: <Placeholder title="Chats" /> },
|
||||
{ path: "/settings", element: <Placeholder title="Einstellungen" /> },
|
||||
{ path: "/settings", element: <SettingsPage /> },
|
||||
{ path: "/impressum", element: <DocPage name="impressum" /> },
|
||||
{ path: "/datenschutz", element: <DocPage name="datenschutz" /> },
|
||||
{ path: "/beitragsordnung", element: <DocPage name="beitragsordnung" /> },
|
||||
|
||||
@@ -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 (
|
||||
<section>
|
||||
|
||||
@@ -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 <AuthBox />;
|
||||
return <Settings />;
|
||||
}
|
||||
|
||||
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 (
|
||||
<section id="settings">
|
||||
<h2>Einstellungen</h2>
|
||||
|
||||
<h3>Name ändern</h3>
|
||||
<form id="rename-form" onSubmit={rename.onSubmit}>
|
||||
<input name="user" type="text" placeholder="Neuer Nutzername" autoComplete="username" />{" "}
|
||||
<button type="submit" disabled={rename.busy}>Namen ändern</button>
|
||||
</form>
|
||||
<p className="msg" id="rename-msg">{rename.msg}</p>
|
||||
{rename.ok && <p className="muted">Name geändert.</p>}
|
||||
|
||||
<h3>Konto löschen</h3>
|
||||
<form
|
||||
id="delete-form"
|
||||
onSubmit={(e) => {
|
||||
if (confirm("Konto wirklich unwiderruflich löschen?")) del.onSubmit(e);
|
||||
else e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<p className="muted">Löscht dein Konto samt Beiträgen und Votes unwiderruflich.</p>{" "}
|
||||
<input name="pass1" type="password" placeholder="Passwort bestätigen" autoComplete="current-password" />{" "}
|
||||
<button type="submit" disabled={del.busy}>Konto endgültig löschen</button>
|
||||
</form>
|
||||
<p className="msg" id="delete-msg">{del.msg}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -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 key={username} username={username} />;
|
||||
}
|
||||
|
||||
// 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<Profile>(`/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 (
|
||||
<section id="profile">
|
||||
<div className="profile-head">
|
||||
<img
|
||||
id="profile-avatar"
|
||||
className="avatar avatar-lg"
|
||||
src={avatarUrl(info?.avatar ?? "") + avatarBust}
|
||||
alt=""
|
||||
/>
|
||||
<div>
|
||||
<h2 id="profile-name">{name}</h2>
|
||||
<p id="profile-info" className="muted">
|
||||
{info && `Mitglied seit ${new Date(info.created_at * 1000).toLocaleDateString("de-DE")}`}
|
||||
</p>
|
||||
</div>
|
||||
<div className="profile-header">
|
||||
{info?.header && <img src={`/${info.header}`} alt="" />}
|
||||
</div>
|
||||
|
||||
<div id="settings" hidden={!isOwner}>
|
||||
{isOwner && <Settings onAvatar={() => setAvatarBust(`?t=${Date.now()}`)} />}
|
||||
<div className="profile-body">
|
||||
<div className="profile-top">
|
||||
<img id="profile-avatar" className="avatar avatar-xl" src={avatarUrl(info?.avatar ?? "")} alt="" />
|
||||
{isOwner && (
|
||||
<button onClick={() => setEditing(!editing)} aria-expanded={editing}>
|
||||
{editing ? "Fertig" : "Profil bearbeiten"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<h2 id="profile-name">{name}</h2>
|
||||
{info?.bio && <p className="bio">{linkify(info.bio)}</p>}
|
||||
<p id="profile-info" className="muted">
|
||||
{info &&
|
||||
`Mitglied seit ${new Date(info.created_at * 1000).toLocaleDateString("de-DE")} · ` +
|
||||
`${info.entries} ${info.entries === 1 ? "Beitrag" : "Beiträge"}`}
|
||||
</p>
|
||||
{isOwner && editing && info && <ProfileEdit info={info} />}
|
||||
</div>
|
||||
|
||||
{info && (
|
||||
@@ -62,81 +71,64 @@ function ProfileView({ username }: { username: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
// useFormAction verdrahtet ein Einstellungsformular: POST auf path, bei Erfolg
|
||||
// onSuccess mit Formular und Antwort, bei Fehler die Meldung unter dem Formular.
|
||||
function useFormAction<T>(path: string, fallback: string, onSuccess: (form: HTMLFormElement, data: T) => void) {
|
||||
const m = useMutation({ mutationFn: (fd: FormData) => api.post<T>(path, fd) });
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const form = e.currentTarget;
|
||||
m.mutate(new FormData(form), { onSuccess: (data) => onSuccess(form, data) });
|
||||
};
|
||||
return { onSubmit, busy: m.isPending, msg: m.isError ? errMsg(m.error, fallback) : "" };
|
||||
}
|
||||
|
||||
// Settings: nur für den Eigentümer.
|
||||
function Settings({ onAvatar }: { onAvatar: () => void }) {
|
||||
// ProfileEdit: Header-Bild, Profilbild und Beschreibung, nur für den
|
||||
// Eigentümer.
|
||||
function ProfileEdit({ info }: { info: Profile }) {
|
||||
const qc = useQueryClient();
|
||||
const navigate = useNavigate();
|
||||
const authChanged = useAuthChanged();
|
||||
const [bio, setBio] = useState(info.bio);
|
||||
|
||||
// Neues Bild und neuer Name tauchen auch in den Beitragskarten auf -> die
|
||||
// Feeds und das eigene Konto neu laden.
|
||||
const refresh = () => {
|
||||
const refreshProfile = () => qc.invalidateQueries({ queryKey: ["profile"] });
|
||||
// Das Profilbild taucht auch in den Beitragskarten und im eigenen Konto auf.
|
||||
const refreshAvatar = () => {
|
||||
qc.invalidateQueries({ queryKey: ["feed"] });
|
||||
qc.invalidateQueries({ queryKey: ["thread"] });
|
||||
qc.invalidateQueries({ queryKey: ["profile"] });
|
||||
refreshProfile();
|
||||
return authChanged();
|
||||
};
|
||||
|
||||
const avatar = useFormAction<{ avatar: string }>("/user/avatar", "Hochladen fehlgeschlagen.", (form) => {
|
||||
const header = useFormAction("/user/header", "Hochladen fehlgeschlagen.", (form) => {
|
||||
form.reset();
|
||||
onAvatar();
|
||||
refresh();
|
||||
refreshProfile();
|
||||
});
|
||||
const rename = useFormAction<{ username: string }>("/user/rename", "Umbenennen fehlgeschlagen.", async (_form, data) => {
|
||||
await refresh();
|
||||
navigate(`/u/${encodeURIComponent(data.username)}`);
|
||||
});
|
||||
const del = useFormAction("/user/delete", "Löschen fehlgeschlagen.", async () => {
|
||||
await refresh();
|
||||
navigate("/");
|
||||
const removeHeader = useFormAction("/user/header/remove", "Entfernen fehlgeschlagen.", refreshProfile);
|
||||
const avatar = useFormAction("/user/avatar", "Hochladen fehlgeschlagen.", (form) => {
|
||||
form.reset();
|
||||
refreshAvatar();
|
||||
});
|
||||
const saveBio = useFormAction("/user/bio", "Speichern fehlgeschlagen.", refreshProfile);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2>Einstellungen</h2>
|
||||
<details>
|
||||
<summary>Profilbild ändern</summary>
|
||||
<form id="avatar-form" onSubmit={avatar.onSubmit}>
|
||||
<input name="avatar" type="file" accept="image/*" />{" "}
|
||||
<button type="submit" disabled={avatar.busy}>Bild hochladen</button>
|
||||
<div className="profile-edit">
|
||||
<h3>Header-Bild</h3>
|
||||
<form id="header-form" onSubmit={header.onSubmit}>
|
||||
<input name="header" type="file" accept="image/*" />{" "}
|
||||
<button type="submit" disabled={header.busy}>Bild hochladen</button>
|
||||
</form>
|
||||
{info.header && (
|
||||
<form onSubmit={removeHeader.onSubmit}>
|
||||
<button type="submit" disabled={removeHeader.busy}>Header-Bild entfernen</button>
|
||||
</form>
|
||||
<p className="msg" id="avatar-msg">{avatar.msg}</p>
|
||||
</details>
|
||||
<details>
|
||||
<summary>Name ändern</summary>
|
||||
<form id="rename-form" onSubmit={rename.onSubmit}>
|
||||
<input name="user" type="text" placeholder="Neuer Nutzername" autoComplete="username" />{" "}
|
||||
<button type="submit" disabled={rename.busy}>Namen ändern</button>
|
||||
</form>
|
||||
<p className="msg" id="rename-msg">{rename.msg}</p>
|
||||
</details>
|
||||
<details>
|
||||
<summary>Konto löschen</summary>
|
||||
<form
|
||||
id="delete-form"
|
||||
onSubmit={(e) => {
|
||||
if (confirm("Konto wirklich unwiderruflich löschen?")) del.onSubmit(e);
|
||||
else e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<p className="muted">Löscht dein Konto samt Beiträgen und Votes unwiderruflich.</p>{" "}
|
||||
<input name="pass1" type="password" placeholder="Passwort bestätigen" autoComplete="current-password" />{" "}
|
||||
<button type="submit" disabled={del.busy}>Konto endgültig löschen</button>
|
||||
</form>
|
||||
<p className="msg" id="delete-msg">{del.msg}</p>
|
||||
</details>
|
||||
</>
|
||||
)}
|
||||
<p className="msg">{header.msg || removeHeader.msg}</p>
|
||||
|
||||
<h3>Profilbild</h3>
|
||||
<form id="avatar-form" onSubmit={avatar.onSubmit}>
|
||||
<input name="avatar" type="file" accept="image/*" />{" "}
|
||||
<button type="submit" disabled={avatar.busy}>Bild hochladen</button>
|
||||
</form>
|
||||
<p className="msg" id="avatar-msg">{avatar.msg}</p>
|
||||
|
||||
<h3>Beschreibung</h3>
|
||||
<form id="bio-form" onSubmit={saveBio.onSubmit}>
|
||||
<textarea name="bio" rows={4} maxLength={maxBio} value={bio} onChange={(e) => setBio(e.target.value)} />
|
||||
<div className="row">
|
||||
<button type="submit" disabled={saveBio.busy}>Speichern</button>
|
||||
{saveBio.ok && bio === info.bio && <span className="muted">Gespeichert.</span>}
|
||||
<span className="muted counter">{[...bio].length}/{maxBio}</span>
|
||||
</div>
|
||||
</form>
|
||||
<p className="msg">{saveBio.msg}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,11 @@ export interface Profile {
|
||||
username: string;
|
||||
created_at: number;
|
||||
avatar: string;
|
||||
// Header-Bild, '' = schwarzer Balken.
|
||||
header: string;
|
||||
bio: string;
|
||||
// Anzahl nicht gelöschter Beiträge.
|
||||
entries: number;
|
||||
}
|
||||
|
||||
export interface StatsDetail {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { FormEvent } from "react";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { api, errMsg } from "./api";
|
||||
|
||||
// useFormAction verdrahtet ein Einstellungsformular: POST auf path, bei Erfolg
|
||||
// onSuccess mit Formular und Antwort, bei Fehler die Meldung unter dem Formular.
|
||||
// ok meldet, dass der letzte Versand geklappt hat.
|
||||
export function useFormAction<T>(path: string, fallback: string, onSuccess: (form: HTMLFormElement, data: T) => void) {
|
||||
const m = useMutation({ mutationFn: (fd: FormData) => api.post<T>(path, fd) });
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const form = e.currentTarget;
|
||||
m.mutate(new FormData(form), { onSuccess: (data) => onSuccess(form, data) });
|
||||
};
|
||||
return { onSubmit, busy: m.isPending, msg: m.isError ? errMsg(m.error, fallback) : "", ok: m.isSuccess };
|
||||
}
|
||||
Reference in New Issue
Block a user