Skip to content
Snippets Groups Projects
Commit 928412da authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: fix infinite load cycle in image browser

The image loader did not check if it reached the end of the result set
and just kept increasing the page number, spamming steering with
requests.
parent 3e08827f
No related branches found
No related tags found
No related merge requests found
...@@ -21,23 +21,24 @@ import { ref, useAttrs } from 'vue' ...@@ -21,23 +21,24 @@ import { ref, useAttrs } from 'vue'
import Loading from './Loading.vue' import Loading from './Loading.vue'
const props = defineProps<{ const props = defineProps<{
loadMore: () => void | Promise<void> loadMore: () => Promise<boolean>
}>() }>()
const attrs = useAttrs() const attrs = useAttrs()
const scroller = ref<HTMLOListElement>() const scroller = ref<HTMLOListElement>()
const isLoading = ref(false) const isLoading = ref(false)
const canLoadMore = ref(true)
async function loadMoreData() { async function loadMoreData() {
isLoading.value = true isLoading.value = true
try { try {
await props.loadMore() canLoadMore.value = await props.loadMore()
} finally { } finally {
isLoading.value = false isLoading.value = false
} }
} }
loadMoreData() loadMoreData()
useInfiniteScroll(scroller, loadMoreData) useInfiniteScroll(scroller, loadMoreData, { canLoadMore: () => canLoadMore.value })
</script> </script>
<script lang="ts"> <script lang="ts">
......
...@@ -28,8 +28,9 @@ const emit = defineEmits<{ ...@@ -28,8 +28,9 @@ const emit = defineEmits<{
const imageStore = useImageStore() const imageStore = useImageStore()
function loadMore() { async function loadMore() {
imageStore.list(imageStore.count === 0 ? 1 : imageStore.currentPage + 1) const result = await imageStore.list(imageStore.count === 0 ? 1 : imageStore.currentPage + 1)
return result.length > 0
} }
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment