Skip to content

Commit bcd447d

Browse files
committed
example: Integrate useCollections
1 parent cf60bf6 commit bcd447d

File tree

7 files changed

+29
-20
lines changed

7 files changed

+29
-20
lines changed

example/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Main from "./pages/Main";
33

44
function App() {
55
return (
6-
<div className="App h-screen grid grid-rows-[min-content_1fr]">
6+
<div className="App grid grid-rows-[min-content_1fr]">
77
<Header />
88
<main className="flex items-stretch">
99
<Main />
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import T from 'prop-types';
22

3-
export function H2({ children }) {
4-
return <h2 className='font-bold text-lg'>{children}</h2>;
3+
export function H2({ children, className }) {
4+
return <h2 className={`font-bold text-lg ${className}`}>{children}</h2>;
55
}
66

77
const Props = {
88
children: T.node.isRequired,
9+
className: T.string
910
}
1011

1112
H2.propTypes = Props;

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 ${className}`}>{ children }</div>;
4+
return <div className={`bg-slate-100 ${className}`}>{ children }</div>;
55
}
66

77
Panel.propTypes = {

example/src/layout/Section/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 Section({ children, className }) {
4-
return <div className={`my-8 ${className}`}>{ children }</div>;
4+
return <div className={`${className}`}>{ children }</div>;
55
}
66

77
Section.propTypes = {

example/src/pages/Main/ItemList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PaginationButton.propTypes = {
2929

3030
function ItemList ({ items, isLoading, error, nextPage, previousPage }) {
3131
return (
32-
<Panel className="grid grid-rows-[1fr_min-content]">
32+
<Panel className="grid grid-rows-[1fr_min-content] p-4">
3333
<div className="overflow-x-clip">
3434
<H2>Item List</H2>
3535
{isLoading && (<p>Loading...</p>)}

example/src/pages/Main/QueryBuilder.jsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import T from 'prop-types';
2-
import { useCallback } from 'react';
2+
import { useCallback, useMemo } from 'react';
3+
4+
import { useCollections, StacApi } from "stac-react";
35

46
import { PrimaryButton } from "../../components/buttons";
57
import { Checkbox, Legend } from '../../components/form';
68
import { H2 } from "../../components/headers";
79
import Panel from "../../layout/Panel";
810
import Section from '../../layout/Section';
911

10-
import { collectionsOptions } from '../../config';
11-
1212
function QueryBuilder ({
1313
setIsBboxDrawEnabled,
14-
collections,
14+
collections: selectedCollections,
1515
setCollections,
1616
handleSubmit,
1717
dateRangeFrom,
@@ -20,25 +20,33 @@ function QueryBuilder ({
2020
setDateRangeTo
2121
}) {
2222
const handleEnableBbox = useCallback(() => setIsBboxDrawEnabled(true), [setIsBboxDrawEnabled]);
23-
23+
2424
const handleRangeFromChange = useCallback((e) => setDateRangeFrom(e.target.value), [setDateRangeFrom]);
2525
const handleRangeToChange = useCallback((e) => setDateRangeTo(e.target.value), [setDateRangeTo]);
26+
27+
const stacApi = useMemo(() => new StacApi(process.env.REACT_APP_STAC_API), []);
28+
const { collections } = useCollections(stacApi);
29+
30+
const collectionOptions = useMemo(
31+
() => collections ? collections.collections.map(({ id, title }) => ({ value: id, label: title})) : [],
32+
[collections]
33+
);
2634

2735
return (
28-
<Panel>
29-
<H2>Query Builder</H2>
36+
<Panel className="py-4 grid grid-rows-[min-content_auto_min-content_min-content_min-content] gap-4 h-[calc(100vh_-_90px)]">
37+
<H2 className="px-4">Query Builder</H2>
3038

31-
<Section>
39+
<Section className="px-4 overflow-x-hidden overflow-y-auto">
3240
<Checkbox
3341
label="Select Collections"
3442
name="collections"
35-
options={collectionsOptions}
36-
values={collections}
43+
options={collectionOptions}
44+
values={selectedCollections}
3745
onChange={setCollections}
3846
/>
3947
</Section>
4048

41-
<Section>
49+
<Section className="px-4">
4250
<fieldset>
4351
<Legend>Select Date Range</Legend>
4452
<label htmlFor='date_from'>From</label>
@@ -48,11 +56,11 @@ function QueryBuilder ({
4856
</fieldset>
4957
</Section>
5058

51-
<Section>
59+
<Section className="px-4">
5260
<PrimaryButton onClick={handleEnableBbox}>Set bbox</PrimaryButton>
5361
</Section>
5462

55-
<Section>
63+
<Section className="px-4">
5664
<PrimaryButton onClick={handleSubmit}>Submit</PrimaryButton>
5765
</Section>
5866
</Panel>

example/src/pages/Main/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import QueryBuilder from "./QueryBuilder";
77

88
function Main() {
99
const [isBboxDrawEnabled, setIsBboxDrawEnabled] = useState(false);
10-
const stacApi = new StacApi(process.env.REACT_APP_STAC_API)
10+
const stacApi = new StacApi(process.env.REACT_APP_STAC_API);
1111
const {
1212
setBbox,
1313
collections,

0 commit comments

Comments
 (0)