0
0
Fork 0

Paginate initial load fix

This commit is contained in:
Joan Sanchez 2023-02-15 15:51:31 +01:00
parent a864e2786b
commit bd904ad82a
6 changed files with 57 additions and 23 deletions

View File

@ -61,8 +61,8 @@ const arrayData = useArrayData(props.dataKey, {
}); });
const store = arrayData.store; const store = arrayData.store;
onMounted(() => { onMounted(async () => {
if (props.autoLoad) paginate(); if (props.autoLoad) await fetch();
}); });
watch( 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() { async function paginate() {
const { page, rowsPerPage, sortBy, descending } = pagination.value; const { page, rowsPerPage, sortBy, descending } = pagination.value;

View File

@ -27,7 +27,7 @@ onMounted(() => {
async function search() { async function search() {
const params = userParams.value; const params = userParams.value;
await arrayData.apply({ params }); await arrayData.addFilter({ params });
} }
const tags = computed(() => { const tags = computed(() => {

View File

@ -1,8 +1,7 @@
<script setup> <script setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { route } from 'quasar/wrappers';
const props = defineProps({ const props = defineProps({
dataKey: { dataKey: {
@ -22,7 +21,7 @@ const props = defineProps({
}); });
const router = useRouter(); const router = useRouter();
// const route = useRoute(); const route = useRoute();
const arrayData = useArrayData(props.dataKey); const arrayData = useArrayData(props.dataKey);
const store = arrayData.store; const store = arrayData.store;
const searchText = ref(); const searchText = ref();
@ -35,26 +34,26 @@ onMounted(() => {
}); });
async function search() { async function search() {
await arrayData.apply({ await arrayData.applyFilter({
params: { params: {
search: searchText.value, search: searchText.value,
}, },
}); });
if (!props.redirect) return; if (!props.redirect) return;
console.log(route.query);
const moduleRoute = route.matched[1];
console.log(moduleRoute);
const rows = store.data; const rows = store.data;
if (rows.length === 1) { if (rows.length === 1) {
const firstRow = rows[0]; const firstRow = rows[0];
router.push({ path: `/customer/${firstRow.id}` }); const stateName = `${moduleRoute.name}Card`;
} else { await router.push({ name: stateName, params: { id: firstRow.id } });
router.replace({ path: `/customer` }); arrayData.updateStateParams();
} else if (route.matched.length > 3) {
await router.push({ name: moduleRoute.name });
arrayData.updateStateParams();
} }
// if (route.matched.length > 2) {
// } else {
// }
} }
</script> </script>
@ -63,9 +62,9 @@ async function search() {
<q-input <q-input
id="searchbar" id="searchbar"
v-model="searchText" v-model="searchText"
:label="props.label" :placeholder="props.label"
dense dense
standout="bg-grey-6 text-white" standout
autofocus autofocus
> >
<template #prepend> <template #prepend>
@ -74,3 +73,16 @@ async function search() {
</q-input> </q-input>
</q-form> </q-form>
</template> </template>
<style lang="scss">
#searchbar .q-field {
min-width: 350px;
}
.body--light #searchbar {
.q-field--standout.q-field--highlighted .q-field__control {
background-color: $grey-7;
color: #333;
}
}
</style>

View File

@ -99,13 +99,20 @@ export function useArrayData(key, userOptions) {
return response.data; return response.data;
} }
async function apply({ filter, params }) { async function applyFilter({ filter, params }) {
if (filter) store.userFilter = filter; if (filter) store.userFilter = filter;
if (params) store.userParams = Object.assign({}, params); if (params) store.userParams = Object.assign({}, params);
await fetch({ append: false }); 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() { async function loadMore() {
if (!hasMoreData.value) return; if (!hasMoreData.value) return;
@ -133,7 +140,8 @@ export function useArrayData(key, userOptions) {
return { return {
fetch, fetch,
apply, applyFilter,
addFilter,
refresh, refresh,
request, request,
loadMore, loadMore,

View File

@ -2,13 +2,18 @@
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import TicketDescriptor from './TicketDescriptor.vue'; import TicketDescriptor from './TicketDescriptor.vue';
import LeftMenu from 'components/LeftMenu.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(); const state = useState();
</script> </script>
<template> <template>
<teleport-slot to="#searchbar">
<VnSearchbar data-key="TicketList" />
</teleport-slot>
<q-drawer v-model="state.drawer.value" show-if-above :width="256" :breakpoint="500"> <q-drawer v-model="state.drawer.value" show-if-above :width="256" :breakpoint="500">
<q-scroll-area class="fit"> <q-scroll-area class="fit">
<ticket-descriptor /> <TicketDescriptor />
<q-separator /> <q-separator />
<left-menu source="card" /> <left-menu source="card" />
</q-scroll-area> </q-scroll-area>

View File

@ -73,7 +73,7 @@ function viewSummary(id) {
<template> <template>
<teleport-slot to="#searchbar"> <teleport-slot to="#searchbar">
<VnSearchbar data-key="TicketList" /> <VnSearchbar data-key="TicketList" label="Search by ticket id or alias" />
</teleport-slot> </teleport-slot>
<teleport-slot to="#rightPanel"> <teleport-slot to="#rightPanel">
<VnFilterPanel data-key="TicketList"> <VnFilterPanel data-key="TicketList">