2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2022-06-21 10:38:57 +02:00
|
|
|
import { screenStore, routeStore, builderStore } from "stores"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Component from "./Component.svelte"
|
2021-09-01 12:41:48 +02:00
|
|
|
import Provider from "./context/Provider.svelte"
|
2022-06-20 17:12:46 +02:00
|
|
|
import { onMount, getContext } from "svelte"
|
2022-09-02 19:14:08 +02:00
|
|
|
import { enrichButtonActions } from "../utils/buttonActions.js"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-30 16:05:36 +01:00
|
|
|
export let params = {}
|
2022-06-20 17:12:46 +02:00
|
|
|
|
|
|
|
const context = getContext("context")
|
|
|
|
|
|
|
|
// Keep route params up to date
|
2020-11-23 12:29:24 +01:00
|
|
|
$: routeStore.actions.setRouteParams(params || {})
|
2020-11-13 16:42:32 +01:00
|
|
|
|
|
|
|
// Get the screen definition for the current route
|
2020-11-18 20:18:18 +01:00
|
|
|
$: screenDefinition = $screenStore.activeScreen?.props
|
2020-11-17 13:08:24 +01:00
|
|
|
|
2021-05-20 15:47:17 +02:00
|
|
|
onMount(() => {
|
2022-06-20 17:12:46 +02:00
|
|
|
// Mark the router as loaded whenever the screen mounts
|
2021-05-20 15:47:17 +02:00
|
|
|
if (!$routeStore.routerLoaded) {
|
|
|
|
routeStore.actions.setRouterLoaded()
|
|
|
|
}
|
2022-06-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Enrich and execute and on load actions.
|
|
|
|
// We manually construct the full context here as this component is the
|
|
|
|
// one that provides the url context, so it is not available in $context yet
|
2022-06-21 10:38:57 +02:00
|
|
|
if ($screenStore.activeScreen?.onLoad && !$builderStore.inBuilder) {
|
2022-06-20 17:12:46 +02:00
|
|
|
const actions = enrichButtonActions($screenStore.activeScreen.onLoad, {
|
|
|
|
...$context,
|
|
|
|
url: params,
|
|
|
|
})
|
2022-09-02 19:14:08 +02:00
|
|
|
if (actions != null) {
|
|
|
|
actions()
|
|
|
|
}
|
2022-06-20 17:12:46 +02:00
|
|
|
}
|
2021-05-20 15:47:17 +02:00
|
|
|
})
|
2020-11-13 16:42:32 +01:00
|
|
|
</script>
|
|
|
|
|
2021-02-10 16:49:23 +01:00
|
|
|
<!-- Ensure to fully remount when screen changes -->
|
2022-01-25 12:21:42 +01:00
|
|
|
{#if $routeStore.routerLoaded}
|
|
|
|
{#key screenDefinition?._id}
|
|
|
|
<Provider key="url" data={params}>
|
|
|
|
<Component isScreen instance={screenDefinition} />
|
|
|
|
</Provider>
|
|
|
|
{/key}
|
|
|
|
{/if}
|