Skip to content

Commit cf7a136

Browse files
committed
Add pagination buttons
1 parent d8c44c4 commit cf7a136

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

example/src/components/buttons/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const DefaultButtonType = {
1111
className: T.string,
1212
}
1313

14-
function Button({ type, className, children, onClick }) {
14+
export function Button({ type, className, children, onClick }) {
1515
return (
1616
<button
1717
type={type}

example/src/layout/Panel/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import T from 'prop-types';
22

33
function Panel({ children, className }) {
4-
return <div className={`bg-slate-100 p-4 overflow-x-clip overflow-y-auto ${className}`}>{ children }</div>;
4+
return <div className={`bg-slate-100 p-4 ${className}`}>{ children }</div>;
55
}
66

77
Panel.propTypes = {

example/src/pages/Main/ItemList.jsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,59 @@ import { TItemList } from "./proptypes";
33

44
import { H2 } from "../../components/headers";
55
import Panel from "../../layout/Panel";
6+
import { Button } from "../../components/buttons";
67

78

89

9-
function ItemList ({ items, isLoading, error }) {
10+
function PaginationButton ({disabled, onClick, children}) {
1011
return (
11-
<Panel>
12-
<H2>Item List</H2>
13-
{isLoading && (<p>Loading...</p>)}
14-
{error && (<p>{ error }</p>)}
15-
{items && (
16-
<ul>
17-
{items.features.map(({ id }) => (
18-
<li key={id}>{ id }</li>
19-
))}
20-
</ul>
21-
)}
12+
<Button
13+
disabled={disabled}
14+
onClick={onClick}
15+
className="bg-slate-500 text-white"
16+
>
17+
{children}
18+
</Button>
19+
);
20+
}
21+
22+
PaginationButton.propTypes = {
23+
disabled: T.bool,
24+
onClick: T.func.isRequired,
25+
children: T.node.isRequired
26+
}
27+
28+
29+
30+
function ItemList ({ items, isLoading, error, nextPage, previousPage }) {
31+
return (
32+
<Panel className="grid grid-rows-[1fr_min-content]">
33+
<div className="overflow-x-clip">
34+
<H2>Item List</H2>
35+
{isLoading && (<p>Loading...</p>)}
36+
{error && (<p>{ error }</p>)}
37+
{items && (
38+
<ul>
39+
{items.features.map(({ id }) => (
40+
<li key={id}>{ id }</li>
41+
))}
42+
</ul>
43+
)}
44+
</div>
45+
<div className="grid grid-cols-2 gap-4">
46+
<PaginationButton disabled={!previousPage} onClick={previousPage}>Previous page</PaginationButton>
47+
<PaginationButton disabled={!nextPage} onClick={nextPage}>Next page</PaginationButton>
48+
</div>
2249
</Panel>
2350
);
2451
}
2552

2653
ItemList.propTypes = {
2754
items: TItemList,
2855
isLoading: T.bool,
29-
error: T.string
56+
error: T.string,
57+
previousPage: T.func,
58+
nextPage: T.func
3059
}
3160

3261
export default ItemList;

example/src/pages/Main/index.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function Main() {
1919
submit,
2020
results,
2121
state,
22-
error
22+
error,
23+
nextPage,
24+
previousPage
2325
} = useStacSearch(stacApi);
2426

2527
const handleDrawComplete = useCallback((feature) => {
@@ -42,7 +44,13 @@ function Main() {
4244
dateRangeTo={dateRangeTo}
4345
setDateRangeTo={setDateRangeTo}
4446
/>
45-
<ItemList items={results} isLoading={state === 'LOADING'} error={error && 'Error loading results'} />
47+
<ItemList
48+
items={results}
49+
isLoading={state === 'LOADING'}
50+
error={error && 'Error loading results'}
51+
nextPage={nextPage}
52+
previousPage={previousPage}
53+
/>
4654
<Map
4755
className='col-span-2'
4856
isBboxDrawEnabled={isBboxDrawEnabled}

0 commit comments

Comments
 (0)