11import { useDomains } from "../../hooks/useDomains.ts" ;
22import { Loader } from "../../Loader.tsx" ;
3- import { Flex , Group , Table , Text } from "@mantine/core" ;
3+ import { Flex , Group , Pagination , Stack , Table , Text } from "@mantine/core" ;
44import { formatDateTime } from "../../util.ts" ;
55import { IconPlus , IconServer } from "@tabler/icons-react" ;
6- import { useDisclosure } from "@mantine/hooks" ;
6+ import { useDisclosure , useScrollIntoView } from "@mantine/hooks" ;
77import { NewDomain } from "./NewDomain.tsx" ;
88import { Link } from "../../Link.tsx" ;
99import InfoAlert from "../InfoAlert.tsx" ;
@@ -14,6 +14,9 @@ import OrganizationHeader from "../organizations/OrganizationHeader.tsx";
1414import { MaintainerButton } from "../RoleButtons.tsx" ;
1515import { useProjectWithId } from "../../hooks/useProjects.ts" ;
1616import { Domain } from "../../types.ts" ;
17+ import { useState } from "react" ;
18+
19+ const PER_PAGE = 20 ;
1720
1821function DomainRow ( { domain } : { domain : Domain } ) {
1922 const project_name = useProjectWithId ( domain . project_id ) ?. name ;
@@ -59,6 +62,12 @@ function DomainRow({ domain }: { domain: Domain }) {
5962export default function DomainsOverview ( ) {
6063 const [ opened , { open, close } ] = useDisclosure ( false ) ;
6164 const { domains } = useDomains ( ) ;
65+ const [ activePage , setPage ] = useState ( 1 ) ;
66+
67+ const { scrollIntoView, targetRef } = useScrollIntoView < HTMLTableSectionElement > ( {
68+ duration : 500 ,
69+ offset : 100 ,
70+ } ) ;
6271
6372 if ( domains === null ) {
6473 return < Loader /> ;
@@ -73,15 +82,27 @@ export default function DomainsOverview() {
7382 </ InfoAlert >
7483
7584 < NewDomain opened = { opened } close = { close } />
76- < StyledTable headers = { [ "Domains" , "DNS Status" , "Usable by" , "Updated" , "" ] } >
77- { domains . map ( ( domain ) => (
85+ < StyledTable ref = { targetRef } headers = { [ "Domains" , "DNS Status" , "Usable by" , "Updated" , "" ] } >
86+ { domains . slice ( ( activePage - 1 ) * PER_PAGE , activePage * PER_PAGE ) . map ( ( domain ) => (
7887 < DomainRow domain = { domain } key = { domain . id } />
7988 ) ) }
8089 </ StyledTable >
8190 < Flex justify = "center" mt = "md" >
82- < MaintainerButton onClick = { ( ) => open ( ) } leftSection = { < IconPlus /> } >
83- New Domain
84- </ MaintainerButton >
91+ < Stack >
92+ { domains . length > PER_PAGE && (
93+ < Pagination
94+ value = { activePage }
95+ onChange = { ( p ) => {
96+ setPage ( p ) ;
97+ scrollIntoView ( { alignment : "start" } ) ;
98+ } }
99+ total = { Math . ceil ( domains . length / PER_PAGE ) }
100+ />
101+ ) }
102+ < MaintainerButton onClick = { ( ) => open ( ) } leftSection = { < IconPlus /> } >
103+ New Domain
104+ </ MaintainerButton >
105+ </ Stack >
85106 </ Flex >
86107 </ >
87108 ) ;
0 commit comments