From 35503601f3c5317bf2f2725b5ce29eb9a86264f6 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 10 Apr 2021 12:33:44 +0200 Subject: [PATCH] :bug: (focus) wait 100 for first stacked note --- src/hooks/useFocus.hook.ts | 6 ++++-- src/hooks/useOverlay.hook.ts | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/hooks/useFocus.hook.ts b/src/hooks/useFocus.hook.ts index fccea04..8973723 100644 --- a/src/hooks/useFocus.hook.ts +++ b/src/hooks/useFocus.hook.ts @@ -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) } }) } diff --git a/src/hooks/useOverlay.hook.ts b/src/hooks/useOverlay.hook.ts index 520f3a6..cdea123 100644 --- a/src/hooks/useOverlay.hook.ts +++ b/src/hooks/useOverlay.hook.ts @@ -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() } }