-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<script lang="ts"> | ||
import HomeLayout from "@kredeum/svelte/src/components/Global/HomeLayout.svelte"; | ||
import Navigation from "@kredeum/svelte/src/components/Global/Navigation.svelte"; | ||
import StatsNetworks from "./StatsNetworks.svelte"; | ||
import type { NetworkType } from "@kredeum/common/src/common/types"; | ||
import { networks } from "@kredeum/common/src/common/networks"; | ||
// Manage StatsNetworks Svelte components in Tabs with 2 states: | ||
// - active (i.e. displayed) or not (only one at a time) | ||
// - mounted or not (mounted one time, can't be unmounted) | ||
// To avoid re-calling onchain data each time tab is reactivated | ||
// To avoid calling onchain data on a tab never activated | ||
type TabsMounted = { [key: string]: boolean }; | ||
let tabsMounted: TabsMounted = { | ||
Mainnets: true, | ||
OPnets: false, | ||
Testnets: false, | ||
Inactives: false | ||
}; | ||
let tabActive = "Mainnets"; | ||
const getNetworks = (tab: string): NetworkType[] => { | ||
if (tab === "OPnets") return networks.getAllOpMainnets(); | ||
if (tab === "Testnets") return networks.getAllTestnets(); | ||
if (tab === "Inactives") return networks.getAllInactive(); | ||
return networks.getAllMainnets(); | ||
}; | ||
$: console.log(tabsMounted); | ||
</script> | ||
|
||
<HomeLayout> | ||
<span slot="nav"> | ||
<Navigation chainId={0} /> | ||
</span> | ||
|
||
<span slot="header"> | ||
<h1>Kredeum NFTs Factory - Statistics</h1> | ||
</span> | ||
|
||
<span slot="content"> | ||
<div class="stats"> | ||
<div class="tabs"> | ||
{#each Object.keys(tabsMounted) as tabKey} | ||
<button | ||
class={tabActive === tabKey ? "active" : ""} | ||
on:click={() => { | ||
console.log("click", tabKey, tabsMounted); | ||
tabActive = tabKey; | ||
tabsMounted[tabKey] = true; | ||
}}>{tabKey}</button | ||
> | ||
{/each} | ||
</div> | ||
|
||
{#each Object.entries(tabsMounted) as [tabKey, tabMounted]} | ||
{#if tabMounted} | ||
<span class={tabActive === tabKey ? "" : "hidden"}> | ||
<StatsNetworks networks={getNetworks(tabKey)} /> | ||
</span> | ||
{/if} | ||
{/each} | ||
</div> | ||
</span> | ||
</HomeLayout> | ||
|
||
<style> | ||
.stats { | ||
margin-left: 20px; | ||
} | ||
.tabs { | ||
display: flex; | ||
gap: 10px; | ||
} | ||
.tabs button { | ||
padding: 10px; | ||
border: none; | ||
cursor: pointer; | ||
background-color: #aaa; | ||
} | ||
.tabs button.active { | ||
background-color: #eee; | ||
} | ||
</style> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,5 @@ | ||
<script lang="ts"> | ||
import Addresses from "./Addresses.svelte"; | ||
import type { NetworkType } from "@kredeum/common/src/common/types"; | ||
import { networks } from "@kredeum/common/src/common/networks"; | ||
// Manage Addresses Svelte components in Tabs with 2 states: | ||
// - active (i.e. displayed) or not (only one at a time) | ||
// - mounted or not (mounted one time, can't be unmounted) | ||
// To avoid re-calling onchain data each time tab is reactivated | ||
// To avoid calling onchain data on a tab never activated | ||
type TabsMounted = { [key: string]: boolean }; | ||
let tabsMounted: TabsMounted = { | ||
Mainnets: true, | ||
OPnets: false, | ||
Testnets: false, | ||
Inactives: false | ||
}; | ||
let tabActive = "Mainnets"; | ||
const getNetworks = (tab: string): NetworkType[] => { | ||
if (tab === "OPnets") return networks.getAllOpMainnets(); | ||
if (tab === "Testnets") return networks.getAllTestnets(); | ||
if (tab === "Inactives") return networks.getAllInactive(); | ||
return networks.getAllMainnets(); | ||
}; | ||
$: console.log(tabsMounted); | ||
import Stats from "$lib/components/Stats.svelte"; | ||
</script> | ||
|
||
<div class="stats"> | ||
<h1>Kredeum NFTs Factory - Statistics</h1> | ||
|
||
<div class="tabs"> | ||
{#each Object.keys(tabsMounted) as tabKey} | ||
<button | ||
class={tabActive === tabKey ? "active" : ""} | ||
on:click={() => { | ||
console.log("click", tabKey, tabsMounted); | ||
tabActive = tabKey; | ||
tabsMounted[tabKey] = true; | ||
}}>{tabKey}</button | ||
> | ||
{/each} | ||
</div> | ||
|
||
{#each Object.entries(tabsMounted) as [tabKey, tabMounted]} | ||
{#if tabMounted} | ||
<span class={tabActive === tabKey ? "" : "hidden"}> | ||
<Addresses networks={getNetworks(tabKey)} /> | ||
</span> | ||
{/if} | ||
{/each} | ||
</div> | ||
|
||
<style> | ||
.stats { | ||
margin-left: 20px; | ||
} | ||
.tabs { | ||
display: flex; | ||
gap: 10px; | ||
} | ||
.tabs button { | ||
padding: 10px; | ||
border: none; | ||
cursor: pointer; | ||
background-color: #aaa; | ||
} | ||
.tabs button.active { | ||
background-color: #eee; | ||
} | ||
</style> | ||
<Stats /> |
This file was deleted.
Oops, something went wrong.