diff --git a/src/components/navigation/PaginationButtons.vue b/src/components/navigation/PaginationButtons.vue new file mode 100644 index 000000000..aff91d336 --- /dev/null +++ b/src/components/navigation/PaginationButtons.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/src/components/views/OnlineModView.vue b/src/components/views/OnlineModView.vue index 5d03dea83..c30e884cf 100644 --- a/src/components/views/OnlineModView.vue +++ b/src/components/views/OnlineModView.vue @@ -59,15 +59,12 @@


- + @@ -84,15 +81,17 @@ import OnlineModListProvider from '../../providers/components/loaders/OnlineModL import ArrayUtils from '../../utils/ArrayUtils'; import debounce from 'lodash.debounce'; import SearchUtils from '../../utils/SearchUtils'; +import PaginationButtons from "../navigation/PaginationButtons.vue"; @Component({ components: { OnlineModList: OnlineModListProvider.provider, + PaginationButtons, } }) export default class OnlineModView extends Vue { - readonly pageSize = 140; + readonly pageSize = 40; pagedThunderstoreModList: ThunderstoreMod[] = []; pageNumber = 1; searchableThunderstoreModList: ThunderstoreMod[] = []; diff --git a/src/utils/Pagination.ts b/src/utils/Pagination.ts new file mode 100644 index 000000000..b0283bf22 --- /dev/null +++ b/src/utils/Pagination.ts @@ -0,0 +1,54 @@ + +export type PaginationButton = { + index: number; + title: string; +} + +export function truncatePagination(props: { + currentPage: number, + pageCount: number, + contextSize: number, +}): PaginationButton[] { + const result = []; + + if (props.currentPage - props.contextSize > 1) { + result.push({ + index: 1, + title: "1" + }); + } + if (props.currentPage - props.contextSize - 1 > 1) { + result.push({ + index: props.currentPage - props.contextSize - 1, + title: "...", + }); + } + + for ( + let i = props.currentPage - props.contextSize; + i <= props.currentPage + props.contextSize; + i++ + ) { + if (i > 0 && i <= props.pageCount) { + result.push({ + index: i, + title: i.toString(), + }); + } + } + + if (props.currentPage + props.contextSize + 1 < props.pageCount) { + result.push({ + index: props.currentPage + props.contextSize + 1, + title: "...", + }); + } + if (props.currentPage + props.contextSize < props.pageCount) { + result.push({ + index: props.pageCount, + title: props.pageCount.toString(), + }); + } + + return result; +}