0
0
Fork 0

refs #6704: fix bug

This commit is contained in:
Javier Segarra 2024-01-16 11:24:28 +01:00
parent 9daffdfa22
commit b58f9bee2e
4 changed files with 53 additions and 13 deletions

View File

@ -79,6 +79,7 @@ async function search() {
isLoading.value = true;
const params = { ...userParams.value };
store.pagination = true;
store.userParamsChanged = true;
store.filter.skip = 0;
store.skip = 0;
const { params: newParams } = await arrayData.addFilter({ params });
@ -87,6 +88,8 @@ async function search() {
if (!props.showAll && !Object.values(params).length) store.data = [];
isLoading.value = false;
// store.pagination = false;
emit('search');
}
async function remove(key) {
@ -96,10 +99,11 @@ async function remove(key) {
}
async function clearFilters() {
isLoading.value = true;
store.userParamsChanged = true;
// Filtrar los params no removibles
const removableFilters = Object.keys(userParams.value).filter((param) =>
props.unremovableParams.includes(param)
props.unremovableParams.includes(param)
);
const newParams = {};
// Conservar solo los params que no son removibles

View File

@ -1,5 +1,12 @@
<script setup>
import { onMounted, ref, watch, onUnmounted } from 'vue';
import {
onMounted,
ref,
watch,
onUnmounted,
onRenderTriggered,
onRenderTracked,
} from 'vue';
import { useI18n } from 'vue-i18n';
import { useArrayData } from 'composables/useArrayData';
import { useRoute } from 'vue-router';
@ -57,7 +64,7 @@ const props = defineProps({
default: null,
},
});
const infiniteScrollRef = ref();
const emit = defineEmits(['onFetch', 'onPaginate']);
defineExpose({ fetch });
const isLoading = ref(false);
@ -82,12 +89,19 @@ onMounted(() => {
if (props.autoLoad) fetch();
});
watch(()=>[props.data, store],
// onRenderTracked((e)=>{
// console.log(e)
// });
// onRenderTracked((e)=>{
// console.log(e)
// });
watch(
() => [props.data, store],
() => {
// store.skip = 0;
store.data = props.data;
if(store.pagination)
paginate()
if (store.pagination) paginate();
}
);
@ -115,9 +129,14 @@ async function paginate() {
if (!props.url) return;
isLoading.value = true;
// infiniteScrollRef.value.resume()
await arrayData.loadMore();
if (!arrayData.hasMoreData.value) {
// infiniteScrollRef.value.resume()
if (store.userParamsChanged) arrayData.hasMoreData.value = true;
store.userParamsChanged = false;
isLoading.value = false;
return;
}
@ -135,6 +154,7 @@ async function paginate() {
}
async function onLoad(...params) {
console.log('ENTRA');
if (!store.data) return;
const done = params[1];
@ -143,9 +163,16 @@ async function onLoad(...params) {
pagination.value.page = pagination.value.page + 1;
await paginate();
let isDone = false;
if (store.userParamsChanged) isDone = !arrayData.hasMoreData.value;
// console.error('isDone', isDone);
// if(isDone){
// // infiniteScrollRef.value.trigger()
// console.error('VnPaginate', isDone, arrayData.store.pagination)
const endOfPages = !arrayData.hasMoreData.value;
done(endOfPages);
// }
// done(false);
done(isDone);
}
</script>
@ -183,6 +210,7 @@ async function onLoad(...params) {
</div>
</div>
<QInfiniteScroll
ref="infiniteScrollRef"
v-if="store.data"
@load="onLoad"
:offset="offset"

View File

@ -98,11 +98,17 @@ export function useArrayData(key, userOptions) {
const { limit } = filter;
hasMoreData.value = response.data.length === limit;
if (store.pagination) {
// await loadMore();
store.pagination = false;
/*if (Object.keys(store.userParams).length > 0) {
hasMoreData.value = true;
} else if(store.userParamsChanged){
hasMoreData.value = false;
}
else */hasMoreData.value = response.data.length === limit;
// if (store.pagination) {
// console.error('Before-ArrayData', store.pagination, hasMoreData.value)
// hasMoreData.value = true;
// console.error('After-ArrayData', store.pagination, hasMoreData.value)
// }
if (append) {
if (!store.data) store.data = [];
for (const row of response.data) store.data.push(row);
@ -182,6 +188,7 @@ export function useArrayData(key, userOptions) {
async function loadMore() {
if (!hasMoreData.value) return;
console.error('loadMore', hasMoreData.value);
store.skip = store.limit * page.value;
page.value += 1;
@ -200,7 +207,7 @@ export function useArrayData(key, userOptions) {
if (store.skip) query.skip = store.skip;
if (store.userParams && Object.keys(store.userParams).length !== 0)
query.params = JSON.stringify(store.userParams);
// hasMoreData.value = true;
if (router)
router.replace({
path: route.path,

View File

@ -21,6 +21,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
isLoading: false,
loadMore: false,
pagination: false,
userParamsChanged: true,
exprBuilder: null,
};
}