elmeg-demo/frontend/app/settings/page.tsx
fullsizemalt bd6832705f feat: Add Mark Caught button for chase songs + fix Next.js 16 build errors
- Add MarkCaughtButton component to show page setlist
- Fix TypeScript errors in profile, settings, welcome pages
- Fix Switch component onChange props
- Fix notification-bell imports and button size
- Fix performance-list orphaned JSX
- Fix song-evolution-chart tooltip types
- Add Suspense boundaries for useSearchParams (Next.js 16 requirement)
2025-12-22 00:21:58 -08:00

139 lines
5.7 KiB
TypeScript

"use client"
import { useState, useEffect } from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { Button } from "@/components/ui/button"
import { usePreferences } from "@/contexts/preferences-context"
import { useAuth } from "@/contexts/auth-context"
import { getApiUrl } from "@/lib/api-config"
export default function SettingsPage() {
const { preferences, updatePreferences, loading } = usePreferences()
const { user } = useAuth()
const [bio, setBio] = useState("")
const [saving, setSaving] = useState(false)
const [saved, setSaved] = useState(false)
useEffect(() => {
// Bio might be in extended user response - check dynamically
if (user && 'bio' in user && typeof (user as Record<string, unknown>).bio === 'string') {
setBio((user as Record<string, unknown>).bio as string)
}
}, [user])
const handleSaveProfile = async () => {
setSaving(true)
setSaved(false)
const token = localStorage.getItem("token")
try {
await fetch(`${getApiUrl()}/users/me`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
body: JSON.stringify({ bio })
})
setSaved(true)
setTimeout(() => setSaved(false), 2000)
} catch (e) {
console.error(e)
} finally {
setSaving(false)
}
}
if (loading) {
return <div>Loading settings...</div>
}
return (
<div className="max-w-2xl mx-auto space-y-6">
<h1 className="text-3xl font-bold tracking-tight">Settings</h1>
{/* Profile Section */}
<Card>
<CardHeader>
<CardTitle>Profile</CardTitle>
<CardDescription>
Tell other fans about yourself.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label htmlFor="bio">Bio</Label>
<Textarea
id="bio"
placeholder="Been following the band since 2019..."
value={bio}
onChange={(e) => setBio(e.target.value)}
rows={3}
/>
</div>
<Button onClick={handleSaveProfile} disabled={saving}>
{saving ? "Saving..." : saved ? "Saved ✓" : "Save Profile"}
</Button>
</CardContent>
</Card>
{/* Preferences Section */}
<Card>
<CardHeader>
<CardTitle>Preferences</CardTitle>
<CardDescription>
Customize your browsing experience.
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<div className="flex items-center justify-between space-x-2">
<div className="space-y-0.5">
<Label htmlFor="wiki-mode">Wiki Mode</Label>
<p className="text-sm text-muted-foreground">
Hide all social features (comments, ratings, reviews) for a pure archive experience.
</p>
</div>
<Switch
id="wiki-mode"
checked={preferences.wiki_mode}
onChange={(e) => updatePreferences({ wiki_mode: e.target.checked })}
/>
</div>
<div className="flex items-center justify-between space-x-2">
<div className="space-y-0.5">
<Label htmlFor="show-ratings">Show Ratings</Label>
<p className="text-sm text-muted-foreground">
Display 1-10 ratings on shows and songs.
</p>
</div>
<Switch
id="show-ratings"
checked={preferences.show_ratings}
disabled={preferences.wiki_mode}
onChange={(e) => updatePreferences({ show_ratings: e.target.checked })}
/>
</div>
<div className="flex items-center justify-between space-x-2">
<div className="space-y-0.5">
<Label htmlFor="show-comments">Show Comments</Label>
<p className="text-sm text-muted-foreground">
Display comment sections on pages.
</p>
</div>
<Switch
id="show-comments"
checked={preferences.show_comments}
disabled={preferences.wiki_mode}
onChange={(e) => updatePreferences({ show_comments: e.target.checked })}
/>
</div>
</CardContent>
</Card>
</div>
)
}