2020-11-17 13:08:24 +01:00
|
|
|
import { writable, derived } from "svelte/store"
|
|
|
|
import { routeStore } from "./routes"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-18 20:18:18 +01:00
|
|
|
const createScreenStore = () => {
|
2020-11-17 13:08:24 +01:00
|
|
|
const screens = writable([])
|
|
|
|
const store = derived([screens, routeStore], ([$screens, $routeStore]) => {
|
2020-11-18 22:06:12 +01:00
|
|
|
const activeScreen =
|
|
|
|
$screens.length === 1
|
|
|
|
? $screens[0]
|
|
|
|
: $screens.find(screen => screen.route === $routeStore.activeRoute)
|
2020-11-17 13:08:24 +01:00
|
|
|
return {
|
|
|
|
screens: $screens,
|
|
|
|
activeScreen,
|
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const fetchScreens = () => {
|
|
|
|
const frontendDefinition = window["##BUDIBASE_FRONTEND_DEFINITION##"]
|
2020-11-17 13:08:24 +01:00
|
|
|
screens.set(frontendDefinition.screens)
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
|
|
|
actions: { fetchScreens },
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-18 20:18:18 +01:00
|
|
|
export const screenStore = createScreenStore()
|