Skip to content

Commit

Permalink
load more on videos in ready
Browse files Browse the repository at this point in the history
  • Loading branch information
yussan committed Feb 8, 2024
1 parent cb150e8 commit 2335e85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 10 additions & 2 deletions components/templates/PostLists/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
outline
color="purple"
/>
</div></div
></DefaultLayout>
</div>
</div>

<p
v-if="postData.status && postData.status !== 200"
class="text-center text-grey"
>
{{ postData?.message || "Post Not Available" }}
</p>
</DefaultLayout>
</template>

<script setup>
Expand Down
23 changes: 17 additions & 6 deletions components/templates/VideoLists/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<TitleMedium :title="metaData.title" />
<BoxVideos :size="'large'" :data="videoData" :loading="isLoading" />
<div
v-if="!isLoading && videoData?.result?.length"
v-if="
!isLoading && videoData?.result?.length && videoData?.status === 200
"
class="col-12 q-pa-lg text-center"
>
<q-btn
Expand All @@ -15,6 +17,12 @@
color="purple"
/>
</div>
<p
v-if="videoData.status && videoData.status !== 200"
class="text-center text-grey"
>
{{ videoData?.message || "Video Not Available" }}
</p>
</DefaultLayout>
</template>

Expand Down Expand Up @@ -59,11 +67,12 @@ const metaData = computed({
// initiate functions
const fetchData = async (nextQuery) => {
isLoading.value = true;
const query = { ...nextQuery, ...DEFAULT_QUERY };
// if (query.page !== 0) query.page = DEFAULT_QUERY.limit * (query.page - 1);
const response = await fetchVideos({ query });
if (!query.lastupdatedon) {
if (!query.lastcreatedat) {
videoData.value = response;
} else {
//do loadmore
Expand All @@ -74,13 +83,15 @@ const fetchData = async (nextQuery) => {
videoData.value.result = [...videoData.value.result, ...response.result];
}
}
isLoading.value = false;
};
const fetchLoadMore = async () => {
isLoading.value = true;
setTimeout(() => {
isLoading.value = false;
}, 2000);
const nextQuery = {};
nextQuery.lastcreatedat =
videoData.value.result[videoData.value.result.length - 1].createdAt;
return fetchData(nextQuery);
};
// onMounted
Expand Down

0 comments on commit 2335e85

Please sign in to comment.