Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard-provider): fix default display of dashboard cards #428

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading