Added better looking pad scroll.

This commit is contained in:
SamTV12345 2024-03-14 16:41:48 +01:00
parent 7ef69d3840
commit 9575ab8457
2 changed files with 50 additions and 12 deletions

View file

@ -639,3 +639,35 @@ table tbody tr.active-row {
font-weight: bold; font-weight: bold;
color: #009879; color: #009879;
} }
.pad-pagination{
display: flex;
justify-content: center;
gap: 10px;
margin-top: 20px;
}
.pad-pagination button {
display: flex;
padding: 10px 20px;
border-radius: 5px;
border: none;
color: black;
cursor: pointer;
}
.pad-pagination button:disabled {
background: transparent;
color: lightgrey;
cursor: not-allowed;
}
.pad-pagination span {
align-self: center;
}
.pad-pagination >span {
font-size: 20px;
}

View file

@ -6,7 +6,7 @@ import {useDebounce} from "../utils/useDebounce.ts";
import {determineSorting} from "../utils/sorting.ts"; import {determineSorting} from "../utils/sorting.ts";
import * as Dialog from "@radix-ui/react-dialog"; import * as Dialog from "@radix-ui/react-dialog";
import {IconButton} from "../components/IconButton.tsx"; import {IconButton} from "../components/IconButton.tsx";
import {Trash2} from "lucide-react"; import {ArrowLeft, ArrowRight, ChevronLeft, ChevronRight, Trash2} from "lucide-react";
import {SearchField} from "../components/SearchField.tsx"; import {SearchField} from "../components/SearchField.tsx";
export const PadPage = ()=>{ export const PadPage = ()=>{
@ -21,16 +21,16 @@ export const PadPage = ()=>{
const {t} = useTranslation() const {t} = useTranslation()
const [searchTerm, setSearchTerm] = useState<string>('') const [searchTerm, setSearchTerm] = useState<string>('')
const pads = useStore(state=>state.pads) const pads = useStore(state=>state.pads)
const [currentPage, setCurrentPage] = useState<number>(0)
const [deleteDialog, setDeleteDialog] = useState<boolean>(false)
const [padToDelete, setPadToDelete] = useState<string>('')
const pages = useMemo(()=>{ const pages = useMemo(()=>{
if(!pads){ if(!pads){
return [0] return [0]
} }
const totalPages = Math.ceil(pads!.total / searchParams.limit) return Math.ceil(pads!.total / searchParams.limit)
return Array.from({length: totalPages}, (_, i) => i+1)
},[pads, searchParams.limit]) },[pads, searchParams.limit])
const [deleteDialog, setDeleteDialog] = useState<boolean>(false)
const [padToDelete, setPadToDelete] = useState<string>('')
useDebounce(()=>{ useDebounce(()=>{
setSearchParams({ setSearchParams({
@ -158,15 +158,21 @@ export const PadPage = ()=>{
} }
</tbody> </tbody>
</table> </table>
<div className="settings-button-bar"> <div className="settings-button-bar pad-pagination">
{pages.map((page)=>{ <button disabled={currentPage == 0} onClick={()=>{
return <button key={page} onClick={()=>{ setCurrentPage(currentPage-1)
setSearchParams({ setSearchParams({
...searchParams, ...searchParams,
offset: (page-1)*searchParams.limit offset: (Number(currentPage)-1)*searchParams.limit})
}) }}><ChevronLeft/><span>Previous Page</span></button>
}}>{page}</button> <span>{currentPage+1} out of {pages}</span>
})} <button disabled={pages == currentPage+1} onClick={()=>{
setCurrentPage(currentPage+1)
setSearchParams({
...searchParams,
offset: (Number(currentPage)-1)*searchParams.limit
})
}}><span>Next Page</span><ChevronRight/></button>
</div> </div>
</div> </div>
} }