Improve route handling when creating new components and screens
This commit is contained in:
parent
f72f3f88f7
commit
607a36e2e4
|
@ -67,7 +67,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$goto(`./${screenId}`)
|
// Select and go to new screen
|
||||||
|
store.actions.screens.select(screenId)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
notifications.error("Error creating screens")
|
notifications.error("Error creating screens")
|
||||||
|
|
|
@ -56,6 +56,11 @@ export const syncURLToState = options => {
|
||||||
|
|
||||||
// Navigate to a certain URL
|
// Navigate to a certain URL
|
||||||
const gotoUrl = (url, params) => {
|
const gotoUrl = (url, params) => {
|
||||||
|
// Clean URL
|
||||||
|
if (url?.endsWith("/index")) {
|
||||||
|
url = url.replace("/index", "")
|
||||||
|
}
|
||||||
|
// Allow custom URL handling
|
||||||
if (beforeNavigate) {
|
if (beforeNavigate) {
|
||||||
const res = beforeNavigate(url, params)
|
const res = beforeNavigate(url, params)
|
||||||
if (res?.url) {
|
if (res?.url) {
|
||||||
|
@ -65,10 +70,6 @@ export const syncURLToState = options => {
|
||||||
params = res.params
|
params = res.params
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clean URL
|
|
||||||
if (url?.endsWith("/index")) {
|
|
||||||
url = url.replace("/index", "")
|
|
||||||
}
|
|
||||||
log("Navigating to", url, "with params", params)
|
log("Navigating to", url, "with params", params)
|
||||||
cachedGoto(url, params)
|
cachedGoto(url, params)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<script>
|
<script>
|
||||||
import ScreenList from "./ScreenList/index.svelte"
|
import ScreenList from "./ScreenList/index.svelte"
|
||||||
import ComponentList from "./ComponentList/index.svelte"
|
import ComponentList from "./ComponentList/index.svelte"
|
||||||
import { isActive } from "@roxi/routify"
|
import { selectedScreen } from "builderStore"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<ScreenList />
|
<ScreenList />
|
||||||
{#if $isActive("./:componentId")}
|
{#if $selectedScreen}
|
||||||
<ComponentList />
|
<ComponentList />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
import DropdownMenu from "./DropdownMenu.svelte"
|
import DropdownMenu from "./DropdownMenu.svelte"
|
||||||
import NewScreen from "components/design/NewScreen/index.svelte"
|
import NewScreen from "components/design/NewScreen/index.svelte"
|
||||||
import { onMount, tick } from "svelte"
|
import { onMount, tick } from "svelte"
|
||||||
|
import { beforeUrlChange } from "@roxi/routify"
|
||||||
|
|
||||||
let newScreen = false
|
let newScreen = false
|
||||||
let search = false
|
let search = false
|
||||||
|
@ -25,6 +26,14 @@
|
||||||
|
|
||||||
$: filteredScreens = getFilteredScreens($sortedScreens, searchValue)
|
$: filteredScreens = getFilteredScreens($sortedScreens, searchValue)
|
||||||
|
|
||||||
|
// Close new screen when URL changes
|
||||||
|
$beforeUrlChange(() => {
|
||||||
|
if (newScreen) {
|
||||||
|
newScreen = false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
|
||||||
const openSearch = async () => {
|
const openSearch = async () => {
|
||||||
|
@ -176,7 +185,12 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="newScreen" class:newScreenVisible={newScreen}>
|
<div class="newScreen" class:newScreenVisible={newScreen}>
|
||||||
<NewScreen onClose={() => (newScreen = false)} />
|
<NewScreen
|
||||||
|
onClose={() => {
|
||||||
|
console.log("close")
|
||||||
|
newScreen = false
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
Loading…
Reference in New Issue