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

View File

@ -7,6 +7,18 @@
import ComponentListPanel from "./_components/navigation/ComponentListPanel.svelte" import ComponentListPanel from "./_components/navigation/ComponentListPanel.svelte"
import ComponentSettingsPanel from "./_components/settings/ComponentSettingsPanel.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 // Keep URL and state in sync for selected component ID
const stopSyncing = syncURLToState({ const stopSyncing = syncURLToState({
urlParam: "componentId", urlParam: "componentId",
@ -15,6 +27,7 @@
fallbackUrl: "../", fallbackUrl: "../",
store, store,
routify, routify,
beforeNavigate: cleanUrl,
}) })
onDestroy(stopSyncing) onDestroy(stopSyncing)