From b0958249dc95c175d9265af205d5b0363ebca9a3 Mon Sep 17 00:00:00 2001 From: Dennis Westermann Date: Mon, 9 Nov 2026 13:05:46 +0100 Subject: [PATCH 1/2] feat(profile): add profile settings with avatar, public profile and account tools - New /einstellungen page: profile (avatar, bio, location, pronouns, links), privacy (members / public / hidden, show posts and trust tree), notification preferences and account (email change, delete account). - Migration 0003: new profile columns, profile_settings table, RPCs update_profile, set_avatar, update_notification_settings, get_public_profile, delete_my_account, anon read policy for public avatars. - Public profile at /u/ for visibility = public, served via RPC only. - Auth callback honors an allow-listed next=/einstellungen redirect. - Tests: 11 new unit tests, SQL contract extended to 111 checks. Co-Authored-By: Claude Sonnet 5.5 --- app/app/einstellungen/page.tsx | 9 + app/app/globals.css | 266 +++++++ app/app/u/[username]/page.tsx | 12 +- app/components/profile.tsx | 252 ++++-- app/components/provider.tsx | 3 + app/components/settings.tsx | 722 ++++++++++++++++++ app/components/shell.tsx | 10 + app/components/ui.tsx | 2 +- app/lib/auth-callback.ts | 10 +- app/lib/image.ts | 56 ++ app/lib/model.ts | 125 ++- app/lib/public-profile.ts | 41 + app/lib/repositories/contract.ts | 11 + app/lib/repositories/demo.ts | 106 ++- app/lib/repositories/supabase.ts | 79 +- app/lib/seed.ts | 10 + app/lib/supabase/database.ts | 39 + app/tests/profile.test.ts | 254 ++++++ docs/FLUTTER_CONTRACT.md | 14 + supabase/migrations/0003_profile_settings.sql | 158 ++++ supabase/tests/README.md | 2 +- supabase/tests/contract.py | 58 ++ 22 files changed, 2164 insertions(+), 75 deletions(-) create mode 100644 app/app/einstellungen/page.tsx create mode 100644 app/components/settings.tsx create mode 100644 app/lib/image.ts create mode 100644 app/lib/public-profile.ts create mode 100644 app/tests/profile.test.ts create mode 100644 supabase/migrations/0003_profile_settings.sql diff --git a/app/app/einstellungen/page.tsx b/app/app/einstellungen/page.tsx new file mode 100644 index 0000000..95f9619 --- /dev/null +++ b/app/app/einstellungen/page.tsx @@ -0,0 +1,9 @@ +import type { Metadata } from "next"; +import { SettingsPage } from "@/components/settings"; +export const metadata: Metadata = { + title: "Einstellungen", + robots: { index: false }, +}; +export default function Page() { + return ; +} diff --git a/app/app/globals.css b/app/app/globals.css index ebee528..7f9e7d8 100644 --- a/app/app/globals.css +++ b/app/app/globals.css @@ -3379,3 +3379,269 @@ label.consent input[type="checkbox"] { font-size: 12px; padding: 8px 12px; } + +/* Profil-Einstellungen und erweiterte Profilansicht. */ +.profile-meta { + display: flex; + flex-wrap: wrap; + gap: 4px 14px; + margin-top: 8px; + font-size: 13px; + color: var(--ink-muted); +} +.profile-meta span { + display: inline-flex; + align-items: center; + gap: 5px; +} +.profile-links { + list-style: none; + display: flex; + flex-wrap: wrap; + gap: 8px; + padding: 0; + margin: 16px 0 0; +} +.profile-links a { + display: inline-flex; + align-items: center; + gap: 6px; + min-height: 34px; + padding: 6px 12px; + border: 1.5px solid var(--line); + border-radius: 999px; + font-size: 12px; + font-weight: 700; + overflow-wrap: anywhere; +} +.profile-links a:hover { + background: var(--mango); + color: var(--on-mango); +} +.profile-owner-bar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 10px; + margin: 14px 0 4px; +} +.profile-owner-bar .button { + min-height: 36px; + padding: 6px 14px; + font-size: 12px; +} +.visibility-chip { + display: inline-flex; + align-items: center; + gap: 6px; + font-size: 11px; + font-weight: 800; + letter-spacing: 0.06em; + text-transform: uppercase; + padding: 5px 10px; + border: 1.5px solid var(--line); + border-radius: 999px; +} +.settings-layout { + max-width: 710px; + margin: auto; +} +.settings-layout > .eyebrow { + display: flex; +} +.settings-title { + font-size: 54px; + margin: 12px 0 24px; +} +.settings-tabs { + display: flex; + gap: 8px; + overflow-x: auto; + border-bottom: 2px solid var(--line); + padding-bottom: 12px; + margin-bottom: 8px; +} +.settings-tabs button { + display: inline-flex; + align-items: center; + gap: 8px; + flex: none; + min-height: 42px; + padding: 8px 14px; + border: 1.5px solid transparent; + border-radius: 5px; + font-weight: 750; + font-size: 13px; +} +.settings-tabs button:hover { + background: color-mix(in srgb, var(--ink) 7%, transparent); +} +.settings-tabs button[data-state="active"] { + border-color: var(--line); + background: var(--mango); + color: var(--on-mango); +} +.settings-panel { + padding: 8px 0 40px; +} +.settings-panel h2 { + font-size: 26px; + margin: 28px 0 12px; +} +.settings-panel fieldset { + border: 0; + padding: 0; + margin: 24px 0 0; + min-width: 0; +} +.settings-panel legend { + padding: 0; + font-size: 12px; + font-weight: 700; + margin-bottom: 8px; +} +.settings-panel legend small { + font-weight: 400; + color: var(--ink-muted); + margin-left: 6px; +} +.settings-save { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-top: 26px; + padding-top: 18px; + border-top: 2px solid var(--line); +} +.settings-save .helper-text { + margin: 0; +} +.avatar-editor { + display: flex; + align-items: center; + gap: 22px; + padding: 18px 0 8px; +} +.avatar-editor .helper-text { + margin: 2px 0 10px; +} +.avatar-actions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 14px; +} +.avatar-actions .button { + min-height: 40px; + padding: 8px 14px; + font-size: 13px; +} +.link-row { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) auto; + gap: 8px; + margin-bottom: 8px; + align-items: center; +} +label.radio-card, +label.switch-row { + display: flex; + align-items: flex-start; + gap: 12px; + margin: 0 0 10px; + padding: 14px; + border: 1.5px solid var(--line); + border-radius: 5px; + background: var(--surface-raised); + font-weight: 400; + cursor: pointer; +} +label.radio-card.checked { + background: color-mix(in srgb, var(--mango) 16%, var(--surface-raised)); + box-shadow: 3px 3px 0 var(--line); +} +label.radio-card input[type="radio"], +label.switch-row input[type="checkbox"] { + width: 18px; + height: 18px; + flex: none; + margin: 2px 0 0; + padding: 0; + accent-color: var(--blue); +} +label.radio-card > svg { + flex: none; + margin-top: 1px; +} +label.radio-card > span, +label.switch-row > span { + float: none; + display: grid; + gap: 3px; + font-size: 14px; + color: var(--ink); +} +label.radio-card small, +label.switch-row small { + font-size: 12px; + color: var(--ink-muted); + line-height: 1.55; +} +label.switch-row:has(input:disabled) { + opacity: 0.5; + cursor: not-allowed; +} +.inline-form { + display: flex; + gap: 8px; + align-items: stretch; + margin-bottom: 16px; +} +.inline-form input { + flex: 1; + min-width: 0; +} +.account-email { + font-size: 14px; + margin-bottom: 4px; + overflow-wrap: anywhere; +} +.danger-zone { + margin-top: 36px; + padding: 18px; + border: 2px solid var(--line); + border-left: 6px solid #c1121f; + border-radius: 5px; +} +.danger-zone h2 { + margin-top: 0; +} +.button-danger { + background: #c1121f; + color: #fff; + border-color: #c1121f; +} +@media (max-width: 640px) { + .settings-title { + font-size: 40px; + } + .link-row { + grid-template-columns: 1fr auto; + } + .link-row input:first-child { + grid-column: 1 / -1; + } + .link-row .icon-button { + grid-column: 2; + grid-row: 2; + } + .avatar-editor { + flex-direction: column; + align-items: flex-start; + } + .inline-form { + flex-direction: column; + } +} diff --git a/app/app/u/[username]/page.tsx b/app/app/u/[username]/page.tsx index 6734e6e..03f343e 100644 --- a/app/app/u/[username]/page.tsx +++ b/app/app/u/[username]/page.tsx @@ -1,11 +1,19 @@ import type { Metadata } from "next"; import { ProfilePage } from "@/components/profile"; +import { loadPublicProfile } from "@/lib/public-profile"; type Props = { params: Promise<{ username: string }> }; export async function generateMetadata({ params }: Props): Promise { const { username } = await params; - return { title: `@${username}` }; + const person = await loadPublicProfile(username); + if (!person) return { title: `@${username}`, robots: { index: false } }; + return { + title: `${person.display_name} (@${person.username})`, + description: + person.bio || `${person.display_name} ist Mitglied bei Humans Only.`, + }; } export default async function Page({ params }: Props) { const { username } = await params; - return ; + const publicProfile = await loadPublicProfile(username); + return ; } diff --git a/app/components/profile.tsx b/app/components/profile.tsx index 21b1ef0..9bbf4ed 100644 --- a/app/components/profile.tsx +++ b/app/components/profile.tsx @@ -2,18 +2,113 @@ import Link from "next/link"; import { ArrowRight, + ExternalLink, GitBranch, + Globe, + Lock, + MapPin, Mic, + Settings, Ticket, UserRoundCheck, + Users, } from "lucide-react"; import { useClub } from "./provider"; import { Avatar, Loading } from "./ui"; import { AudioPlayer } from "./audio-player"; import { PostCard } from "./post-card"; -export function ProfilePage({ username }: { username: string }) { +import type { ProfileLink, PublicProfile, Visibility } from "@/lib/model"; +const VISIBILITY_LABEL: Record< + Visibility, + { text: string; Icon: typeof Users } +> = { + members: { text: "Nur Mitglieder", Icon: Users }, + public: { text: "Öffentlich", Icon: Globe }, + hidden: { text: "Zurückhaltend", Icon: Lock }, +}; +function ProfileMeta({ + pronouns, + location, +}: { + pronouns: string; + location: string; +}) { + if (!pronouns && !location) return null; + return ( +

+ {pronouns && {pronouns}} + {location && ( + + + {location} + + )} +

+ ); +} +function ProfileLinks({ links }: { links: ProfileLink[] }) { + const safe = links.filter((l) => /^https?:\/\//i.test(l.url)); + if (!safe.length) return null; + return ( + + ); +} +/** Was Besucher ohne Login sehen, wenn ein Mitglied sein Profil öffentlich gestellt hat. */ +function PublicProfileView({ profile }: { profile: PublicProfile }) { + return ( +
+
+
+ KEIN FILTER NÖTIG. + +
+
+ + MENSCH IM CLUBHAUS +

+ {profile.display_name} + . +

+ @{profile.username} + + {profile.bio &&

{profile.bio}

} + +

+ + Dieses Profil ist öffentlich. Beiträge und Stimme bleiben im Club. +

+ + Mit Ticket eintreten + + +
+
+
+ ); +} +export function ProfilePage({ + username, + publicProfile = null, +}: { + username: string; + publicProfile?: PublicProfile | null; +}) { const { state, loading, me } = useClub(); const person = state.profiles.find((p) => p.username === username); + if (!person && publicProfile && (loading || !me)) + return ; if (loading) return ; if (!person) return ( @@ -39,6 +134,11 @@ export function ProfilePage({ username }: { username: string }) { (p) => p.author_id === person.id && !p.parent_id, ); const mine = person.id === me?.id; + // Zurückhaltende Profile zeigen anderen Mitgliedern nur Name, Nutzername und Bild. + const restricted = person.visibility === "hidden" && !mine; + const showTree = !restricted && (person.show_trust_tree || mine); + const showPosts = !restricted && (person.show_posts || mine); + const visibility = VISIBILITY_LABEL[person.visibility]; return (
@@ -57,8 +157,34 @@ export function ProfilePage({ username }: { username: string }) { . @{person.username} -

{person.bio}

- {person.voice_intro_url ? ( + {mine && ( +
+ + + {visibility.text} + + + + Profil bearbeiten + +
+ )} + {restricted ? ( +

+ + {person.display_name} zeigt auf dem Profil nur Namen und Bild. +

+ ) : ( + <> + + {person.bio &&

{person.bio}

} + + + )} + {restricted ? null : person.voice_intro_url ? ( )} -
- {inviter ? ( - - + {showTree && ( +
+ {inviter ? ( + + + + Eingeladen von @{inviter.username} + + + + ) : ( - Eingeladen von @{inviter.username} + + Gastgeber der ersten Stunde - - - ) : ( - - - Gastgeber der ersten Stunde - - )} -
+ )} +
+ )}
-
- - - VERTRAUEN WÄCHST WEITER - -

- Gute Menschen kennen -
- gute Menschen. -

-

- {person.display_name} bürgt für {children.length}{" "} - {children.length === 1 ? "Menschen" : "Menschen"} im Clubhaus. -

-
- {children.map((child) => ( - - - {child.display_name} - @{child.username} - + {showTree && ( +
+ + + VERTRAUEN WÄCHST WEITER + +

+ Gute Menschen kennen +
+ gute Menschen. +

+

+ {person.display_name} bürgt für {children.length}{" "} + {children.length === 1 ? "Menschen" : "Menschen"} im Clubhaus. +

+
+ {children.map((child) => ( + + + {child.display_name} + @{child.username} + + + ))} +
+ {!children.length && ( +

+ Hier beginnt bald ein neuer Ast im Vertrauens-Stammbaum. +

+ )} + {mine && ( + + + {person.invites_left} Goldene Tickets ansehen + - ))} + )} +
+ )} + {showPosts && ( +
+

Gedanken von {person.display_name}

+ {posts.length ? ( + posts.map((post) => ) + ) : ( +

Der erste Beitrag kommt bestimmt.

+ )}
- {!children.length && ( -

- Hier beginnt bald ein neuer Ast im Vertrauens-Stammbaum. -

- )} - {mine && ( - - - {person.invites_left} Goldene Tickets ansehen - - - )} -
-
-

Gedanken von {person.display_name}

- {posts.length ? ( - posts.map((post) => ) - ) : ( -

Der erste Beitrag kommt bestimmt.

- )} -
+ )} ); } diff --git a/app/components/provider.tsx b/app/components/provider.tsx index ecb167b..57ce08e 100644 --- a/app/components/provider.tsx +++ b/app/components/provider.tsx @@ -11,6 +11,7 @@ import { config } from "@/lib/config"; import { createDemoSnapshot, SPACE_ID } from "@/lib/seed"; import { createRepository } from "@/lib/repositories"; import type { ClubhouseRepository } from "@/lib/repositories/contract"; +import { DEFAULT_NOTIFICATIONS } from "@/lib/model"; import type { Profile, Snapshot } from "@/lib/model"; const empty: Snapshot = { profiles: [], @@ -20,6 +21,8 @@ const empty: Snapshot = { tickets: [], votes: [], currentUserId: null, + email: null, + settings: { ...DEFAULT_NOTIFICATIONS }, waitlist: [], isAdmin: false, }; diff --git a/app/components/settings.tsx b/app/components/settings.tsx new file mode 100644 index 0000000..ba7529a --- /dev/null +++ b/app/components/settings.tsx @@ -0,0 +1,722 @@ +"use client"; +import * as Tabs from "@radix-ui/react-tabs"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { useEffect, useMemo, useRef, useState } from "react"; +import { + Bell, + Camera, + Eye, + Globe, + LogOut, + Plus, + ShieldAlert, + Trash2, + UserRound, + Users, + X, + Lock, +} from "lucide-react"; +import { useClub } from "./provider"; +import { Avatar, Loading } from "./ui"; +import { config } from "@/lib/config"; +import { prepareAvatar } from "@/lib/image"; +import { MAX_LINKS } from "@/lib/model"; +import type { + NotificationSettings, + Profile, + ProfileLink, + Visibility, +} from "@/lib/model"; + +type Draft = { + displayName: string; + bio: string; + location: string; + pronouns: string; + links: ProfileLink[]; + visibility: Visibility; + showPosts: boolean; + showTrustTree: boolean; +}; +function toDraft(p: Profile): Draft { + return { + displayName: p.display_name, + bio: p.bio, + location: p.location, + pronouns: p.pronouns, + links: p.links.map((l) => ({ ...l })), + visibility: p.visibility, + showPosts: p.show_posts, + showTrustTree: p.show_trust_tree, + }; +} +const VISIBILITY_OPTIONS: { + value: Visibility; + title: string; + text: string; + Icon: typeof Users; +}[] = [ + { + value: "members", + title: "Nur Mitglieder", + text: "Alle Mitglieder von Humans Only sehen dein Profil. Ohne Login sieht niemand etwas. Das ist die Standard-Einstellung.", + Icon: Users, + }, + { + value: "public", + title: "Öffentlich", + text: "Jeder mit dem Link sieht Namen, Bild, Bio, Ort, Pronomen und Links, auch ohne Login und in Suchmaschinen. Beiträge, Vertrauensbaum und deine Stimme bleiben im Club.", + Icon: Globe, + }, + { + value: "hidden", + title: "Zurückhaltend", + text: "Andere Mitglieder sehen auf deinem Profil nur Namen, Nutzernamen und Bild. Deine Beiträge im Clubhaus bleiben für Mitglieder sichtbar.", + Icon: Lock, + }, +]; + +export function SettingsPage() { + const { me, loading } = useClub(); + if (loading) return ; + if (!me) + return ( +
+

Einstellungen sind für Mitglieder da.

+

+ Tritt mit deinem Goldenen Ticket ein, um dein Profil zu gestalten. +

+ + Mit Ticket eintreten + +
+ ); + return ; +} + +function SettingsBody({ me }: { me: Profile }) { + const { repository, refresh, notify } = useClub(); + const [tab, setTab] = useState("profil"); + const savedKey = JSON.stringify(toDraft(me)); + const saved = useMemo(() => JSON.parse(savedKey) as Draft, [savedKey]); + const [draft, setDraft] = useState(saved); + // Neu laden (Fokus, Realtime) darf ungespeicherte Eingaben nicht überschreiben; + // erst wenn sich die gespeicherten Werte selbst ändern, wird das Formular neu aufgesetzt. + useEffect(() => setDraft(saved), [saved]); + const dirty = JSON.stringify(draft) !== savedKey; + const [saving, setSaving] = useState(false); + const [error, setError] = useState(""); + function set(key: K, value: Draft[K]) { + setDraft((d) => ({ ...d, [key]: value })); + } + async function save(event?: React.FormEvent) { + event?.preventDefault(); + setSaving(true); + setError(""); + try { + await repository().updateProfile(draft); + await refresh(); + notify("Dein Profil ist gespeichert."); + } catch (err) { + setError( + err instanceof Error + ? err.message + : "Das Profil konnte nicht gespeichert werden.", + ); + } finally { + setSaving(false); + } + } + const saveBar = ( +
+ + {dirty ? "Du hast ungespeicherte Änderungen." : "Alles gespeichert."} + + +
+ ); + return ( +
+ + ← Zurück zu deinem Profil + + DEIN PLATZ IM CLUBHAUS +

+ Einstellungen. +

+ + + + + Profil + + + + Privatsphäre + + + + Mitteilungen + + + + Konto + + + + +
void save(e)}> +
+
+ + set("displayName", e.target.value)} + maxLength={60} + autoComplete="name" + required + /> +
+
+ + +
+
+ +