Hide new component panel when selected component changes
This commit is contained in:
parent
682203fbda
commit
ceecfb50e9
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue