Allow user to hide unwanted panels
This commit is contained in:
@@ -10,7 +10,30 @@ import CardUpload from "./CardUpload.svelte";
|
|||||||
import CardPrepaidTransactions from "./CardPrepaidTransactions.svelte";
|
import CardPrepaidTransactions from "./CardPrepaidTransactions.svelte";
|
||||||
import CardFsHome from "./CardFSHome.svelte";
|
import CardFsHome from "./CardFSHome.svelte";
|
||||||
|
|
||||||
let cards = [
|
let cards = []
|
||||||
|
|
||||||
|
const save = () => {
|
||||||
|
let storage = {
|
||||||
|
expanded: [],
|
||||||
|
hidden: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const card of cards) {
|
||||||
|
if (card.expanded === true) {
|
||||||
|
storage.expanded.push(card.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const card of cards) {
|
||||||
|
if (card.hidden === true) {
|
||||||
|
storage.hidden.push(card.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.localStorage.setItem("dashboard_layout", JSON.stringify(storage))
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
cards = [
|
||||||
{
|
{
|
||||||
id: "upload",
|
id: "upload",
|
||||||
elem: CardUpload,
|
elem: CardUpload,
|
||||||
@@ -20,7 +43,7 @@ let cards = [
|
|||||||
elem: CardFsHome,
|
elem: CardFsHome,
|
||||||
title: "Filesystem home",
|
title: "Filesystem home",
|
||||||
link: "/d/me",
|
link: "/d/me",
|
||||||
hidden: window.user.subscription.filesystem_access === false,
|
hidden_default: window.user.subscription.filesystem_access === false,
|
||||||
}, {
|
}, {
|
||||||
id: "account",
|
id: "account",
|
||||||
elem: CardAccount,
|
elem: CardAccount,
|
||||||
@@ -36,7 +59,7 @@ let cards = [
|
|||||||
elem: CardPrepaidTransactions,
|
elem: CardPrepaidTransactions,
|
||||||
title: "Prepaid transactions",
|
title: "Prepaid transactions",
|
||||||
link: "/user/prepaid/transactions",
|
link: "/user/prepaid/transactions",
|
||||||
hidden: window.user.subscription.type !== "prepaid"
|
hidden_default: window.user.subscription.type !== "prepaid"
|
||||||
}, {
|
}, {
|
||||||
id: "usage",
|
id: "usage",
|
||||||
elem: CardUsage,
|
elem: CardUsage,
|
||||||
@@ -52,69 +75,47 @@ let cards = [
|
|||||||
link: "/user/activity",
|
link: "/user/activity",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
const save = () => {
|
|
||||||
let storage = {
|
|
||||||
expanded: [],
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const card of cards) {
|
// Apply the view settings from localstorage
|
||||||
if (card.expanded === true) {
|
try {
|
||||||
storage.expanded.push(card.id)
|
const storage = JSON.parse(window.localStorage.getItem("dashboard_layout"))
|
||||||
}
|
if (storage === null) {
|
||||||
}
|
|
||||||
|
|
||||||
window.localStorage.setItem(
|
|
||||||
"dashboard_layout",
|
|
||||||
JSON.stringify(storage),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const load = () => {
|
|
||||||
const str = window.localStorage.getItem("dashboard_layout")
|
|
||||||
if (str === null) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const storage = JSON.parse(str)
|
|
||||||
|
|
||||||
if (storage.expanded) {
|
|
||||||
for (const card of cards) {
|
for (const card of cards) {
|
||||||
if (storage.expanded.includes(card.id)) {
|
if (storage.expanded && storage.expanded.includes(card.id)) {
|
||||||
card.expanded = true
|
card.expanded = true
|
||||||
}
|
}
|
||||||
|
if (storage.hidden && storage.hidden.includes(card.id)) {
|
||||||
|
card.hidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
// Update the view
|
console.warn("Failed to load dashboard settings", err)
|
||||||
cards = cards
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
load()
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
{#each cards as card (card.id)}{#if !card.hidden}
|
{#each cards as card (card.id)}{#if !card.hidden && !card.hidden_default}
|
||||||
<div class="card" class:card_wide={card.expanded}>
|
<div class="card" class:card_wide={card.expanded}>
|
||||||
<div class="title_box">
|
<div class="title_box">
|
||||||
<h2>
|
<h2>{card.title}</h2>
|
||||||
{card.title}
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
{#if card.link}
|
{#if card.link}
|
||||||
<Button
|
<Button link_href={card.link} icon="link" flat/>
|
||||||
link_href={card.link}
|
|
||||||
icon="link"
|
|
||||||
flat
|
|
||||||
/>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
click={() => {card.expanded = !card.expanded; save()}}
|
click={() => {card.expanded = !card.expanded; save()}}
|
||||||
icon={card.expanded ? "fullscreen_exit" : "fullscreen"}
|
icon={card.expanded ? "fullscreen_exit" : "fullscreen"}
|
||||||
flat
|
flat/>
|
||||||
/>
|
<Button
|
||||||
|
click={() => {card.hidden = !card.hidden; save()}}
|
||||||
|
icon="visibility_off"
|
||||||
|
flat/>
|
||||||
</div>
|
</div>
|
||||||
<div class="card_component">
|
<div class="card_component">
|
||||||
<svelte:component this={card.elem} expanded={card.expanded}/>
|
<svelte:component this={card.elem} expanded={card.expanded}/>
|
||||||
@@ -123,6 +124,24 @@ onMount(() => {
|
|||||||
{/if}{/each}
|
{/if}{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="cards">
|
||||||
|
{#each cards as card (card.id)}
|
||||||
|
{#if card.hidden}
|
||||||
|
<div class="card">
|
||||||
|
<div class="title_box">
|
||||||
|
<h2>{card.title}</h2>
|
||||||
|
|
||||||
|
{#if card.link}
|
||||||
|
<Button link_href={card.link} icon="link" flat/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<Button click={() => {card.hidden = !card.hidden; save()}} icon="visibility" flat/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.cards {
|
.cards {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
Reference in New Issue
Block a user