Compare commits

...

2 Commits

Author SHA1 Message Date
pythongosssss
02c13c403f Safety mechanism to prevent loading everything 2024-11-24 11:44:26 +00:00
pythongosssss
8254e3c9cf Fix number of items shown when loading more
Fix number of items shown on status update
2024-11-24 11:37:02 +00:00

View File

@@ -163,6 +163,7 @@ const outputFilterPopup = ref(null)
const ITEMS_PER_PAGE = 8 const ITEMS_PER_PAGE = 8
const SCROLL_THRESHOLD = 100 // pixels from bottom to trigger load const SCROLL_THRESHOLD = 100 // pixels from bottom to trigger load
const MAX_LOAD_ITERATIONS = 10
const allTasks = computed(() => const allTasks = computed(() =>
isInFolderView.value isInFolderView.value
@@ -181,42 +182,47 @@ const allGalleryItems = computed(() =>
) )
const filterTasks = (tasks: TaskItemImpl[]) => const filterTasks = (tasks: TaskItemImpl[]) =>
tasks tasks.filter((t) => {
.filter((t) => { if (
if ( hideCanceled.value &&
hideCanceled.value && t.status?.messages?.at(-1)?.[0] === 'execution_interrupted'
t.status?.messages?.at(-1)?.[0] === 'execution_interrupted' ) {
) { return false
return false }
}
if ( if (
hideCached.value && hideCached.value &&
t.flatOutputs?.length && t.flatOutputs?.length &&
t.flatOutputs.every((o) => o.cached) t.flatOutputs.every((o) => o.cached)
) { ) {
return false return false
} }
return true return true
}) })
.slice(0, ITEMS_PER_PAGE)
const loadMoreItems = () => { const loadMoreItems = (iteration: number) => {
const currentLength = visibleTasks.value.length const currentLength = visibleTasks.value.length
const newTasks = filterTasks(allTasks.value).slice( const newTasks = filterTasks(allTasks.value).slice(
currentLength, currentLength,
currentLength + ITEMS_PER_PAGE currentLength + ITEMS_PER_PAGE
) )
visibleTasks.value.push(...newTasks) visibleTasks.value.push(...newTasks)
// If we've added some items, check if we need to add more
// Prevent loading everything at once in case of render update issues
if (newTasks.length && iteration < MAX_LOAD_ITERATIONS) {
nextTick(() => {
checkAndLoadMore(iteration + 1)
})
}
} }
const checkAndLoadMore = () => { const checkAndLoadMore = (iteration: number) => {
if (!scrollContainer.value) return if (!scrollContainer.value) return
const { scrollHeight, scrollTop, clientHeight } = scrollContainer.value const { scrollHeight, scrollTop, clientHeight } = scrollContainer.value
if (scrollHeight - scrollTop - clientHeight < SCROLL_THRESHOLD) { if (scrollHeight - scrollTop - clientHeight < SCROLL_THRESHOLD) {
loadMoreItems() loadMoreItems(iteration)
} }
} }
@@ -224,7 +230,7 @@ useInfiniteScroll(
scrollContainer, scrollContainer,
() => { () => {
if (visibleTasks.value.length < allTasks.value.length) { if (visibleTasks.value.length < allTasks.value.length) {
loadMoreItems() loadMoreItems(0)
} }
}, },
{ distance: SCROLL_THRESHOLD } { distance: SCROLL_THRESHOLD }
@@ -234,12 +240,16 @@ useInfiniteScroll(
// This is necessary as the sidebar tab can change size when user drags the splitter. // This is necessary as the sidebar tab can change size when user drags the splitter.
useResizeObserver(scrollContainer, () => { useResizeObserver(scrollContainer, () => {
nextTick(() => { nextTick(() => {
checkAndLoadMore() checkAndLoadMore(0)
}) })
}) })
const updateVisibleTasks = () => { const updateVisibleTasks = () => {
visibleTasks.value = filterTasks(allTasks.value) visibleTasks.value = filterTasks(allTasks.value).slice(0, ITEMS_PER_PAGE)
nextTick(() => {
checkAndLoadMore(0)
})
} }
const toggleExpanded = () => { const toggleExpanded = () => {