2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2020-11-25 10:50:51 +01:00
|
|
|
import { writable } from "svelte/store"
|
2020-11-19 19:39:22 +01:00
|
|
|
import { setContext, onMount } from "svelte"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Component from "./Component.svelte"
|
2021-01-27 16:52:12 +01:00
|
|
|
import NotificationDisplay from "./NotificationDisplay.svelte"
|
2021-02-05 12:44:33 +01:00
|
|
|
import Provider from "./Provider.svelte"
|
2020-11-18 20:18:18 +01:00
|
|
|
import SDK from "../sdk"
|
2021-02-01 19:51:22 +01:00
|
|
|
import {
|
|
|
|
createContextStore,
|
|
|
|
initialise,
|
|
|
|
screenStore,
|
|
|
|
authStore,
|
|
|
|
} from "../store"
|
2021-02-26 15:04:31 +01:00
|
|
|
import { TableNames, ActionTypes } from "../constants"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-20 10:50:10 +01:00
|
|
|
// Provide contexts
|
|
|
|
setContext("sdk", SDK)
|
2020-11-25 10:50:51 +01:00
|
|
|
setContext("component", writable({}))
|
2021-02-01 19:51:22 +01:00
|
|
|
setContext("context", createContextStore())
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-19 19:39:22 +01:00
|
|
|
let loaded = false
|
|
|
|
|
|
|
|
// Load app config
|
|
|
|
onMount(async () => {
|
2020-12-11 15:24:19 +01:00
|
|
|
await initialise()
|
2021-01-28 15:29:35 +01:00
|
|
|
await authStore.actions.fetchUser()
|
2020-11-19 19:39:22 +01:00
|
|
|
loaded = true
|
|
|
|
})
|
2021-02-26 15:04:31 +01:00
|
|
|
|
|
|
|
// Register this as a refreshable datasource so that user changes cause
|
|
|
|
// the user object to be refreshed
|
|
|
|
$: actions = [
|
|
|
|
{
|
|
|
|
type: ActionTypes.RefreshDatasource,
|
|
|
|
callback: () => authStore.actions.fetchUser(),
|
2021-03-16 14:54:34 +01:00
|
|
|
metadata: { dataSource: { type: "table", tableId: TableNames.USERS } },
|
2021-02-26 15:04:31 +01:00
|
|
|
},
|
|
|
|
]
|
2020-11-13 16:42:32 +01:00
|
|
|
</script>
|
|
|
|
|
2020-12-02 19:10:46 +01:00
|
|
|
{#if loaded && $screenStore.activeLayout}
|
2021-02-26 15:04:31 +01:00
|
|
|
<Provider key="user" data={$authStore} {actions}>
|
2021-02-05 12:44:33 +01:00
|
|
|
<Component definition={$screenStore.activeLayout.props} />
|
|
|
|
<NotificationDisplay />
|
|
|
|
</Provider>
|
2021-01-22 12:31:56 +01:00
|
|
|
{/if}
|