0
0
Fork 0

fix: hasMoreData

This commit is contained in:
Alex Moreno 2024-04-19 14:43:38 +02:00
parent c638209f0e
commit ae2737673d
1 changed files with 7 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<script setup>
import { onMounted, ref, watch, computed } from 'vue';
import { onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useArrayData } from 'composables/useArrayData';
@ -77,7 +77,6 @@ const arrayData = useArrayData(props.dataKey, {
userParams: props.userParams,
exprBuilder: props.exprBuilder,
});
const hasMoreData = computed(() => arrayData.hasMoreData);
const store = arrayData.store;
onMounted(() => {
@ -97,7 +96,7 @@ const addFilter = async (filter, params) => {
async function fetch() {
await arrayData.fetch({ append: false });
if (!hasMoreData.value) {
if (!arrayData.hasMoreData.value) {
isLoading.value = false;
}
emit('onFetch', store.data);
@ -110,8 +109,8 @@ async function paginate() {
isLoading.value = true;
await arrayData.loadMore();
if (!hasMoreData.value) {
if (store.userParamsChanged) hasMoreData.value = true;
if (!arrayData.hasMoreData.value) {
if (store.userParamsChanged) arrayData.hasMoreData.value = true;
store.userParamsChanged = false;
endPagination();
return;
@ -142,7 +141,7 @@ async function onLoad(index, done) {
await paginate();
let isDone = false;
if (store.userParamsChanged) isDone = !hasMoreData.value;
if (store.userParamsChanged) isDone = !arrayData.hasMoreData.value;
done(isDone);
}
@ -187,7 +186,7 @@ defineExpose({ fetch, addFilter });
v-if="store.data"
@load="onLoad"
:offset="offset"
:disable="disableInfiniteScroll || !hasMoreData.value"
:disable="disableInfiniteScroll || !arrayData.hasMoreData.value"
class="full-width"
v-bind="$attrs"
>
@ -197,7 +196,7 @@ defineExpose({ fetch, addFilter });
</div>
</QInfiniteScroll>
<div
v-if="!isLoading && hasMoreData.value"
v-if="!isLoading && arrayData.hasMoreData.value"
class="w-full flex justify-center q-mt-md"
>
<QBtn color="primary" :label="t('Load more data')" @click="paginate()" />