Working Graphs Tab Redirection

This commit is contained in:
Neshura 2023-08-14 19:53:26 +02:00
parent ab6ff1c994
commit 44f96b6071
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 29 additions and 8 deletions

View file

@ -1,8 +0,0 @@
import { redirect } from '@sveltejs/kit';
export function load({ url }: { url: URL }) {
if (url.pathname == '/graphs') {
throw redirect(302, '/graphs/tab');
}
}

View file

@ -1,6 +1,35 @@
<script lang="ts"> <script lang="ts">
import SubNav from './SubNav.svelte'; import SubNav from './SubNav.svelte';
import '../styles.css'; import '../styles.css';
import { goto } from "$app/navigation";
import { page } from "$app/stores";
import GraphsTabStore from '$lib/stores/GraphsTab';
let graphsTab = "tab";
// Tab Detection
GraphsTabStore.subscribe(tab => {
graphsTab = tab;
if (typeof localStorage !== 'undefined') {
localStorage.setItem('graphsTab', graphsTab);
}
})
page.subscribe((tab) => {
if (tab && tab.route && tab.route.id) {
let currentTab;
const tmp = tab.route.id.split("/").at(-1);
if (typeof tmp === "string") {
currentTab = tmp;
}
else {
currentTab = "graphs";
}
if (currentTab == "graphs") {
goto('/graphs/' + graphsTab);
}
}
})
</script> </script>