1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +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 67e8490eac
commit fbe15ccfd9

View file

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