diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-05-08 21:24:45 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-05-08 21:24:45 +0200 |
commit | 87d3f500cccb6ad6b8472137e96bc4634e911e15 (patch) | |
tree | 5a13de99d2c444ba997aa69371f2385c0195a9f8 /asset-sources/fietsboek.ts | |
parent | f7fce26deacf8b63b4852c511eb9cf460df694f9 (diff) | |
download | fietsboek-87d3f500cccb6ad6b8472137e96bc4634e911e15.tar.gz fietsboek-87d3f500cccb6ad6b8472137e96bc4634e911e15.tar.bz2 fietsboek-87d3f500cccb6ad6b8472137e96bc4634e911e15.zip |
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.
Diffstat (limited to 'asset-sources/fietsboek.ts')
-rw-r--r-- | asset-sources/fietsboek.ts | 20 |
1 files changed, 20 insertions, 0 deletions
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; |