From 87d3f500cccb6ad6b8472137e96bc4634e911e15 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 8 May 2023 21:24:45 +0200 Subject: add a button to change the sorting on home page Currently it is realized via a small cookie that is set, which might not be optimal. It's also not too bad though and works just well. And I'm not sure how a better alternative would look like. --- asset-sources/fietsboek.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'asset-sources') diff --git a/asset-sources/fietsboek.ts b/asset-sources/fietsboek.ts index aed2852..1cadfc2 100644 --- a/asset-sources/fietsboek.ts +++ b/asset-sources/fietsboek.ts @@ -369,6 +369,26 @@ function clearInputButtonClicked(event: MouseEvent) { addHandler(".button-clear-input", "click", clearInputButtonClicked); +/** + * Handler to change the sorting of the home page. + * + * This basically sets the cookie to signal that the home page should be + * returned reversed, and then reloads the page. + * + * @param event - The triggering event. + */ +function changeHomeSorting(_event: MouseEvent) { + const currentSorting = document.cookie.split("; ") + .find((row) => row.startsWith("home_sorting=")) + ?.split("=")[1] ?? "asc"; + const newSorting = currentSorting == "asc" ? "desc" : "asc"; + document.cookie = `home_sorting=${newSorting}; SameSite=Lax`; + window.location.reload(); +} + +addHandler("#changeHomeSorting", "click", changeHomeSorting); + + document.addEventListener('DOMContentLoaded', function() { window.fietsboekImageIndex = 0; -- cgit v1.2.3