From a332935ba7d6a558e1172b18947dbe6cc8f5052c Mon Sep 17 00:00:00 2001 From: ginnoir Date: Wed, 3 Jun 2026 20:06:25 -0500 Subject: [PATCH] fix: render dashboard greeting and date client-side to respect local timezone --- src/app/d/[slug]/page.tsx | 18 ++---------------- src/components/dashboard-greeting.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 src/components/dashboard-greeting.tsx diff --git a/src/app/d/[slug]/page.tsx b/src/app/d/[slug]/page.tsx index ca0d84e..d49d841 100644 --- a/src/app/d/[slug]/page.tsx +++ b/src/app/d/[slug]/page.tsx @@ -9,6 +9,7 @@ import { DashboardEditor } from "@/components/dashboard-editor"; import { EditDashboardButton } from "@/components/edit-dashboard-button"; import { DashboardSwitcher } from "@/components/dashboard-switcher"; import { DashboardTab } from "@/components/dashboard-tab"; +import { DashboardGreeting } from "@/components/dashboard-greeting"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { auth } from "@/lib/auth"; import { db } from "@/lib/db"; @@ -31,9 +32,6 @@ const smColSpan: Record = { 12: "sm:col-span-12", }; -const greetingForHour = (h: number) => - h < 5 ? "Up early" : h < 12 ? "Good morning" : h < 18 ? "Good afternoon" : "Good evening"; - export default async function DashboardPage({ params, searchParams, @@ -83,12 +81,6 @@ export default async function DashboardPage({ const dashLayout = (user.themeDashLayout as DashLayout) ?? "classic"; const containerCls = dashLayout === "glance" ? "max-w-[760px] mx-auto" : dashLayout === "split" ? "" : ""; - const greeting = greetingForHour(new Date().getHours()); - const today = new Date().toLocaleDateString(undefined, { - weekday: "long", - month: "long", - day: "numeric", - }); const firstName = (user.name ?? "").split(" ")[0] ?? ""; return ( @@ -103,13 +95,7 @@ export default async function DashboardPage({ )}
-
-

- {greeting} - {firstName && `, ${firstName}`}. -

-

{today}

-
+
diff --git a/src/components/dashboard-greeting.tsx b/src/components/dashboard-greeting.tsx new file mode 100644 index 0000000..8d2ca76 --- /dev/null +++ b/src/components/dashboard-greeting.tsx @@ -0,0 +1,24 @@ +"use client"; + +const greetingForHour = (h: number) => + h < 5 ? "Up early" : h < 12 ? "Good morning" : h < 18 ? "Good afternoon" : "Good evening"; + +export function DashboardGreeting({ firstName }: { firstName: string }) { + const now = new Date(); + const greeting = greetingForHour(now.getHours()); + const today = now.toLocaleDateString(undefined, { + weekday: "long", + month: "long", + day: "numeric", + }); + + return ( +
+

+ {greeting} + {firstName && `, ${firstName}`}. +

+

{today}

+
+ ); +}