/* * Copyright (C) 2025 Aleksander WilczyƄski (aleks@alekswilc.dev) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * See LICENSE for more. */ import { Dispatch, SetStateAction } from "react"; const getPaginationNums = (page: number, pages: number) => { if (pages <= 5) return Array.from({ length: pages }, (_, i) => i + 1); const numbers = [1]; if (page <= 3) { numbers.push(2, 3, 4); } else if (page >= pages - 2) { numbers.push(pages - 3, pages - 2, pages - 1); } else { numbers.push(page - 1, page, page + 1); } numbers.push(pages); return [...new Set(numbers)].sort((a, b) => a - b); } export const Paginator = ({ page, setPage, pages }: { page: number, pages: number, setPage: Dispatch> }) => { // todo: rewrite this shit XDDDDDDDD const numbers = getPaginationNums(page, pages); return
; };