diff --git a/svelte/src/user_home/dashboard/Dashboard.svelte b/svelte/src/user_home/dashboard/Dashboard.svelte index 5cc31cd..c7bf41c 100644 --- a/svelte/src/user_home/dashboard/Dashboard.svelte +++ b/svelte/src/user_home/dashboard/Dashboard.svelte @@ -10,51 +10,12 @@ import CardUpload from "./CardUpload.svelte"; import CardPrepaidTransactions from "./CardPrepaidTransactions.svelte"; import CardFsHome from "./CardFSHome.svelte"; -let cards = [ - { - id: "upload", - elem: CardUpload, - title: "Quick upload", - }, { - id: "filesystem_home", - elem: CardFsHome, - title: "Filesystem home", - link: "/d/me", - hidden: window.user.subscription.filesystem_access === false, - }, { - id: "account", - elem: CardAccount, - title: "Account", - link: "/user/settings", - }, { - id: "subscription", - elem: CardSubscription, - title: "Subscription", - link: "/user/subscription", - }, { - id: "prepaid_transactions", - elem: CardPrepaidTransactions, - title: "Prepaid transactions", - link: "/user/prepaid/transactions", - hidden: window.user.subscription.type !== "prepaid" - }, { - id: "usage", - elem: CardUsage, - title: "Usage", - }, { - id: "statistics", - elem: CardStatistics, - title: "Statistics", - }, { - id: "activiy", - elem: CardActivity, - title: "Activity", - link: "/user/activity", - }, -] +let cards = [] + const save = () => { let storage = { expanded: [], + hidden: [], } for (const card of cards) { @@ -62,59 +23,99 @@ const save = () => { storage.expanded.push(card.id) } } - - window.localStorage.setItem( - "dashboard_layout", - JSON.stringify(storage), - ) -} - -const load = () => { - const str = window.localStorage.getItem("dashboard_layout") - if (str === null) { - return - } - - const storage = JSON.parse(str) - - if (storage.expanded) { - for (const card of cards) { - if (storage.expanded.includes(card.id)) { - card.expanded = true - } + for (const card of cards) { + if (card.hidden === true) { + storage.hidden.push(card.id) } } - // Update the view - cards = cards + window.localStorage.setItem("dashboard_layout", JSON.stringify(storage)) } onMount(() => { - load() + cards = [ + { + id: "upload", + elem: CardUpload, + title: "Quick upload", + }, { + id: "filesystem_home", + elem: CardFsHome, + title: "Filesystem home", + link: "/d/me", + hidden_default: window.user.subscription.filesystem_access === false, + }, { + id: "account", + elem: CardAccount, + title: "Account", + link: "/user/settings", + }, { + id: "subscription", + elem: CardSubscription, + title: "Subscription", + link: "/user/subscription", + }, { + id: "prepaid_transactions", + elem: CardPrepaidTransactions, + title: "Prepaid transactions", + link: "/user/prepaid/transactions", + hidden_default: window.user.subscription.type !== "prepaid" + }, { + id: "usage", + elem: CardUsage, + title: "Usage", + }, { + id: "statistics", + elem: CardStatistics, + title: "Statistics", + }, { + id: "activiy", + elem: CardActivity, + title: "Activity", + link: "/user/activity", + }, + ] + + // Apply the view settings from localstorage + try { + const storage = JSON.parse(window.localStorage.getItem("dashboard_layout")) + if (storage === null) { + return + } + + for (const card of cards) { + if (storage.expanded && storage.expanded.includes(card.id)) { + card.expanded = true + } + if (storage.hidden && storage.hidden.includes(card.id)) { + card.hidden = true + } + } + } catch (err) { + console.warn("Failed to load dashboard settings", err) + return + } })