1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

Fix unrecoverable crash when the screen URL param is not a valid screen

This commit is contained in:
Andrew Kingston 2020-10-17 18:06:00 +01:00
parent 8e50aa152b
commit ee5b039c76

View file

@ -1,6 +1,6 @@
<script>
import { onMount } from "svelte"
import { params, leftover } from "@sveltech/routify"
import { params, leftover, goto } from "@sveltech/routify"
import { store } from "builderStore"
// Get any leftover params not caught by Routifys params store.
@ -8,17 +8,30 @@
// It's a screen, set it to that screen
if ($params.screen !== "page-layout") {
store.setCurrentScreen(decodeURI($params.screen))
const currentScreenName = decodeURI($params.screen)
const validScreen =
$store.screens.findIndex(
screen => screen.props._instanceName === currentScreenName
) !== -1
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it.
if ($leftover) {
// Get the correct screen children.
const screenChildren = $store.pages[$params.page]._screens.find(
screen =>
screen.props._instanceName === $params.screen ||
screen.props._instanceName === decodeURIComponent($params.screen)
).props._children
findComponent(componentIds, screenChildren)
if (!validScreen) {
// Go to main layout if URL set to invalid screen
store.setCurrentPage("main")
$goto("../../main")
} else {
// Otherwise proceed to set screen
store.setCurrentScreen(currentScreenName)
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it.
if ($leftover) {
// Get the correct screen children.
const screenChildren = $store.pages[$params.page]._screens.find(
screen =>
screen.props._instanceName === $params.screen ||
screen.props._instanceName === decodeURIComponent($params.screen)
).props._children
findComponent(componentIds, screenChildren)
}
}
} else {
// It's a page, so set the screentype to page.