mirror of https://github.com/Budibase/budibase.git
nocodelowcodelow-codedockerdocker-composeinternal-projectinternal-toolinternal-toolslow-code-developmentlow-code-development-platformopensourceselfhostedweb-devweb-developmentweb-development-toolswebdevwebdevelopmentworkflow-automationautomationdeveloper-tools
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
82 lines
2.2 KiB
<script>
|
|
import { writable } from "svelte/store"
|
|
import { setContext, onMount } from "svelte"
|
|
import Component from "./Component.svelte"
|
|
import NotificationDisplay from "./NotificationDisplay.svelte"
|
|
import Provider from "./Provider.svelte"
|
|
import SDK from "../sdk"
|
|
import {
|
|
createContextStore,
|
|
initialise,
|
|
screenStore,
|
|
authStore,
|
|
routeStore,
|
|
builderStore,
|
|
} from "../store"
|
|
import { TableNames, ActionTypes } from "../constants"
|
|
import SettingsBar from "./SettingsBar.svelte"
|
|
|
|
// Provide contexts
|
|
setContext("sdk", SDK)
|
|
setContext("component", writable({}))
|
|
setContext("context", createContextStore())
|
|
|
|
let dataLoaded = false
|
|
|
|
// Load app config
|
|
onMount(async () => {
|
|
await initialise()
|
|
await authStore.actions.fetchUser()
|
|
dataLoaded = true
|
|
})
|
|
|
|
// 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(),
|
|
metadata: { dataSource: { type: "table", tableId: TableNames.USERS } },
|
|
},
|
|
]
|
|
|
|
// Redirect to home layout if no matching route
|
|
$: {
|
|
if (dataLoaded && $routeStore.routerLoaded && !$routeStore.activeRoute) {
|
|
if ($authStore) {
|
|
routeStore.actions.navigate("/")
|
|
} else {
|
|
const returnUrl = `${window.location.pathname}${window.location.hash}`
|
|
const encodedUrl = encodeURIComponent(returnUrl)
|
|
window.location = `/builder/auth/login?returnUrl=${encodedUrl}`
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{#if dataLoaded && $screenStore.activeLayout}
|
|
<div
|
|
id="spectrum-root"
|
|
lang="en"
|
|
dir="ltr"
|
|
class="spectrum spectrum--medium spectrum--light"
|
|
>
|
|
<Provider key="user" data={$authStore} {actions}>
|
|
<Component definition={$screenStore.activeLayout.props} />
|
|
<NotificationDisplay />
|
|
{#if $builderStore.inBuilder && $builderStore.selectedComponent}
|
|
{#key $builderStore.selectedComponentId}
|
|
<SettingsBar />
|
|
{/key}
|
|
{/if}
|
|
</Provider>
|
|
</div>
|
|
{/if}
|
|
|
|
<style>
|
|
div {
|
|
background: transparent;
|
|
height: 100%;
|
|
position: relative;
|
|
}
|
|
</style>
|
|
|