Add custom dashboard card order
This commit is contained in:
@@ -10,18 +10,21 @@ 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";
|
||||||
import AddressReputation from "../../home_page/AddressReputation.svelte";
|
import AddressReputation from "../../home_page/AddressReputation.svelte";
|
||||||
|
import { flip } from "svelte/animate";
|
||||||
|
|
||||||
let cards = []
|
let cards = []
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
let storage = {
|
let storage = {
|
||||||
size: {},
|
size: {},
|
||||||
|
order: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const card of cards) {
|
for (const card of cards) {
|
||||||
if (card.size !== undefined && card.size !== 1) {
|
if (card.size !== undefined && card.size !== 1) {
|
||||||
storage.size[card.id] = card.size
|
storage.size[card.id] = card.size
|
||||||
}
|
}
|
||||||
|
storage.order.push(card.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.localStorage.setItem("dashboard_layout", JSON.stringify(storage))
|
window.localStorage.setItem("dashboard_layout", JSON.stringify(storage))
|
||||||
@@ -50,50 +53,65 @@ const shrink = i => {
|
|||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const swap_card = (idx1, idx2) => {
|
||||||
|
const card1 = cards[idx1]
|
||||||
|
cards[idx1] = cards[idx2]
|
||||||
|
cards[idx2] = card1
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
cards = [
|
cards = []
|
||||||
{
|
cards.push({
|
||||||
id: "upload",
|
id: "upload",
|
||||||
elem: CardUpload,
|
elem: CardUpload,
|
||||||
title: "Quick upload",
|
title: "Quick upload",
|
||||||
link: "/",
|
link: "/",
|
||||||
}, {
|
})
|
||||||
|
if (window.user.subscription.filesystem_access === true) {
|
||||||
|
cards.push({
|
||||||
id: "filesystem_home",
|
id: "filesystem_home",
|
||||||
elem: CardFsHome,
|
elem: CardFsHome,
|
||||||
title: "Filesystem home",
|
title: "Filesystem home",
|
||||||
link: "/d/me",
|
link: "/d/me",
|
||||||
hidden: window.user.subscription.filesystem_access === false,
|
})
|
||||||
}, {
|
}
|
||||||
|
cards.push({
|
||||||
id: "account",
|
id: "account",
|
||||||
elem: CardAccount,
|
elem: CardAccount,
|
||||||
title: "Account",
|
title: "Account",
|
||||||
link: "/user/settings",
|
link: "/user/settings",
|
||||||
}, {
|
})
|
||||||
|
cards.push({
|
||||||
id: "subscription",
|
id: "subscription",
|
||||||
elem: CardSubscription,
|
elem: CardSubscription,
|
||||||
title: "Subscription",
|
title: "Subscription",
|
||||||
link: "/user/subscription",
|
link: "/user/subscription",
|
||||||
}, {
|
})
|
||||||
|
if (window.user.subscription.type === "prepaid") {
|
||||||
|
cards.push({
|
||||||
id: "prepaid_transactions",
|
id: "prepaid_transactions",
|
||||||
elem: CardPrepaidTransactions,
|
elem: CardPrepaidTransactions,
|
||||||
title: "Prepaid transactions",
|
title: "Prepaid transactions",
|
||||||
link: "/user/prepaid/transactions",
|
link: "/user/prepaid/transactions",
|
||||||
hidden: window.user.subscription.type !== "prepaid"
|
})
|
||||||
}, {
|
}
|
||||||
|
cards.push({
|
||||||
id: "usage",
|
id: "usage",
|
||||||
elem: CardUsage,
|
elem: CardUsage,
|
||||||
title: "Usage",
|
title: "Usage",
|
||||||
}, {
|
})
|
||||||
|
cards.push({
|
||||||
id: "statistics",
|
id: "statistics",
|
||||||
elem: CardStatistics,
|
elem: CardStatistics,
|
||||||
title: "Statistics",
|
title: "Statistics",
|
||||||
}, {
|
})
|
||||||
id: "activiy",
|
cards.push({
|
||||||
|
id: "activity",
|
||||||
elem: CardActivity,
|
elem: CardActivity,
|
||||||
title: "Activity",
|
title: "Activity",
|
||||||
link: "/user/activity",
|
link: "/user/activity",
|
||||||
},
|
})
|
||||||
]
|
|
||||||
|
|
||||||
// Apply the view settings from localstorage
|
// Apply the view settings from localstorage
|
||||||
try {
|
try {
|
||||||
@@ -110,6 +128,12 @@ onMount(() => {
|
|||||||
card.size = 1
|
card.size = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (layout.order !== undefined && layout.order instanceof Array) {
|
||||||
|
cards.sort((card1, card2) => {
|
||||||
|
return layout.order.indexOf(card1.id) - layout.order.indexOf(card2.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Failed to load dashboard settings", err)
|
console.warn("Failed to load dashboard settings", err)
|
||||||
return
|
return
|
||||||
@@ -123,8 +147,8 @@ onMount(() => {
|
|||||||
|
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
{#each cards as card, i (card.id)}
|
{#each cards as card, i (card.id)}
|
||||||
{#if !card.hidden && card.size > 0}
|
|
||||||
<div
|
<div
|
||||||
|
animate:flip={{duration: 250}}
|
||||||
class="card"
|
class="card"
|
||||||
class:size_1={card.size === 1}
|
class:size_1={card.size === 1}
|
||||||
class:size_2={card.size === 2}
|
class:size_2={card.size === 2}
|
||||||
@@ -132,10 +156,21 @@ onMount(() => {
|
|||||||
>
|
>
|
||||||
<div class="title_box">
|
<div class="title_box">
|
||||||
{#if card.link}
|
{#if card.link}
|
||||||
<Button link_href={card.link} icon="link" flat/>
|
<h2>
|
||||||
|
<a href={card.link}>
|
||||||
|
{card.title}
|
||||||
|
</a>
|
||||||
|
</h2>
|
||||||
|
{:else}
|
||||||
|
<h2>{card.title}</h2>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<h2>{card.title}</h2>
|
{#if i > 0}
|
||||||
|
<Button click={() => swap_card(i, i-1)} icon="chevron_left" flat/>
|
||||||
|
{/if}
|
||||||
|
{#if i < cards.length-1}
|
||||||
|
<Button click={() => swap_card(i, i+1)} icon="chevron_right" flat/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Button click={() => shrink(i)} icon="zoom_out" flat/>
|
<Button click={() => shrink(i)} icon="zoom_out" flat/>
|
||||||
<span>
|
<span>
|
||||||
@@ -143,29 +178,13 @@ onMount(() => {
|
|||||||
</span>
|
</span>
|
||||||
<Button click={() => expand(i)} icon="zoom_in" flat/>
|
<Button click={() => expand(i)} icon="zoom_in" flat/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if !card.hidden && card.size > 0}
|
||||||
<div class="card_component">
|
<div class="card_component">
|
||||||
<svelte:component this={card.elem} card_size={card.size}/>
|
<svelte:component this={card.elem} card_size={card.size}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="cards">
|
|
||||||
{#each cards as card, i (card.id)}
|
|
||||||
{#if card.size === 0}
|
|
||||||
<div class="card size_1">
|
|
||||||
<div class="title_box">
|
|
||||||
{#if card.link}
|
|
||||||
<Button link_href={card.link} icon="link" flat/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<h2>{card.title}</h2>
|
|
||||||
|
|
||||||
<Button click={() => expand(i)} icon="visibility" flat/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -215,6 +234,10 @@ onMount(() => {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
text-align: center;
|
padding-left: 0.2em;
|
||||||
|
}
|
||||||
|
.title_box > h2 > a {
|
||||||
|
border-bottom: none;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Reference in New Issue
Block a user