2021-06-30 21:35:02 +02:00
|
|
|
import { derived } from "svelte/store"
|
2020-11-17 13:08:24 +01:00
|
|
|
import { routeStore } from "./routes"
|
2020-11-24 10:31:54 +01:00
|
|
|
import { builderStore } from "./builder"
|
2021-06-30 21:35:02 +02:00
|
|
|
import { appStore } from "./app"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-18 20:18:18 +01:00
|
|
|
const createScreenStore = () => {
|
2020-11-24 10:31:54 +01:00
|
|
|
const store = derived(
|
2021-06-30 21:35:02 +02:00
|
|
|
[appStore, routeStore, builderStore],
|
|
|
|
([$appStore, $routeStore, $builderStore]) => {
|
2020-11-27 17:36:31 +01:00
|
|
|
let activeLayout
|
2020-11-24 10:31:54 +01:00
|
|
|
let activeScreen
|
|
|
|
if ($builderStore.inBuilder) {
|
|
|
|
// Use builder defined definitions if inside the builder preview
|
2020-11-27 17:36:31 +01:00
|
|
|
activeLayout = $builderStore.layout
|
2020-11-24 10:31:54 +01:00
|
|
|
activeScreen = $builderStore.screen
|
|
|
|
} else {
|
2021-05-20 15:47:17 +02:00
|
|
|
activeLayout = { props: { _component: "screenslot" } }
|
|
|
|
|
|
|
|
// Find the correct screen by matching the current route
|
2021-06-30 21:35:02 +02:00
|
|
|
const { screens, layouts } = $appStore
|
2021-05-20 15:47:17 +02:00
|
|
|
if ($routeStore.activeRoute) {
|
2020-12-04 15:04:07 +01:00
|
|
|
activeScreen = screens.find(
|
2021-05-04 12:32:22 +02:00
|
|
|
screen => screen._id === $routeStore.activeRoute.screenId
|
2020-12-04 15:04:07 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
if (activeScreen) {
|
|
|
|
activeLayout = layouts.find(
|
2021-05-04 12:32:22 +02:00
|
|
|
layout => layout._id === activeScreen.layoutId
|
2020-12-04 15:04:07 +01:00
|
|
|
)
|
|
|
|
}
|
2020-11-24 10:31:54 +01:00
|
|
|
}
|
2020-11-27 17:36:31 +01:00
|
|
|
return { activeLayout, activeScreen }
|
2020-11-17 13:08:24 +01:00
|
|
|
}
|
2020-11-24 10:31:54 +01:00
|
|
|
)
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
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()
|