Generalize goToMessage

This commit is contained in:
Jon Staab
2025-06-05 10:55:16 -07:00
parent d8b87db784
commit 8e28ff13e9
4 changed files with 97 additions and 85 deletions
+8 -2
View File
@@ -100,7 +100,7 @@ export const isIntersecting = async (element: Element) =>
observer.observe(element)
})
export const scrollToEvent = async (id: string) => {
export const scrollToEvent = async (id: string, attempts = 3): Promise<boolean> => {
const element = document.querySelector(`[data-event="${id}"]`) as any
if (element) {
@@ -114,6 +114,8 @@ export const scrollToEvent = async (id: string) => {
setTimeout(() => {
element.style = ""
}, 800 + 400)
return true
} else {
const lastElement = last(Array.from(document.querySelectorAll("[data-event]")))
@@ -123,6 +125,10 @@ export const scrollToEvent = async (id: string) => {
await sleep(300)
scrollToEvent(id)
if (attempts > 0) {
return scrollToEvent(id, attempts - 1)
} else {
return false
}
}
}