feat: Completely reworked routing to use a client side stack router

This commit is contained in:
Aleksi Lassila
2024-05-16 15:15:41 +03:00
parent b0e0fe8cc9
commit c2be333d5f
14 changed files with 379 additions and 104 deletions

View File

@@ -10,26 +10,28 @@
import classNames from 'classnames';
import { get, type Readable, writable, type Writable } from 'svelte/store';
import Container from '../../../Container.svelte';
import { useLocation, useNavigate } from 'svelte-navigator';
import { registrars, Selectable } from '../../selectable';
import { defaultStackRouter, navigate } from '../StackRouter/StackRouter';
import { onMount } from 'svelte';
const location = useLocation();
const navigate = useNavigate();
let selectedIndex = 0;
$: activeIndex = {
'': 0,
series: 0,
movies: 1,
library: 2,
search: 3,
manage: 4
}[$location.pathname.split('/')[1] || '/'];
let activeIndex = -1;
// '': 0,
// series: 0,
// movies: 1,
// library: 2,
// search: 3,
// manage: 4
// }[$location.pathname.split('/')[1] || '/'];
let isNavBarOpen: Readable<boolean>;
let focusIndex: Writable<number> = writable(0);
let selectable: Selectable;
focusIndex.subscribe((v) => (selectedIndex = v));
focusIndex.subscribe((v) => {
selectedIndex = v;
});
const selectIndex = (index: number) => () => {
if (index === activeIndex) {
@@ -40,14 +42,34 @@
const path =
{
0: '/',
1: 'movies',
2: 'library',
3: 'search',
4: 'manage'
1: '/movies',
2: '/library',
3: '/search',
4: '/manage'
}[index] || '/';
navigate(path);
selectedIndex = index;
};
onMount(() => {
defaultStackRouter.subscribe((r) => {
const bottomPage = r[0];
console.log('bottomPage', bottomPage);
if (bottomPage) {
activeIndex =
{
'/': 0,
'/series': 0,
'/movies': 1,
'/library': 2,
'/search': 3,
'/manage': 4
}[bottomPage.route.path] ?? -1;
selectable.focusIndex.set(activeIndex);
selectedIndex = activeIndex;
}
});
});
</script>
<Container