From 0021b103d0f4409e4ea099eb6e089069b4576aa7 Mon Sep 17 00:00:00 2001 From: Ryan Pandya Date: Tue, 3 Dec 2024 21:30:40 -0800 Subject: [PATCH] Minor frontend fixes --- .../dashboard/days/EditableDayComment.tsx | 2 +- .../web/components/dashboard/days/MoodStars.tsx | 17 +++++++++-------- .../dashboard/hours/EditableHourCode.tsx | 3 ++- .../dashboard/hours/EditableHourComment.tsx | 2 +- packages/trpc/routers/days.ts | 7 +++++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/web/components/dashboard/days/EditableDayComment.tsx b/apps/web/components/dashboard/days/EditableDayComment.tsx index 33e2ea4..49862aa 100644 --- a/apps/web/components/dashboard/days/EditableDayComment.tsx +++ b/apps/web/components/dashboard/days/EditableDayComment.tsx @@ -36,7 +36,7 @@ export default function EditableDayComment({ if (!newComment) { return } updateDay( { - dateQuery: format(day.date, "yyyy-MM-dd"), + dateQuery: day.date, comment: newComment, }, { diff --git a/apps/web/components/dashboard/days/MoodStars.tsx b/apps/web/components/dashboard/days/MoodStars.tsx index 662cfb0..0cd4d65 100644 --- a/apps/web/components/dashboard/days/MoodStars.tsx +++ b/apps/web/components/dashboard/days/MoodStars.tsx @@ -8,21 +8,22 @@ import { import { ButtonWithTooltip } from "@/components/ui/button"; import { Star } from "lucide-react"; import { useUpdateDay } from "@lifetracker/shared-react/hooks/days"; -import { format } from 'date-fns'; -import { useRouter } from "next/navigation"; - +import { useState } from "react"; +import { toast } from "@/components/ui/use-toast"; export function MoodStars({ - day, + day: initialDay, maximum = 10, }) { - const router = useRouter(); + + const [day, setDay] = useState(initialDay); + const { mutate: updateDay, isPending } = useUpdateDay({ - onSuccess: () => { + onSuccess: (res, req, meta) => { + setDay(res); toast({ description: "Rating updated!", }); - router.refresh(); }, }); const setStars = (newStars: number) => { @@ -32,7 +33,7 @@ export function MoodStars({ } updateDay( { - dateQuery: format(day.date, "yyyy-MM-dd"), + dateQuery: day.date, mood: newStars, }, { diff --git a/apps/web/components/dashboard/hours/EditableHourCode.tsx b/apps/web/components/dashboard/hours/EditableHourCode.tsx index b12d28e..77436b9 100644 --- a/apps/web/components/dashboard/hours/EditableHourCode.tsx +++ b/apps/web/components/dashboard/hours/EditableHourCode.tsx @@ -62,9 +62,10 @@ export function EditableHourCode({