Browse Source

FIX: pagination changed to redux-vue

pull/2433/head
Владислав Прийма 6 months ago
parent
commit
f3a6ea8bc1
  1. 81
      src/app/components/Clients/Pagination.vue
  2. 7
      src/app/components/Icons/ChevronDoubleLeft.vue
  3. 7
      src/app/components/Icons/ChevronDoubleRight.vue
  4. 7
      src/app/components/Icons/ChevronLeft.vue
  5. 7
      src/app/components/Icons/ChevronRight.vue
  6. 10
      src/app/pages/index.vue
  7. 11
      src/app/stores/clients.ts

81
src/app/components/Clients/Pagination.vue

@ -1,33 +1,62 @@
<template> <template>
<div <PaginationRoot
class="mt-4 flex items-center justify-center gap-2" :total="clientsStore.total"
:page="clientsStore.page"
:itemsPerPage="clientsStore.limit"
:sibling-count="1"
show-edges
@update:page="setPage"
> >
<button <PaginationList
class="btn" v-slot="{ items }"
v-if="clientsStore.page > 1" class="mt-4 mb-2 flex items-center gap-1 justify-center"
@click="setPage(clientsStore.page - 1)"
> >
<PaginationFirst class="inline-flex items-center text-gray-700 dark:text-neutral-200">
</button> <IconsChevronDoubleLeft class="w-4 md:mr-2" />
</PaginationFirst>
<span class="text-sm text-gray-500"> <PaginationPrev class="inline-flex items-center text-gray-700 dark:text-neutral-200">
{{ clientsStore.page }} / {{ clientsStore.totalPages }} <IconsChevronLeft class="w-4 md:mr-2" />
</span> </PaginationPrev>
<template v-for="(page, index) in items">
<button <PaginationListItem
class="btn" v-if="page.type === 'page'"
v-if="clientsStore.page < clientsStore.totalPages" :key="index"
@click="setPage(clientsStore.page + 1)" class="inline-flex items-center rounded border-2 border-gray-100 px-4 py-2 text-gray-700 transition hover:border-red-800 hover:bg-red-800 hover:text-white dark:border-neutral-600 dark:text-neutral-200 data-[selected]:border-red-800 data-[selected]:bg-red-800 data-[selected]:text-white"
> :value="page.value"
>
</button> {{ page.value }}
</div> </PaginationListItem>
<PaginationEllipsis
v-else
:key="page.type"
:index="index"
class="w-9 h-9 flex items-center justify-center text-gray-700 dark:text-neutral-200"
>
&#8230;
</PaginationEllipsis>
</template>
<PaginationNext class="inline-flex items-center text-gray-700 dark:text-neutral-200">
<IconsChevronRight class="w-4 md:mr-2" />
</PaginationNext>
<PaginationLast class="inline-flex items-center text-gray-700 dark:text-neutral-200">
<IconsChevronDoubleRight class="w-4 md:mr-2" />
</PaginationLast>
</PaginationList>
</PaginationRoot>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
const clientsStore = useClientsStore(); import {
PaginationEllipsis,
function setPage(p: number) { PaginationFirst,
clientsStore.setPageQuery(p); PaginationLast,
PaginationList,
PaginationListItem,
PaginationNext,
PaginationPrev,
PaginationRoot } from 'radix-vue'
const clientsStore = useClientsStore();
function setPage(p: number) {
clientsStore.setPageQuery(p);
} }
</script> </script>

7
src/app/components/Icons/ChevronDoubleLeft.vue

@ -0,0 +1,7 @@
<template>
<ChevronDoubleLeftIcon />
</template>
<script lang="ts" setup>
import ChevronDoubleLeftIcon from '@heroicons/vue/24/outline/esm/ChevronDoubleLeftIcon';
</script>

7
src/app/components/Icons/ChevronDoubleRight.vue

@ -0,0 +1,7 @@
<template>
<ChevronDoubleRightIcon />
</template>
<script lang="ts" setup>
import ChevronDoubleRightIcon from '@heroicons/vue/24/outline/esm/ChevronDoubleRightIcon';
</script>

7
src/app/components/Icons/ChevronLeft.vue

@ -0,0 +1,7 @@
<template>
<ChevronLeftIcon />
</template>
<script lang="ts" setup>
import ChevronLeftIcon from '@heroicons/vue/24/outline/esm/ChevronLeftIcon';
</script>

7
src/app/components/Icons/ChevronRight.vue

@ -0,0 +1,7 @@
<template>
<ChevronRightIcon />
</template>
<script lang="ts" setup>
import ChevronRightIcon from '@heroicons/vue/24/outline/esm/ChevronRightIcon';
</script>

10
src/app/pages/index.vue

@ -15,11 +15,6 @@
v-if="clientsStore.clients && clientsStore.clients.length > 0" v-if="clientsStore.clients && clientsStore.clients.length > 0"
/> />
</div> </div>
<div>
<ClientsPagination
v-if="clientsStore.totalPages > 1"
/>
</div>
<ClientsEmpty <ClientsEmpty
v-if="clientsStore.clients && clientsStore.clients.length === 0" v-if="clientsStore.clients && clientsStore.clients.length === 0"
/> />
@ -29,6 +24,11 @@
> >
<IconsLoading class="mx-auto w-5 animate-spin" /> <IconsLoading class="mx-auto w-5 animate-spin" />
</div> </div>
<div>
<ClientsPagination
v-if="clientsStore.total > clientsStore.limit"
/>
</div>
</Panel> </Panel>
</main> </main>
</template> </template>

11
src/app/stores/clients.ts

@ -33,7 +33,7 @@ export const useClientsStore = defineStore('Clients', () => {
const sortClient = ref<boolean>(true) const sortClient = ref<boolean>(true)
const page = ref<number>(1); const page = ref<number>(1);
const limit = ref<number>(10); const limit = ref<number>(10);
const totalPages = ref<number>(1); const total = ref<number>(0);
const searchParams = ref({ const searchParams = ref({
filter: undefined as string | undefined, filter: undefined as string | undefined,
@ -133,14 +133,13 @@ export const useClientsStore = defineStore('Clients', () => {
}); });
clients.value = transformedClients ?? null; clients.value = transformedClients ?? null;
if (_clients.value){ total.value = (_clients.value?.total ?? _clients.value?.clients?.length) ?? 0;
let total = (_clients.value?.total ?? _clients.value?.clients?.length) ?? 0;
totalPages.value = total <= limit.value ? 1 : Math.ceil(total / limit.value);
}
} }
function setSearchQuery(filter: string) { function setSearchQuery(filter: string) {
clients.value = null; clients.value = null;
total.value = 0;
setPageQuery(1);
searchParams.value.filter = filter || undefined; searchParams.value.filter = filter || undefined;
} }
@ -156,5 +155,5 @@ export const useClientsStore = defineStore('Clients', () => {
searchParams.value.sortClient = value; searchParams.value.sortClient = value;
} }
return { clients, clientsPersist, sortClient, page, totalPages, refresh, _clients, setSearchQuery, setPageQuery, setSortClientQuery }; return { clients, clientsPersist, sortClient, page, total, limit, refresh, _clients, setSearchQuery, setPageQuery, setSortClientQuery };
}); });

Loading…
Cancel
Save