1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

Hide new component panel when selected component changes

This commit is contained in:
Andrew Kingston 2022-10-17 09:23:52 +01:00
parent da3202f3c3
commit df589bc415
2 changed files with 23 additions and 0 deletions

View file

@ -10,6 +10,7 @@ export const syncURLToState = options => {
fallbackUrl,
store,
routify,
beforeNavigate,
} = options || {}
if (
!urlParam ||
@ -41,6 +42,15 @@ export const syncURLToState = options => {
// Navigate to a certain URL
const gotoUrl = (url, params) => {
if (beforeNavigate) {
const res = beforeNavigate(url, params)
if (res?.url) {
url = res.url
}
if (res?.params) {
params = res.params
}
}
log("Navigating to", url, "with params", params)
cachedGoto(url, params)
}

View file

@ -7,6 +7,18 @@
import ComponentListPanel from "./_components/navigation/ComponentListPanel.svelte"
import ComponentSettingsPanel from "./_components/settings/ComponentSettingsPanel.svelte"
const cleanUrl = url => {
// Strip trailing slashes
if (url?.endsWith("/index")) {
url = url.replace("/index", "")
}
// Hide new component panel whenever component ID changes
if (url?.endsWith("/new")) {
url = url.replace("/new", "")
}
return { url }
}
// Keep URL and state in sync for selected component ID
const stopSyncing = syncURLToState({
urlParam: "componentId",
@ -15,6 +27,7 @@
fallbackUrl: "../",
store,
routify,
beforeNavigate: cleanUrl,
})
onDestroy(stopSyncing)