import { useState } from "react"; import { Button, Field, inputClass } from "@/components/ui"; import { errorMessage } from "@/lib/api"; import { perPageOptions, ratingFilters, sortOptions } from "@/lib/browse"; import { cn } from "@/lib/cn"; import { applyPreferences, savePreferences } from "@/lib/preferences"; import type { UserPreferences } from "@/lib/types"; import { useAuth } from "@/store/auth"; import { toast } from "@/store/toasts"; const LANDING_OPTIONS: { value: NonNullable; label: string }[] = [ { value: "library", label: "Library" }, { value: "online", label: "Online" }, { value: "pools", label: "Pools" }, { value: "followed", label: "Followed" }, ]; export function PreferencesCard() { const user = useAuth((state) => state.user); const loadUser = useAuth((state) => state.loadUser); const [values, setValues] = useState({ landing_page: user?.preferences?.landing_page ?? "library", ratings: user?.preferences?.ratings ?? [], ordering: user?.preferences?.ordering ?? "-created_at", per_page: user?.preferences?.per_page ?? 48, zoom: user?.preferences?.zoom ?? 190, }); const [saving, setSaving] = useState(false); if (!user) return null; const ratings = values.ratings ?? []; function toggleRating(value: string) { const next = ratings.includes(value) ? ratings.filter((rating) => rating !== value) : [...ratings, value]; setValues((current) => ({ ...current, ratings: next })); } async function handleSave() { setSaving(true); try { const saved = await savePreferences(values); applyPreferences(saved); await loadUser(); toast.ok("Browsing preferences saved."); } catch (error) { toast.error(errorMessage(error)); } finally { setSaving(false); } } return (

Browsing preferences

Saved to your account, so they follow you to any browser. Changing the filters while browsing updates them as well.

Default rating filter
{ratingFilters.map((option) => ( ))}

No selection shows every rating.

); }