Skip to content

A self-hosted media server and file management system

fix: pagination wrapping and limit on max visible pages

aminnausin9d6cf1181009
diff --git a/resources/js/components/panels/VideoSidebar.vue b/resources/js/components/panels/VideoSidebar.vue
index 75eb61de..76b77ef4 100755
--- a/resources/js/components/panels/VideoSidebar.vue
+++ b/resources/js/components/panels/VideoSidebar.vue
@@ -79,6 +79,7 @@ watch(
stateFolderName: stateFolder?.name,
}"
:items-per-page="10"
+ :max-visible-pages="3"
:pagination-class="'!justify-center !flex-col-reverse'"
:use-pagination-icons="true"
/>
diff --git a/resources/js/components/pinesUI/InputSelect.vue b/resources/js/components/pinesUI/InputSelect.vue
index 6010e94f..c583f1e9 100755
--- a/resources/js/components/pinesUI/InputSelect.vue
+++ b/resources/js/components/pinesUI/InputSelect.vue
@@ -127,7 +127,10 @@ watch(
:id="name ?? 'Select'"
ref="selectButton"
@click="select.toggleSelect()"
- :class="`${select.selectOpen && 'hocus:ring-0'} relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10 text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500 text-gray-900 dark:text-neutral-100 bg-white dark:bg-primary-dark-800 ${props.class}
+ :class="`${select.selectOpen && 'hocus:ring-0'} relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10
+ text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none
+ ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500
+ text-gray-900 dark:text-neutral-100 bg-white dark:bg-primary-dark-800 ${props.class} ${placeholder && !select.selectedItem ? '!text-neutral-400' : ''}
disabled:cursor-not-allowed disabled:hover:ring-neutral-200 disabled:hover:dark:ring-neutral-700 disabled:opacity-60
`"
:disabled="disabled"
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index e95c67d6..75f8f014 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -24,6 +24,7 @@ const props = withDefaults(defineProps<TableProps<T>>(), {
startAscending: true,
searchQuery: '',
usePaginationIcons: false,
+ maxVisiblePages: 5,
});
const emit = defineEmits<{
@@ -75,22 +76,22 @@ onMounted(() => {
<section v-if="props.useToolbar" class="flex justify-center sm:justify-between flex-col sm:flex-row gap-2">
<TextInputLabelled
:value="model ?? tableData.fields.searchQuery"
- :text="'Search:'"
- :placeholder="'Enter Search Query...'"
+ :text="''"
+ :placeholder="`Search ${props.itemName ? `${props.itemName}...` : ''}`"
:id="'table-search'"
class="w-full sm:w-80"
- title="Search Here"
+ title="Search with..."
@input="handleSearch"
/>
<span class="flex items-end gap-2 flex-wrap">
<div class="flex gap-2 flex-col w-full sm:w-40 flex-1">
- <FormInputLabel :field="{ name: 'sort', text: 'Sort by:' }" />
+ <FormInputLabel :field="{ name: 'sort', text: 'Sort by:' }" class="hidden" />
<InputSelect
:name="'sort'"
- :placeholder="'None'"
+ :placeholder="'Sort by...'"
:options="props.sortingOptions"
class="w-full"
- title="Select Sort"
+ title="Sort by..."
@selectItem="handleSortChange"
:defaultItem="0"
/>
@@ -100,8 +101,8 @@ onMounted(() => {
sortAscending = !sortAscending;
handleSortChange();
"
- :title="`Sort Results`"
- :aria-label="`Sort Results`"
+ :title="`Reorder Results...`"
+ :aria-label="`Reorder Results`"
class="ring-inset"
>
<template #icon>
@@ -143,6 +144,7 @@ onMounted(() => {
:itemsPerPage="tableData.fields.itemsPerPage"
:currentPage="tableData.fields.currentPage"
:useIcons="props.usePaginationIcons"
+ :max-visible-pages="props.maxVisiblePages"
@setPage="tableData.handlePageChange"
/>
</section>
diff --git a/resources/js/components/table/TablePagination.vue b/resources/js/components/table/TablePagination.vue
index b80977ae..dafe4cab 100755
--- a/resources/js/components/table/TablePagination.vue
+++ b/resources/js/components/table/TablePagination.vue
@@ -6,12 +6,18 @@ import TablePaginationButton from '@/components/table/TablePaginationButton.vue'
import ProiconsChevronRight from '~icons/proicons/chevron-right';
import ProiconsChevronLeft from '~icons/proicons/chevron-left';
-const props = defineProps<{
- listLength: number;
- currentPage: number;
- itemsPerPage: number;
- useIcons: boolean;
-}>();
+const props = withDefaults(
+ defineProps<{
+ listLength: number;
+ currentPage: number;
+ itemsPerPage: number;
+ useIcons: boolean;
+ maxVisiblePages?: number;
+ }>(),
+ {
+ maxVisiblePages: 5,
+ },
+);
const $element = ref<null | HTMLElement>(null);
const emit = defineEmits(['setPage']);
@@ -19,19 +25,30 @@ const emit = defineEmits(['setPage']);
const pageCount = computed(() => {
return Math.ceil(props.listLength / props.itemsPerPage);
});
-const pageRange = computed(() => {
- let out = null;
- if (pageCount.value <= 5) out = pageCount.value;
- else if (props.currentPage <= 3) out = Math.min(4, pageCount.value);
- else if (pageCount.value - props.currentPage <= 2) {
- let range: number[] = [];
- for (let i = pageCount.value - 3; i <= pageCount.value; i++) {
- range = [...range, i];
+
+const pageRange = computed<number | number[]>(() => {
+ const total = pageCount.value;
+ const current = props.currentPage;
+ const maxVisible = props.maxVisiblePages;
+ const edgeThreshold = Math.max(maxVisible - 1, 3);
+
+ if (total <= maxVisible) return Array.from({ length: total }, (_, i) => i + 1); // Threshold to show all pages at once
+
+ // 1 2 or 3, then show 1 2 3 4... options should be 1 2 or more, so max - 1 or 3 whichever is higher
+ // Threshold (by page selected) to show groups of pages at left end (ie 1, 2, [3], 4, ..., 10)
+ if (current <= edgeThreshold - 1) return Array.from({ length: edgeThreshold }, (_, i) => i + 1); // Number of pages to show with current page on left end (ie [1], 2, 3, 4, ..., 10) (inclusive)
+ if (pageCount.value - current < edgeThreshold - 1) {
+ // 7 8 9 or 10
+ // Threshold (by page selected) to show group of pages at right end (ie 1, ..., 7, [8], 9, 10)
+ let range: number[] = []; // Number of pages to show with current page on left end (ie 1, ..., 7, 8, 9, [10]) (exclusive so 3 items means 3 + 1 [the selected page])
+ for (let i = pageCount.value - edgeThreshold + 1; i <= pageCount.value; i++) {
+ range = [...range, i]; // Fill an array with all integers from pageCount - (number of items in group - 1) to pageCount
}
- out = range;
+
+ return range;
}
- return out === null ? [props.currentPage - 1, props.currentPage, props.currentPage + 1] : out;
+ return maxVisible >= 5 ? [current - 1, current, current + 1] : [current];
});
const handleSetPage = async (page: number) => {
@@ -67,14 +84,15 @@ const handleSetPage = async (page: number) => {
</template>
</TablePaginationButton>
- <template v-if="pageCount > 5 && props.currentPage > 3">
+ <!-- Diff between start and current page is greater than 2 -->
+ <template v-if="pageCount > props.maxVisiblePages && props.currentPage > Math.max(props.maxVisiblePages - 2, 2)">
<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="handleSetPage(page)" />
- <template v-if="pageCount > 5 && pageCount - props.currentPage > 2">
+ <template v-if="pageCount > props.maxVisiblePages && pageCount - props.currentPage > Math.max(props.maxVisiblePages - 3, 1)">
<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>
diff --git a/resources/js/types/types.ts b/resources/js/types/types.ts
index e49f762c..2c0c8d2b 100644
--- a/resources/js/types/types.ts
+++ b/resources/js/types/types.ts
@@ -276,11 +276,13 @@ export interface TableProps<T> {
sortAction?: (sortKey: keyof T, direction: 1 | -1) => void;
sortingOptions?: SortOption[];
itemsPerPage?: number;
+ itemName?: string;
searchQuery?: string;
selectedID?: number | string | null;
tableStyles?: string;
startAscending?: boolean;
paginationClass?: string;
+ maxVisiblePages?: number;
}
export interface DropdownMenuItem {