2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2022-06-21 10:38:57 +02:00
|
|
|
import { screenStore, routeStore, builderStore } from "stores"
|
2022-10-14 11:10:06 +02:00
|
|
|
import { get } from "svelte/store"
|
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")
|
|
|
|
|
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
|
|
|
|
2022-10-14 11:10:06 +02:00
|
|
|
$: runOnLoadActions(params)
|
|
|
|
|
|
|
|
// Enrich and execute any 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
|
|
|
|
const runOnLoadActions = params => {
|
|
|
|
const screenState = get(screenStore)
|
2022-06-20 17:12:46 +02:00
|
|
|
|
2022-10-14 11:10:06 +02:00
|
|
|
if (screenState.activeScreen?.onLoad && !get(builderStore).inBuilder) {
|
|
|
|
const actions = enrichButtonActions(screenState.activeScreen.onLoad, {
|
|
|
|
...get(context),
|
2022-06-20 17:12:46 +02:00
|
|
|
url: params,
|
|
|
|
})
|
2022-09-02 19:14:08 +02:00
|
|
|
if (actions != null) {
|
|
|
|
actions()
|
|
|
|
}
|
2022-06-20 17:12:46 +02:00
|
|
|
}
|
2022-10-14 11:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
// Mark the router as loaded whenever the screen mounts
|
|
|
|
if (!$routeStore.routerLoaded) {
|
|
|
|
routeStore.actions.setRouterLoaded()
|
|
|
|
}
|
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}
|