Skip to content

Commit

Permalink
fix: use correct item threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Jan 29, 2024
1 parent 0c93abc commit c49bfe9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/lib/components/InfiniteScroll.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
const localCtx = ++ctx;
const items = await load(index++);
if (items.length < itemThreshold) {
done = true;
}
if (localCtx !== ctx) {
return;
}
if (items.length < itemThreshold) {
done = true;
}
if (items.length) {
data.push(...items);
data = data;
Expand All @@ -38,9 +38,22 @@
});
}
function onLoadChange() {
data = [];
done = false;
index = 0;
next();
}
$: if (shouldLoad && !loading && !done) {
next();
}
$: {
load;
onLoadChange();
}
</script>

{#each data as item, i (i)}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/recipe/RecipeGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| undefined = undefined;
export let placeholderItems = 10;
export let itemThreshold = 0;
export let itemThreshold = 1;
const sizes: Record<Size, string> = {
sm: '15rem',
Expand Down

0 comments on commit c49bfe9

Please sign in to comment.