feat(spa): add loading bar (#1684)
This commit is contained in:
parent
05e6f05a50
commit
c91cf97f99
2 changed files with 26 additions and 0 deletions
quartz
|
@ -42,8 +42,22 @@ function notifyNav(url: FullSlug) {
|
||||||
const cleanupFns: Set<(...args: any[]) => void> = new Set()
|
const cleanupFns: Set<(...args: any[]) => void> = new Set()
|
||||||
window.addCleanup = (fn) => cleanupFns.add(fn)
|
window.addCleanup = (fn) => cleanupFns.add(fn)
|
||||||
|
|
||||||
|
function startLoading() {
|
||||||
|
const loadingBar = document.createElement("div")
|
||||||
|
loadingBar.className = "navigation-progress"
|
||||||
|
loadingBar.style.width = "0"
|
||||||
|
if (!document.body.contains(loadingBar)) {
|
||||||
|
document.body.appendChild(loadingBar)
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
loadingBar.style.width = "80%"
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
|
||||||
let p: DOMParser
|
let p: DOMParser
|
||||||
async function navigate(url: URL, isBack: boolean = false) {
|
async function navigate(url: URL, isBack: boolean = false) {
|
||||||
|
startLoading()
|
||||||
p = p || new DOMParser()
|
p = p || new DOMParser()
|
||||||
const contents = await fetch(`${url}`)
|
const contents = await fetch(`${url}`)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
@ -104,6 +118,7 @@ async function navigate(url: URL, isBack: boolean = false) {
|
||||||
if (!isBack) {
|
if (!isBack) {
|
||||||
history.pushState({}, "", url)
|
history.pushState({}, "", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyNav(getFullSlug(window))
|
notifyNav(getFullSlug(window))
|
||||||
delete announcer.dataset.persist
|
delete announcer.dataset.persist
|
||||||
}
|
}
|
||||||
|
|
|
@ -587,3 +587,14 @@ iframe.pdf {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navigation-progress {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 3px;
|
||||||
|
background: var(--secondary);
|
||||||
|
transition: width 0.2s ease;
|
||||||
|
z-index: 9999;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue