From bbf03cbc2822094cffe868e0710d2a8f7e1096c0 Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Thu, 13 Feb 2025 20:08:44 +0100
Subject: frontend: Use current date to seed frontpage results

Use the current date (year, month, and day) instead of generating a new
seed every time and potentially making the user unable to go back to see
results that were displayed a moment ago. This essentially makes the
frontpage display daily favourites and bookmarks.

Additionally make sure to set the seed in the filter when navigating to
the respective category.
---
 frontend/src/routes/+page.svelte | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

(limited to 'frontend/src/routes/+page.svelte')

diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte
index 32e4e07..57a7a44 100644
--- a/frontend/src/routes/+page.svelte
+++ b/frontend/src/routes/+page.svelte
@@ -13,13 +13,24 @@
 	import { getContextClient } from '@urql/svelte';
 	import { fade } from 'svelte/transition';
 
-	const bookmarkLink = href('comics', { filter: { include: { bookmarked: true } } });
+	const bookmarkLink = href('comics', {
+		filter: { include: { bookmarked: true } },
+		sort: { on: ComicSort.Random, seed: dailySeed() }
+	});
 	const recentLink = href('comics', {
 		sort: { on: ComicSort.CreatedAt, direction: SortDirection.Descending }
 	});
-	const favouriteLink = href('comics', { filter: { include: { favourite: true } } });
+	const favouriteLink = href('comics', {
+		filter: { include: { favourite: true } },
+		sort: { on: ComicSort.Random, seed: dailySeed() }
+	});
+
+	function dailySeed() {
+		const date = new Date();
+		return +`${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`;
+	}
 
-	let query = $derived(frontpageQuery(getContextClient()));
+	let query = $derived(frontpageQuery(getContextClient(), { seed: dailySeed() }));
 	let recent = $derived($query.data?.recent);
 	let favourites = $derived($query.data?.favourites);
 	let bookmarked = $derived($query.data?.bookmarked);
-- 
cgit v1.2.3-2-gb3c3

