Frontend: added infinite scrolling to posts

main
TZGyn 2 years ago
parent ee097ca153
commit 3849643f7d
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -6,9 +6,12 @@ definePageMeta({
const posts = usePosts() const posts = usePosts()
const openCreatePostModal = ref<Boolean>(false) const openCreatePostModal = ref<Boolean>(false)
const pageType = ref<'following' | 'for you'>('for you') const pageType = ref<'following' | 'for you'>('for you')
const isLoading = ref<Boolean>(false)
const getPosts = async () => { const getPosts = async (order?: 'new' | 'old') => {
await fetchPosts() isLoading.value = true
await fetchPosts(order)
isLoading.value = false
} }
const toggleCreatePostModal = () => { const toggleCreatePostModal = () => {
@ -24,13 +27,26 @@ const createPost = () => {
// toggleCreatePostModal() // toggleCreatePostModal()
} }
const postsView = ref<HTMLElement | null>(null)
useInfiniteScroll(
postsView,
() => {
getPosts()
},
{
distance: 0,
interval: 7000,
}
)
onMounted(() => { onMounted(() => {
getPosts() getPosts()
}) })
</script> </script>
<template> <template>
<div> <div class="h-screen overflow-hidden">
<Header /> <Header />
<div class="sticky top-0 flex bg-primary text-center"> <div class="sticky top-0 flex bg-primary text-center">
<div <div
@ -72,14 +88,20 @@ onMounted(() => {
</div> </div>
</div> </div>
</div> </div>
<div class="mb-16 flex w-full items-center justify-center"> <div class="flex w-full items-center justify-center">
<div class="flex w-full max-w-2xl flex-col"> <div
<div ref="postsView"
v-if="posts" class="flex h-screen w-full max-w-2xl flex-col items-center overflow-scroll pb-48">
v-for="post in posts"> <PostCard
<PostCard :post="post" /> v-for="post in posts"
:post="post" />
<div class="mt-4">
<Icon
v-if="isLoading"
name="loading"
size="32"
class="text-accent" />
</div> </div>
<button @click="getPosts()">More</button>
</div> </div>
</div> </div>
<button <button
@ -93,3 +115,16 @@ onMounted(() => {
<BottomNavigationBar /> <BottomNavigationBar />
</div> </div>
</template> </template>
<style>
/* Hide scrollbar for Chrome, Safari and Opera */
.scrollbar-hidden::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.scrollbar-hidden {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
</style>

Loading…
Cancel
Save