From 7ee5bba14c5ce42ce151ae4e6711f4064fef1500 Mon Sep 17 00:00:00 2001 From: Jake/Rads Date: Mon, 27 Jun 2022 14:45:04 +0200 Subject: [PATCH] fix(dashboard): dont use same indexes per page changing the accordion to individual collapses meant we could implement keyboard navigation between the cards however, I only handled card collapsing state per-page, which caused an issue where opening one card on one page would open the card with the same index on every page this fixes that by indexing the cards based on its position in the whole list rather than per-page --- dashboard/src/lib/list/CardsList.svelte | 32 ++++++++++++++----------- dashboard/src/lib/list/List.svelte | 2 +- dashboard/src/pages/Group.svelte | 2 +- dashboard/src/pages/Member.svelte | 2 +- dashboard/src/pages/Random.svelte | 7 +++--- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/dashboard/src/lib/list/CardsList.svelte b/dashboard/src/lib/list/CardsList.svelte index 7bbf14af..73c90684 100644 --- a/dashboard/src/lib/list/CardsList.svelte +++ b/dashboard/src/lib/list/CardsList.svelte @@ -20,8 +20,12 @@ export let isPublic: boolean; export let itemType: string; export let isMainDash: boolean; + export let itemsPerPage: number; + export let currentPage: number; export let openByDefault = false; + + $: indexStart = itemsPerPage * (currentPage - 1); let cardIndexArray = []; @@ -43,13 +47,13 @@ let el; if (event.key === "ArrowDown") { - if (cardIndexArray[index + 1]) el = cardIndexArray[index + 1]; - else el = cardIndexArray[0]; + if (index + 1 < indexStart + itemsPerPage) el = cardIndexArray[index + 1]; + else el = cardIndexArray[indexStart]; } if (event.key === "ArrowUp") { - if (cardIndexArray[index - 1]) el = cardIndexArray[index - 1]; - else el = cardIndexArray[cardIndexArray.length - 1]; + if (index - 1 >= indexStart) el = cardIndexArray[index - 1]; + else el = cardIndexArray[indexStart + itemsPerPage - 1]; } if (el) { @@ -106,9 +110,9 @@ {#each list as item, index (item.id + index)}

-

- + {#if itemType === "member"} @@ -138,10 +142,10 @@ {:else if openByDefault || settings.accessibility.expandedcards} {#each list as item, index (item.id + index)} -