Skip to content

A self-hosted media server and file management system

scroll to page buttons if page is smaller

aminnausin4bb3444e9d2e
diff --git a/resources/js/components/table/TablePagination.vue b/resources/js/components/table/TablePagination.vue
index 0499982c..d1a38291 100644
--- a/resources/js/components/table/TablePagination.vue
+++ b/resources/js/components/table/TablePagination.vue
@@ -1,7 +1,9 @@
<script setup>
-import { computed } from 'vue';
+import { computed, nextTick, ref } from 'vue';
import TablePaginationButton from './TablePaginationButton.vue';
+const emit = defineEmits(['setPage']);
+const $element = ref(null)
const props = defineProps(['listLength', 'currentPage', 'itemsPerPage']);
const pageCount = computed(() => { return Math.ceil(props.listLength / props.itemsPerPage); });
const pageRange = computed(() => {
@@ -18,10 +20,16 @@ const pageRange = computed(() => {
return out === null ? [props.currentPage - 1, props.currentPage, props.currentPage + 1] : out;
})
+
+const handleSetPage = async (page) => {
+ emit('setPage', page);
+ await nextTick();
+ $element.value?.scrollIntoView();
+}
</script>
<template>
- <div class="flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2" id="pageinate">
+ <div class="flex items-center flex-col sm:flex-row sm:justify-between flex-wrap gap-2" ref="$element">
<p class="text-gray-700 dark:text-neutral-300 line-clamp-1">
Showing
<span class="font-medium dark:text-neutral-100">{{ props.listLength ? props.itemsPerPage * (currentPage - 1) + 1 : 0 }}</span>
@@ -31,27 +39,27 @@ const pageRange = computed(() => {
<span class="font-medium dark:text-neutral-100">{{ listLength }}</span>
<!-- Results -->
</p>
- <nav id="pageinate">
+ <nav>
<ul
class="flex flex-wrap items-center text-sm leading-tight bg-white dark:bg-primary-dark-800/70 border divide-x rounded h-9 text-neutral-500 dark:text-neutral-200 divide-neutral-200 dark:divide-neutral-700 border-neutral-200 dark:border-neutral-700">
<TablePaginationButton :pageNumber="-1" :text="'Previous'" :disabled="props.currentPage === 1"
- @click="$emit('setPage', Math.max(1, props.currentPage - 1))" />
+ @click="handleSetPage(Math.max(1, props.currentPage - 1))" />
<template v-if="pageCount > 5 && props.currentPage > 3">
- <TablePaginationButton :pageNumber="1" :currentPage="props.currentPage" @click="$emit('setPage', 1)" :sticky="true"/>
- <TablePaginationButton :pageNumber="-1" :text="'...'" @click="$emit('setPage', Math.floor(currentPage/2))" :underline="true"/>
+ <TablePaginationButton :pageNumber="1" :currentPage="props.currentPage" @click="handleSetPage(1)" :sticky="true"/>
+ <TablePaginationButton :pageNumber="-1" :text="'...'" @click="handleSetPage(Math.floor(currentPage/2))" :underline="true"/>
</template>
<TablePaginationButton v-for="page in pageRange" :key="page" :pageNumber="page"
- :currentPage="props.currentPage" @click="$emit('setPage', page)" />
+ :currentPage="props.currentPage" @click="handleSetPage(page)" />
<template v-if="pageCount > 5 && pageCount - props.currentPage > 2">
- <TablePaginationButton :pageNumber="-1" :text="'...'" @click="$emit('setPage', Math.floor((pageCount - currentPage) / 2 + currentPage))" :underline="true"/>
- <TablePaginationButton :pageNumber="pageCount" :currentPage="props.currentPage" @click="$emit('setPage', pageCount)" :sticky="true"/>
+ <TablePaginationButton :pageNumber="-1" :text="'...'" @click="handleSetPage(Math.floor((pageCount - currentPage) / 2 + currentPage))" :underline="true"/>
+ <TablePaginationButton :pageNumber="pageCount" :currentPage="props.currentPage" @click="handleSetPage(pageCount)" :sticky="true"/>
</template>
<TablePaginationButton :pageNumber="-1" :text="'Next'" :disabled="props.currentPage === pageCount"
- @click="$emit('setPage', Math.min(pageCount, props.currentPage + 1))" />
+ @click="handleSetPage(Math.min(pageCount, props.currentPage + 1))" />
</ul>
</nav>
</div>