Skip to content

Commit

Permalink
explorer: link network select to appStore
Browse files Browse the repository at this point in the history
  • Loading branch information
deuch13 committed May 20, 2024
1 parent 8df8c07 commit 824bfc5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ exports[`Navbar > renders the Navbar component 1`] = `
<option
value="nodes.dusk.network"
>
testnet
Testnet
</option>
<option
value="devnet.nodes.dusk.network"
>
devnet
Devnet
</option>
Expand Down
8 changes: 1 addition & 7 deletions explorer/src/lib/components/navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@
}

.dusk-navbar__menu--network {
order: 3;
}

.dusk-navbar__menu--network select {
text-transform: uppercase;
padding: 0.625rem 0.875rem;
padding-right: 2.25rem;
font-size: 0.875rem;
font-weight: 500;
order: 3;
}

.dusk-navbar__menu--links {
Expand Down
28 changes: 16 additions & 12 deletions explorer/src/lib/components/navbar/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Button, NavList, Select } from "$lib/dusk/components";
import { AppAnchor, AppImage, SearchNotification } from "$lib/components";
import { SearchField } from "$lib/containers";
import { appStore } from "$lib/stores";
import "./Navbar.css";
Expand Down Expand Up @@ -36,17 +37,6 @@
},
];
const networks = [
{
label: "testnet",
value: `${import.meta.env.VITE_DUSK_TESTNET_NODE}`,
},
{
label: "devnet",
value: `${import.meta.env.VITE_DUSK_DEVNET_NODE}`,
},
];
const dispatch = createEventDispatcher();
async function createEmptySpace() {
Expand All @@ -56,11 +46,21 @@
)[0]?.clientHeight;
}
/**
* @param {Event} e
*/
function handleChange(e) {
// @ts-ignore
appStore.setNetwork(e.target.value);
}
afterNavigate(() => {
hidden = true;
dispatch("toggleMenu", hidden);
showSearchNotification = false;
});
$: ({ networks } = $appStore);
</script>
<nav
Expand Down Expand Up @@ -92,7 +92,11 @@
class:dusk-navbar__menu--hidden={hidden}
id="dusk-navbar-menu"
>
<Select className="dusk-navbar__menu--network" options={networks} />
<Select
className="dusk-navbar__menu--network"
on:change={handleChange}
options={networks}
/>
<NavList className="dusk-navbar__menu--links" {navigation} />
<div class="dusk-navbar__menu--search">
<SearchField
Expand Down
5 changes: 5 additions & 0 deletions explorer/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
onDestroy(pollingDataStore.stop);
$: ({ data, error, isLoading } = $pollingDataStore);
onNetworkChange((network) => {
pollingDataStore.stop();
pollingDataStore.start(network);
});
</script>

<section class="chain-info">
Expand Down

0 comments on commit 824bfc5

Please sign in to comment.