diff --git a/thoughts-frontend/components/thought-form.tsx b/thoughts-frontend/components/thought-form.tsx index 65c5afd..1ce829f 100644 --- a/thoughts-frontend/components/thought-form.tsx +++ b/thoughts-frontend/components/thought-form.tsx @@ -1,60 +1,86 @@ -"use client" +"use client"; -import { useForm } from "react-hook-form" -import { zodResolver } from "@hookform/resolvers/zod" -import { z } from "zod" -import { Button } from "@/components/ui/button" -import { Card, CardContent } from "@/components/ui/card" +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; import { Form, FormField, FormItem, FormControl, FormMessage, -} from "@/components/ui/form" -import { Textarea } from "@/components/ui/textarea" +} from "@/components/ui/form"; +import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, -} from "@/components/ui/select" -import { CreateThoughtSchema, type Me } from "@/lib/api" -import { useAuth } from "@/hooks/use-auth" -import { toast } from "sonner" -import { Globe, Lock, Users } from "lucide-react" -import { useState } from "react" -import { Confetti } from "./confetti" -import { createThought } from "@/app/actions/thoughts" +} from "@/components/ui/select"; +import { CreateThoughtSchema, type Me } from "@/lib/api"; +import { useAuth } from "@/hooks/use-auth"; +import { toast } from "sonner"; +import { Globe, Lock, Users } from "lucide-react"; +import { useState } from "react"; +import { Confetti } from "./confetti"; +import { createThought } from "@/app/actions/thoughts"; const DEFAULT_MOODS = [ - "relaxed 😌", "happy 😊", "excited ðŸĪĐ", "grateful 🙏", "inspired âœĻ", - "thoughtful ðŸĪ”", "curious 🧐", "amused 😄", "proud 💊", "hopeful 🌟", - "tired ðŸ˜ī", "stressed 😰", "anxious 😟", "sad ðŸ˜Ē", "frustrated ðŸ˜Ī", - "angry 😠", "bored 😑", "confused 😕", "nostalgic ðŸĨđ", "silly ðŸĪŠ", -] + "relaxed 😌", + "happy 😊", + "excited ðŸĪĐ", + "grateful 🙏", + "inspired âœĻ", + "thoughtful ðŸĪ”", + "curious 🧐", + "amused 😄", + "proud 💊", + "hopeful 🌟", + "tired ðŸ˜ī", + "stressed 😰", + "anxious 😟", + "sad ðŸ˜Ē", + "frustrated ðŸ˜Ī", + "angry 😠", + "bored 😑", + "confused 😕", + "nostalgic ðŸĨđ", + "silly ðŸĪŠ", +]; interface ThoughtFormProps { /** Set to the parent thought ID when composing a reply. */ - replyToId?: string + replyToId?: string; /** Called after successful submit (e.g. close the reply panel). */ - onSuccess?: () => void + onSuccess?: () => void; /** Whether to wrap in a Card. Defaults to true when no replyToId. */ - card?: boolean - currentUser?: Me | null + card?: boolean; + currentUser?: Me | null; } -export function ThoughtForm({ replyToId, onSuccess, card = !replyToId, currentUser }: ThoughtFormProps) { - const { token } = useAuth() - const [showConfetti, setShowConfetti] = useState(false) +export function ThoughtForm({ + replyToId, + onSuccess, + card = !replyToId, + currentUser, +}: ThoughtFormProps) { + const { token } = useAuth(); + const [showConfetti, setShowConfetti] = useState(false); const allMoods = [ ...DEFAULT_MOODS, ...(currentUser?.customMoods ?? []) - .filter(m => !DEFAULT_MOODS.some(d => d.toLowerCase().startsWith(m.name.toLowerCase()))) - .map(m => `${m.name} ${m.value}`), - ] + .filter( + (m) => + !DEFAULT_MOODS.some((d) => + d.toLowerCase().startsWith(m.name.toLowerCase()), + ), + ) + .map((m) => `${m.name} ${m.value}`), + ]; const form = useForm>({ resolver: zodResolver(CreateThoughtSchema), @@ -63,21 +89,23 @@ export function ThoughtForm({ replyToId, onSuccess, card = !replyToId, currentUs visibility: "public", ...(replyToId ? { inReplyToId: replyToId } : {}), }, - }) + }); async function onSubmit(values: z.infer) { if (!token) { - toast.error("You must be logged in.") - return + toast.error("You must be logged in."); + return; } try { - await createThought(values) - toast.success(replyToId ? "Reply posted!" : "Thought posted!") - setShowConfetti(true) - form.reset() - onSuccess?.() + await createThought(values); + toast.success(replyToId ? "Reply posted!" : "Thought posted!"); + setShowConfetti(true); + form.reset(); + onSuccess?.(); } catch { - toast.error(replyToId ? "Failed to post reply." : "Failed to post thought.") + toast.error( + replyToId ? "Failed to post reply." : "Failed to post thought.", + ); } } @@ -91,7 +119,9 @@ export function ThoughtForm({ replyToId, onSuccess, card = !replyToId, currentUs