From bd904ad82a736d7f00a58b5cb0346e628b635310 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 15 Feb 2023 15:51:31 +0100 Subject: [PATCH] Paginate initial load fix --- src/components/PaginateData.vue | 13 ++++++-- src/components/ui/VnFilterPanel.vue | 2 +- src/components/ui/VnSearchbar.vue | 44 ++++++++++++++++++---------- src/composables/useArrayData.js | 12 ++++++-- src/pages/Ticket/Card/TicketCard.vue | 7 ++++- src/pages/Ticket/TicketList.vue | 2 +- 6 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/components/PaginateData.vue b/src/components/PaginateData.vue index fb0549f38..88f2157ca 100644 --- a/src/components/PaginateData.vue +++ b/src/components/PaginateData.vue @@ -61,8 +61,8 @@ const arrayData = useArrayData(props.dataKey, { }); const store = arrayData.store; -onMounted(() => { - if (props.autoLoad) paginate(); +onMounted(async () => { + if (props.autoLoad) await fetch(); }); watch( @@ -72,6 +72,15 @@ watch( } ); +async function fetch() { + await arrayData.fetch({ append: false }); + if (!arrayData.hasMoreData.value) { + isLoading.value = false; + } + + emit('onFetch', store.data); +} + async function paginate() { const { page, rowsPerPage, sortBy, descending } = pagination.value; diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 557a07f3b..777ef5bfe 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -27,7 +27,7 @@ onMounted(() => { async function search() { const params = userParams.value; - await arrayData.apply({ params }); + await arrayData.addFilter({ params }); } const tags = computed(() => { diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 6c0809c8b..d8e6efcf2 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -1,8 +1,7 @@ @@ -63,9 +62,9 @@ async function search() { + + diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 5dde2f516..6c9558637 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -99,13 +99,20 @@ export function useArrayData(key, userOptions) { return response.data; } - async function apply({ filter, params }) { + async function applyFilter({ filter, params }) { if (filter) store.userFilter = filter; if (params) store.userParams = Object.assign({}, params); await fetch({ append: false }); } + async function addFilter({ filter, params }) { + if (filter) store.userFilter = Object.assign(store.userFilter, filter); + if (params) store.userParams = Object.assign(store.userParams, params); + + await fetch({ append: false }); + } + async function loadMore() { if (!hasMoreData.value) return; @@ -133,7 +140,8 @@ export function useArrayData(key, userOptions) { return { fetch, - apply, + applyFilter, + addFilter, refresh, request, loadMore, diff --git a/src/pages/Ticket/Card/TicketCard.vue b/src/pages/Ticket/Card/TicketCard.vue index 71df0dfce..6992b2406 100644 --- a/src/pages/Ticket/Card/TicketCard.vue +++ b/src/pages/Ticket/Card/TicketCard.vue @@ -2,13 +2,18 @@ import { useState } from 'src/composables/useState'; import TicketDescriptor from './TicketDescriptor.vue'; import LeftMenu from 'components/LeftMenu.vue'; +import TeleportSlot from 'components/ui/TeleportSlot.vue'; +import VnSearchbar from 'src/components/ui/VnSearchbar.vue'; const state = useState();