Extract id from pathname correctly

This commit is contained in:
Misode
2020-06-03 22:59:37 +02:00
parent 65eac13082
commit 3f5ca2177d

View File

@@ -21,8 +21,10 @@ const models: {
'sandbox': new DataModel(SandboxSchema)
}
const modelFromPath = (p: string) => p.split('/').filter(e => e.length !== 0).pop() ?? ''
const modelSelector = (document.getElementById('model-selector') as HTMLInputElement)
const defaultModel = location.pathname.replace(/^\//, '')
const defaultModel = modelFromPath(location.pathname)
let model = models[defaultModel]
const treeViewEl = document.getElementById('tree-view')!
@@ -58,8 +60,7 @@ modelSelector.addEventListener('change', evt => {
})
window.onpopstate = (evt: PopStateEvent) => {
const newModel = location.pathname.replace(/^\//, '')
updateModel(newModel)
updateModel(modelFromPath(location.pathname))
}
const sourceControlsToggle = document.getElementById('source-controls-toggle')!