🐛 (focus) wait 100 for first stacked note

This commit is contained in:
2021-04-10 12:33:44 +02:00
parent 896d0233c5
commit 35503601f3
2 changed files with 22 additions and 10 deletions

View File

@@ -22,13 +22,15 @@ export const useFocus = () => {
nextTick(() => {
const index = stackedNotes.value.findIndex((noteSHA) => noteSHA === sha)
const hasOneStackedNote = stackedNotes.value.length === 1
if (isMobile.value) {
const element = document.querySelector(`.note-${sha}`) as HTMLElement
const top = (index + 1) * (element?.clientHeight ?? height.value)
scrollToNote(top)
scrollToNote(top, hasOneStackedNote)
} else {
const left = (index + 1) * NOTE_WIDTH
scrollToNote(left)
scrollToNote(left, hasOneStackedNote)
}
})
}

View File

@@ -25,15 +25,25 @@ export const useOverlay = (listen = true) => {
)
}
const scrollToNote = (to: number) => {
if (isMobile.value) {
body.scroll({
top: to
})
const scrollToNote = (to: number, wait = false) => {
const go = () => {
if (isMobile.value) {
body.scroll({
top: to
})
} else {
body.scroll({
left: to
})
}
}
if (wait) {
setTimeout(() => {
go()
}, 100)
} else {
body.scroll({
left: to
})
go()
}
}