-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add infinite scrolling * chore: ignore json callback data in code coverage
- Loading branch information
Showing
10 changed files
with
126 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<script setup> | ||
import AppLayout from '@/Layouts/AppLayout.vue'; | ||
import RecipeCard from "@/Components/RecipeCard.vue"; | ||
import {onMounted, ref, watch} from "vue"; | ||
import { useIntersectionObserver } from '@vueuse/core' | ||
const props = defineProps({ | ||
label: { | ||
type: [Array, Object], | ||
required: false, | ||
default() { | ||
return {}; | ||
}, | ||
}, | ||
recipes: { | ||
type: [Array, Object], | ||
required: false, | ||
default() { | ||
return []; | ||
}, | ||
}, | ||
}); | ||
watch(() => props.recipes, (data, prevData) => { | ||
paginationLink.value = data.recipes.next_cursor; | ||
recipeList.value = data.recipes; | ||
}); | ||
const paginationLink = ref(null); | ||
const recipeList = ref([]); | ||
const last = ref(null); | ||
const noMoreScrolling = ref(false); | ||
const isLoading = ref(false); | ||
onMounted(() => { | ||
paginationLink.value = props.recipes.next_page_url; | ||
}) | ||
useIntersectionObserver(last, ([{ isIntersecting }]) => { | ||
if (! isIntersecting) { | ||
return; | ||
} | ||
onLoadMore(); | ||
}) | ||
const onLoadMore = () => { | ||
if (noMoreScrolling.value) { | ||
return; | ||
} | ||
isLoading.value = true; | ||
axios.get(paginationLink.value).then((req) => { | ||
if (req.data.next_page_url === null) { | ||
noMoreScrolling.value = true; | ||
} | ||
recipeList.value = [...recipeList.value, ...req.data.data]; | ||
paginationLink.value = req.data.next_page_url; | ||
}).finally(() => { | ||
isLoading.value = false; | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<AppLayout :title="`${label.name} label`"> | ||
<div class="py-12"> | ||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8"> | ||
<h1 class="text-5xl text-surface-0 mb-10">{{ label.name }}</h1> | ||
<div class="grid sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10"> | ||
<transition-group name="fade"> | ||
<RecipeCard v-for="recipe in recipeList" :key="recipe.slug" :recipe="recipe"></RecipeCard> | ||
</transition-group> | ||
<RecipeCard v-if="isLoading" v-for="skeleton in 9" :skeleton="true"></RecipeCard> | ||
</div> | ||
<div ref="last" class="py-7"></div> | ||
</div> | ||
</div> | ||
</AppLayout> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.fade-enter-from, | ||
.fade-leave-to { | ||
opacity: 0; | ||
} | ||
.fade-enter-to, | ||
.fade-leave-from { | ||
opacity: 1; | ||
} | ||
.fade-enter-active, | ||
.fade-leave-active { | ||
transition: opacity 1s ease; | ||
} | ||
</style> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters