Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-1314: Fix slow Kanban open #3052

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 74 additions & 31 deletions packages/ui/src/components/Scroller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
export let buttons: boolean = false
export let shrink: boolean = false
export let divScroll: HTMLElement | undefined = undefined
export let checkForHeaders = false
export function scroll (top: number, left?: number, behavior: 'auto' | 'smooth' = 'auto') {
if (divScroll) {
Expand Down Expand Up @@ -89,22 +90,42 @@
const trackH = divScroll.clientHeight - shiftTop - shiftBottom - 4
const scrollH = divScroll.scrollHeight
const proc = scrollH / trackH
divBar.style.height = divScroll.clientHeight / proc + 'px'
divBar.style.top = divScroll.scrollTop / proc + shiftTop + 2 + 'px'
if (mask === 'none') divBar.style.visibility = 'hidden'
else {
divBar.style.visibility = 'visible'
const newHeight = divScroll.clientHeight / proc + 'px'
if (divBar.style.height !== 'newHeight') {
divBar.style.height = newHeight
}
const newTop = divScroll.scrollTop / proc + shiftTop + 2 + 'px'
if (divBar.style.top !== newTop) {
divBar.style.top = newTop
}
if (mask === 'none') {
if (divBar.style.visibility !== 'hidden') {
divBar.style.visibility = 'hidden'
}
} else {
if (divBar.style.visibility !== 'visible') {
divBar.style.visibility = 'visible'
}
if (divBar) {
if (timer) {
clearTimeout(timer)
divBar.style.opacity = '1'
if (divBar.style.opacity !== '1') {
divBar.style.opacity = '1'
}
}
timer = setTimeout(() => {
if (divBar) divBar.style.opacity = '0'
if (divBar) {
divBar.style.opacity = '0'
}
}, 1500)
}
}
if (divScroll.clientHeight >= divScroll.scrollHeight) divBar.style.visibility = 'hidden'
if (divScroll.clientHeight >= divScroll.scrollHeight) {
if (divBar.style.visibility !== 'hidden') {
divBar.style.visibility = 'hidden'
}
}
}
}
const checkBarH = (): void => {
Expand Down Expand Up @@ -220,6 +241,13 @@
}
}
let checkBarTimeout: any | undefined = undefined
const delayCall = (op: () => void) => {
clearTimeout(checkBarTimeout)
checkBarTimeout = setTimeout(op, 50)
}
const checkFade = (): void => {
if (divScroll) {
beforeContent = divScroll.scrollTop
Expand All @@ -240,8 +268,8 @@
if (inter.size) checkIntersectionFade()
renderFade()
}
if (!isScrolling) checkBar()
if (!isScrolling && horizontal) checkBarH()
if (!isScrolling) delayCall(checkBar)
if (!isScrolling && horizontal) delayCall(checkBarH)
}
function checkAutoScroll () {
Expand Down Expand Up @@ -336,8 +364,8 @@
if (divScroll && divBox) {
divScroll.addEventListener('wheel', wheelEvent)
divScroll.addEventListener('scroll', checkFade)
checkBar()
if (horizontal) checkBarH()
delayCall(checkBar)
if (horizontal) delayCall(checkBarH)
}
})
onDestroy(() => {
Expand All @@ -349,31 +377,46 @@
})
let oldTop: number
beforeUpdate(() => {
if (divBox && divScroll) oldTop = divScroll.scrollTop
})
afterUpdate(() => {
if (divBox && divScroll) {
if (oldTop !== divScroll.scrollTop) divScroll.scrollTop = oldTop
const tempEls = divBox.querySelectorAll('.categoryHeader')
observer = new IntersectionObserver(checkIntersection, { root: null, rootMargin: '0px', threshold: 0.1 })
tempEls.forEach((el) => observer.observe(el))
const tempCats = divBox.querySelectorAll('.lastCat')
if (tempCats.length > 0) {
hasLastCategories = true
tempCats.forEach((el) => observer.observe(el))
} else hasLastCategories = false
}
})
if (checkForHeaders) {
beforeUpdate(() => {
if (divBox && divScroll) {
oldTop = divScroll.scrollTop
}
})
afterUpdate(() => {
if (divBox && divScroll) {
if (oldTop !== divScroll.scrollTop) {
divScroll.scrollTop = oldTop
}
delayCall(() => {
const tempEls = divBox.querySelectorAll('.categoryHeader')
observer = new IntersectionObserver(checkIntersection, { root: null, rootMargin: '0px', threshold: 0.1 })
tempEls.forEach((el) => observer.observe(el))
const tempCats = divBox.querySelectorAll('.lastCat')
if (tempCats.length > 0) {
hasLastCategories = true
tempCats.forEach((el) => observer.observe(el))
} else {
hasLastCategories = false
}
})
}
})
}
let divHeight: number
const _resize = (): void => checkFade()
const tapScroll = (n: number, dir: 'up' | 'down') => {
if (divScroll) {
if (orientir === 'horizontal') divScroll.scrollBy({ top: 0, left: dir === 'up' ? -n : n, behavior: 'smooth' })
else divScroll.scrollBy({ top: dir === 'up' ? -n : n, left: 0, behavior: 'smooth' })
if (orientir === 'horizontal') {
divScroll.scrollBy({ top: 0, left: dir === 'up' ? -n : n, behavior: 'smooth' })
} else {
divScroll.scrollBy({ top: dir === 'up' ? -n : n, left: 0, behavior: 'smooth' })
}
}
}
</script>
Expand Down
7 changes: 6 additions & 1 deletion plugins/view-resources/src/components/list/ListView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
/>

<div class="w-full h-full py-4 clear-mins">
<Scroller fade={{ multipler: { top: 2.75 * viewOptions.groupBy.length, bottom: 0 } }} padding={'0 1rem'} noFade>
<Scroller
fade={{ multipler: { top: 2.75 * viewOptions.groupBy.length, bottom: 0 } }}
padding={'0 1rem'}
noFade
checkForHeaders
>
<List
bind:this={list}
{_class}
Expand Down