feat(settings): make SettingsProfileCard collapsible
All checks were successful
Deploy Waveform to VPS / deploy (push) Successful in 1m19s

This commit is contained in:
Chneemann 2026-09-26 17:14:40 +02:00
parent 3e1d21f259
commit 2bc0a508ea
No known key found for this signature in database

View file

@ -1,22 +1,24 @@
/** /**
* @file components/settings/SettingsProfileCard.tsx * @file components/settings/SettingsProfileCard.tsx
* @description Card component managing user profile overview, status picker, and color selection. * @description Collapsible card component managing user profile overview, status picker, and color selection.
*/ */
"use client"; "use client";
import { useState } from "react";
import { UserAvatar } from "@/components/ui/UserAvatar"; import { UserAvatar } from "@/components/ui/UserAvatar";
import { UserStatus } from "@/db/schema"; import { UserStatus } from "@/db/schema";
import { import {
MEMBER_STATUS_COLOR_CLASSES, MEMBER_STATUS_COLOR_CLASSES,
MEMBER_COLOR_OPTIONS, MEMBER_COLOR_OPTIONS,
} from "@/lib/constants/member.styles"; } from "@/lib/constants/member.styles";
import { UserRound, Palette } from "lucide-react"; import { UserRound, Palette, ChevronDown } from "lucide-react";
import { useUser } from "@/lib/context/UserContext"; import { useUser } from "@/lib/context/UserContext";
/** Props for the SettingsProfileCard component. */ /** Props for the SettingsProfileCard component. */
interface SettingsProfileCardProps { interface SettingsProfileCardProps {
onUpdate: (fields: Partial<{ status: UserStatus; color: string }>) => void; onUpdate: (fields: Partial<{ status: UserStatus; color: string }>) => void;
defaultOpen?: boolean;
} }
const STATUSES: { label: string; value: UserStatus }[] = [ const STATUSES: { label: string; value: UserStatus }[] = [
@ -26,80 +28,101 @@ const STATUSES: { label: string; value: UserStatus }[] = [
{ label: "DND", value: "DND" }, { label: "DND", value: "DND" },
]; ];
/** Renders a card for managing user profile details, online status, and theme color preferences. */ /** Renders a collapsible card for managing user profile details, status, and theme color. */
export function SettingsProfileCard({ onUpdate }: SettingsProfileCardProps) { export function SettingsProfileCard({
onUpdate,
defaultOpen = true,
}: SettingsProfileCardProps) {
const [isOpen, setIsOpen] = useState(defaultOpen);
const { currentUser } = useUser(); const { currentUser } = useUser();
if (!currentUser) return null; if (!currentUser) return null;
return ( return (
<div className="bg-surface border border-muted/20 rounded-xl p-6 space-y-6"> <div className="bg-surface border border-muted/20 rounded-xl overflow-hidden transition-all">
{/* User Info Header */} {/* Clickable Header / Toggle Bar */}
<div className="flex items-center gap-4"> <button
<UserAvatar user={currentUser} size="md" /> type="button"
<div> onClick={() => setIsOpen((prev) => !prev)}
<h2 className="text-lg font-bold text-white"> className="w-full p-4 flex items-center justify-between hover:bg-white/5 transition-colors cursor-pointer text-left"
{currentUser.username} >
</h2> <div className="flex items-center gap-4">
<p className="text-sm text-muted">{currentUser.email}</p> <UserAvatar user={currentUser} size="md" />
<div>
<h2 className="text-lg font-bold text-white">
{currentUser.username}
</h2>
<p className="text-sm text-muted">{currentUser.email}</p>
</div>
</div> </div>
</div>
{/* Status Selection */} <ChevronDown
<div className="border-t border-muted/20 pt-6 space-y-4"> className={`w-5 h-5 text-muted transition-transform duration-200 ${
<h3 className="text-sm font-semibold text-white flex items-center gap-2"> isOpen ? "rotate-180" : "rotate-0"
<UserRound className="w-4 h-4 text-muted" /> Online Status }`}
</h3> />
<div className="grid grid-cols-2 sm:grid-cols-4 gap-3"> </button>
{STATUSES.map((status) => {
const isSelected = currentUser.status === status.value;
return (
<button
key={status.value}
type="button"
onClick={() => onUpdate({ status: status.value })}
className={`flex items-center gap-2.5 p-3 rounded-lg border text-sm font-medium transition-all ${
isSelected
? "border-accent bg-accent/10 text-white font-semibold"
: "border-muted/20 hover:border-muted/40 text-muted hover:text-white cursor-pointer"
}`}
>
<span
className={`w-2.5 h-2.5 rounded-full ${
MEMBER_STATUS_COLOR_CLASSES[status.value]
}`}
/>
{status.label}
</button>
);
})}
</div>
</div>
{/* Color Palette Selection */} {/* Collapsible Content */}
<div className="border-t border-muted/20 pt-6 space-y-4"> {isOpen && (
<h3 className="text-sm font-semibold text-white flex items-center gap-2"> <div className="p-4 pt-0 space-y-4">
<Palette className="w-4 h-4 text-muted" /> Profile Color {/* Status Selection */}
</h3> <div className="border-t border-muted/20 pt-4 space-y-4">
<div className="flex flex-wrap gap-3"> <h3 className="text-sm font-semibold text-white flex items-center gap-2">
{MEMBER_COLOR_OPTIONS.map((colorClass) => { <UserRound className="w-4 h-4 text-muted" /> Online Status
const isSelected = currentUser.color === colorClass; </h3>
return ( <div className="grid grid-cols-2 sm:grid-cols-4 gap-3">
<button {STATUSES.map((status) => {
key={colorClass} const isSelected = currentUser.status === status.value;
type="button" return (
onClick={() => onUpdate({ color: colorClass })} <button
className={`w-8 h-8 rounded-full ${colorClass} transition-all flex items-center justify-center ${ key={status.value}
isSelected type="button"
? "ring-2 ring-white ring-offset-2 ring-offset-surface scale-110" onClick={() => onUpdate({ status: status.value })}
: "hover:scale-105 opacity-80 hover:opacity-100 cursor-pointer" className={`flex items-center gap-2.5 p-3 rounded-lg border text-sm font-medium transition-all ${
}`} isSelected
aria-label={`Select ${colorClass}`} ? "border-accent bg-accent/10 text-white font-semibold"
/> : "border-muted/20 hover:border-muted/40 text-muted hover:text-white cursor-pointer"
); }`}
})} >
<span
className={`w-2.5 h-2.5 rounded-full ${
MEMBER_STATUS_COLOR_CLASSES[status.value]
}`}
/>
{status.label}
</button>
);
})}
</div>
</div>
{/* Color Palette Selection */}
<div className="border-t border-muted/20 py-4 space-y-4">
<h3 className="text-sm font-semibold text-white flex items-center gap-2">
<Palette className="w-4 h-4 text-muted" /> Profile Color
</h3>
<div className="flex flex-wrap gap-3">
{MEMBER_COLOR_OPTIONS.map((colorClass) => {
const isSelected = currentUser.color === colorClass;
return (
<button
key={colorClass}
type="button"
onClick={() => onUpdate({ color: colorClass })}
className={`w-8 h-8 rounded-full ${colorClass} transition-all flex items-center justify-center ${
isSelected
? "ring-2 ring-white ring-offset-2 ring-offset-surface scale-110"
: "hover:scale-105 opacity-80 hover:opacity-100 cursor-pointer"
}`}
aria-label={`Select ${colorClass}`}
/>
);
})}
</div>
</div>
</div> </div>
</div> )}
</div> </div>
); );
} }