Skip to content

Commit e41e9c1

Browse files
committed
fix: generate random greeting on the server
1 parent b787a27 commit e41e9c1

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/routes/app/+page.server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ export const load: PageServerLoad = async ({ locals }) => {
7575
const allPointsEarned = Number(allPointsEarnedResult[0]?.total_points ?? 0);
7676
const allAttendanceCount = Number(allAttendanceCountResult[0]?.count ?? 0);
7777

78+
const nameGreetings = [
79+
"Hey there, ",
80+
"Welcome back, ",
81+
"Good to see you, ",
82+
"Hello, ",
83+
"Hi there, ",
84+
"Howdy, ",
85+
"What's up, ",
86+
"Ahoy, ",
87+
"Today's a good day, ",
88+
];
89+
7890
return {
91+
greeting: nameGreetings[Math.floor(Math.random() * nameGreetings.length)],
7992
upcomingEvents,
8093
uniqueClubsHostingEvents,
8194
eventsHostedSemester,

src/routes/app/+page.svelte

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script lang="ts">
2-
import Countup from "$lib/components/countup.svelte";
32
import * as Card from "$lib/components/ui/card/index";
43
import type { PageProps } from "./$types";
54
65
const { data }: PageProps = $props();
76
const {
7+
greeting,
88
user,
99
userClub,
1010
upcomingEvents,
@@ -18,24 +18,12 @@
1818
} = data;
1919
2020
const theDay: string = new Date().toLocaleDateString("en-US", { weekday: "long" });
21-
const nameGreetings = [
22-
"Hey there, ",
23-
"Welcome back, ",
24-
"Good to see you, ",
25-
"Hello, ",
26-
"Hi there, ",
27-
"Howdy, ",
28-
"What's up, ",
29-
"Ahoy, ",
30-
"Today's a good day, ",
31-
];
32-
const randomNum = Math.floor(Math.random() * nameGreetings.length);
3321
</script>
3422

3523
<div>
3624
<div class="flex items-center justify-center pt-20">
3725
<div class="text-center">
38-
<h1 class="text-4xl font-bold">{nameGreetings[randomNum]}{user.name}.</h1>
26+
<h1 class="text-4xl font-bold">{greeting}{user.name}.</h1>
3927
<h2 class="text-xl">Today is {theDay}. What's next?</h2>
4028
</div>
4129
</div>

0 commit comments

Comments
 (0)