Skip to content

Commit

Permalink
fix(dashboard-provider): fix default display of dashboard cards
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisvester committed Dec 15, 2024
1 parent 128fde8 commit 88e1ebb
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions rogue-thi-app/lib/providers/DashboardProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
}
}

Expand All @@ -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)
Expand Down

0 comments on commit 88e1ebb

Please sign in to comment.