2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2020-11-18 20:18:18 +01:00
|
|
|
import { onMount } from "svelte"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Router from "svelte-spa-router"
|
2020-11-18 20:18:18 +01:00
|
|
|
import { routeStore, screenStore } from "../store"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Screen from "./Screen.svelte"
|
2020-11-18 20:18:18 +01:00
|
|
|
import { styleable } from "../utils"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
export let styles
|
2020-11-13 16:42:32 +01:00
|
|
|
let routes
|
|
|
|
|
2020-11-19 14:50:20 +01:00
|
|
|
onMount(async () => {
|
2020-11-13 16:42:32 +01:00
|
|
|
await routeStore.actions.fetchRoutes()
|
|
|
|
await screenStore.actions.fetchScreens()
|
|
|
|
routes = {}
|
2020-11-17 13:08:24 +01:00
|
|
|
$routeStore.routes.forEach(route => {
|
2020-11-13 16:42:32 +01:00
|
|
|
routes[route.path] = Screen
|
|
|
|
})
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
// Add catch-all route so that we serve the Screen component always
|
|
|
|
routes["*"] = Screen
|
2020-11-19 14:50:20 +01:00
|
|
|
})
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
function onRouteLoading({ detail }) {
|
|
|
|
routeStore.actions.setActiveRoute(detail.route)
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if routes}
|
2020-11-17 13:08:24 +01:00
|
|
|
<div use:styleable={styles}>
|
|
|
|
<Router on:routeLoading={onRouteLoading} {routes} />
|
|
|
|
</div>
|
2020-11-13 16:42:32 +01:00
|
|
|
{/if}
|