From 88e1ebb783387b08b99974e2dafe872c95a9a2a2 Mon Sep 17 00:00:00 2001 From: Mathis Vester <26164587+mathisvester@users.noreply.github.com> Date: Sun, 15 Dec 2024 13:21:15 +0100 Subject: [PATCH] fix(dashboard-provider): fix default display of dashboard cards --- .../lib/providers/DashboardProvider.jsx | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rogue-thi-app/lib/providers/DashboardProvider.jsx b/rogue-thi-app/lib/providers/DashboardProvider.jsx index 1406310b..0b4d1367 100644 --- a/rogue-thi-app/lib/providers/DashboardProvider.jsx +++ b/rogue-thi-app/lib/providers/DashboardProvider.jsx @@ -12,18 +12,27 @@ const initialState = {} const DashboardContext = createContext(initialState) /** - * Get the default order of shown and hidden dashboard entries + * Check whether to display this card by default property e.g. user kind or current platform */ -function getDefaultDashboardOrder(userKind) { +function shouldDisplayCardByDefault(card, userKind) { const platform = window.matchMedia('(max-width: 768px)').matches ? PLATFORM_MOBILE : PLATFORM_DESKTOP - const filter = (x) => - x.default.includes(platform) && x.default.includes(userKind) + return card.default.includes(platform) && card.default.includes(userKind) +} + +/** + * Get the default order of shown and hidden dashboard entries + */ +function getDefaultDashboardOrder(userKind) { return { - shown: ALL_DASHBOARD_CARDS.filter(filter), - hidden: ALL_DASHBOARD_CARDS.filter((x) => !filter(x)), + shown: ALL_DASHBOARD_CARDS.filter((x) => + shouldDisplayCardByDefault(x, userKind) + ), + hidden: ALL_DASHBOARD_CARDS.filter( + (x) => !shouldDisplayCardByDefault(x, userKind) + ), } } @@ -48,7 +57,8 @@ export default function DashboardProvider({ children }) { ALL_DASHBOARD_CARDS.forEach((card) => { if ( !entries.find((x) => x.key === card.key) && - !hiddenEntries.find((x) => x.key === card.key) + !hiddenEntries.find((x) => x.key === card.key) && + shouldDisplayCardByDefault(card, userKind) ) { // new (previously unknown) card entries.splice(0, 0, card)