Rewire operation/tag DOM ids; implement hash scroll-to

This commit is contained in:
Kyle Shockey
2017-07-14 00:41:22 -07:00
parent 79f91b2e3e
commit 41ecceed87
3 changed files with 48 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
import scrollTo from "scroll-to-element"
const SCROLL_OFFSET = -5
let hasHashBeenParsed = false
export const updateResolved = (ori, { layoutActions }) => (...args) => {
ori(...args)
if(window.location.hash && !hasHashBeenParsed ) {
let hash = window.location.hash.slice(1) // # is first character
if(hash[0] === "!") {
// Parse UI 2.x shebangs
hash = hash.slice(1)
}
if(hash[0] === "/") {
// "/pet/addPet" => "pet/addPet"
// makes the split result cleaner
// also handles forgotten leading slash
hash = hash.slice(1)
}
let [tag, operationId] = hash.split("/")
if(tag && operationId) {
// Pre-expand and scroll to the operation
scrollTo(`#operations-${tag}-${operationId}`, {
offset: SCROLL_OFFSET
})
layoutActions.show(["operations", tag, operationId], true)
} else if(tag) {
// Pre-expand and scroll to the tag
scrollTo(`#operations-tag-${tag}`, {
offset: SCROLL_OFFSET
})
layoutActions.show(["operations-tag", tag], true)
}
}
hasHashBeenParsed = true
}