-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds basic pagination and improved loading state (#37)
- Loading branch information
1 parent
063a357
commit ef577e1
Showing
8 changed files
with
193 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React from "react"; | ||
import { | ||
Box, | ||
Button, | ||
ButtonGroup, | ||
Flex, | ||
HStack, | ||
Icon, | ||
Select, | ||
Spacer, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { | ||
ChevronRightIcon, | ||
ChevronLeftIcon, | ||
ChevronDoubleLeftIcon, | ||
} from "@heroicons/react/24/outline"; | ||
|
||
import type { GSearchResult } from "@/globus/search"; | ||
import { useSearch, useSearchDispatch } from "@/app/search-provider"; | ||
|
||
export const Pagination = ({ result }: { result?: GSearchResult }) => { | ||
const search = useSearch(); | ||
const dispatch = useSearchDispatch(); | ||
|
||
if (!result) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Flex align="center" p={2}> | ||
<HStack> | ||
<Text fontSize="sm" as="label" htmlFor="limit"> | ||
Results per page: | ||
</Text> | ||
<Box> | ||
<Select | ||
id="limit" | ||
size="sm" | ||
value={search.limit} | ||
onChange={(e) => { | ||
dispatch({ | ||
type: "set_limit", | ||
payload: parseInt(e.target.value), | ||
}); | ||
}} | ||
> | ||
<option value={10}>10</option> | ||
<option value={25}>25</option> | ||
<option value={50}>50</option> | ||
<option value={100}>100</option> | ||
</Select> | ||
</Box> | ||
</HStack> | ||
<Spacer /> | ||
<Text fontSize="xs"> | ||
{search.offset > 0 ? search.offset : 1}-{search.offset + search.limit}{" "} | ||
of {result.total} | ||
</Text> | ||
<Spacer /> | ||
<ButtonGroup variant="outline" spacing="6"> | ||
<Button | ||
size="sm" | ||
isDisabled={search.offset === 0} | ||
onClick={() => { | ||
dispatch({ type: "set_offset", payload: 0 }); | ||
}} | ||
> | ||
<Icon as={ChevronDoubleLeftIcon} /> | ||
</Button> | ||
<Button | ||
size="sm" | ||
isDisabled={search.offset === 0} | ||
onClick={() => { | ||
dispatch({ | ||
type: "set_offset", | ||
payload: search.offset - search.limit, | ||
}); | ||
}} | ||
> | ||
<Icon as={ChevronLeftIcon} /> | ||
</Button> | ||
|
||
<Button | ||
size="sm" | ||
onClick={() => { | ||
dispatch({ | ||
type: "set_offset", | ||
payload: search.offset + search.limit, | ||
}); | ||
}} | ||
> | ||
<Icon as={ChevronRightIcon} /> | ||
</Button> | ||
</ButtonGroup> | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters