Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 84 additions & 74 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
isItemInDatetimeBounds,
isVisual,
} from "./utils/stac";
import { StacApiProvider } from "@developmentseed/stac-react";

Check failure on line 19 in src/app.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@developmentseed/stac-react' or its corresponding type declarations.

// TODO make this configurable by the user.
const lineColor: Color = [207, 63, 2, 100];
Expand All @@ -33,6 +34,8 @@
const [filter, setFilter] = useState(true);
const [stacGeoparquetItemId, setStacGeoparquetItemId] = useState<string>();
const [cogTileHref, setCogTileHref] = useState<string>();
const [filteredCollections, setFilteredCollections] = useState<StacCollection[] | undefined>();
const [collections, setFinalCollections] = useState<StacCollection[] | undefined>();

// Derived state
const {
Expand All @@ -52,20 +55,9 @@
value,
enabled: !!value && !collectionsLink,
});
const collections = collectionsLink ? userCollections : linkedCollections;

const items = userItems || linkedItems;
const filteredCollections = useMemo(() => {
if (filter && collections) {
return collections.filter(
(collection) =>
(!bbox || isCollectionInBbox(collection, bbox)) &&
(!datetimeBounds ||
isCollectionInDatetimeBounds(collection, datetimeBounds))
);
} else {
return undefined;
}
}, [collections, filter, bbox, datetimeBounds]);

const filteredItems = useMemo(() => {
if (filter && items) {
return items.filter(
Expand All @@ -79,6 +71,22 @@
}, [items, filter, bbox, datetimeBounds]);

// Effects
useEffect(() => {
setFinalCollections(collectionsLink ? userCollections : linkedCollections);
}, [collectionsLink, userCollections, linkedCollections]);

useEffect(() => {
if(filter && collections) {
const filtered = collections.filter(
(collection) =>
(!bbox || isCollectionInBbox(collection, bbox)) &&
(!datetimeBounds ||
isCollectionInDatetimeBounds(collection, datetimeBounds))
);
setFilteredCollections(filtered ?? undefined)
}
}, [filter, collections, userCollections, bbox, datetimeBounds]);

useEffect(() => {
function handlePopState() {
setHref(new URLSearchParams(location.search).get("href") ?? "");
Expand Down Expand Up @@ -137,67 +145,69 @@

return (
<>
<Box h={"100dvh"}>
<FileUpload.RootProvider value={fileUpload} unstyled={true}>
<FileUpload.Dropzone
disableClick={true}
style={{
height: "100dvh",
width: "100dvw",
}}
>
<Map
value={value}
table={table}
collections={collections}
filteredCollections={filteredCollections}
items={items}
filteredItems={filteredItems}
fillColor={fillColor}
lineColor={lineColor}
setBbox={setBbox}
picked={picked}
setPicked={setPicked}
setStacGeoparquetItemId={setStacGeoparquetItemId}
cogTileHref={cogTileHref}
></Map>
</FileUpload.Dropzone>
</FileUpload.RootProvider>
</Box>
<Container
zIndex={1}
fluid
h="100dvh"
pointerEvents={"none"}
position={"absolute"}
top={0}
left={0}
pt={4}
>
<Overlay
href={href}
setHref={setHref}
fileUpload={fileUpload}
value={value}
error={error}
catalogs={catalogs}
setCollections={setCollections}
collections={collections}
filteredCollections={filteredCollections}
filter={filter}
setFilter={setFilter}
bbox={bbox}
setPicked={setPicked}
picked={picked}
items={items}
filteredItems={filteredItems}
setItems={setItems}
setDatetimeBounds={setDatetimeBounds}
cogTileHref={cogTileHref}
setCogTileHref={setCogTileHref}
></Overlay>
</Container>
<Toaster></Toaster>
<StacApiProvider apiUrl={href || ""}>
<Box h={"100dvh"}>
<FileUpload.RootProvider value={fileUpload} unstyled={true}>
<FileUpload.Dropzone
disableClick={true}
style={{
height: "100dvh",
width: "100dvw",
}}
>
<Map
value={value}
table={table}
collections={collections}
filteredCollections={filteredCollections}
items={items}
filteredItems={filteredItems}
fillColor={fillColor}
lineColor={lineColor}
setBbox={setBbox}
picked={picked}
setPicked={setPicked}
setStacGeoparquetItemId={setStacGeoparquetItemId}
cogTileHref={cogTileHref}
></Map>
</FileUpload.Dropzone>
</FileUpload.RootProvider>
</Box>
<Container
zIndex={1}
fluid
h="100dvh"
pointerEvents={"none"}
position={"absolute"}
top={0}
left={0}
pt={4}
>
<Overlay
href={href}
setHref={setHref}
fileUpload={fileUpload}
value={value}
error={error}
catalogs={catalogs}
setCollections={setCollections}
collections={collections}
filteredCollections={filteredCollections}
filter={filter}
setFilter={setFilter}
bbox={bbox}
setPicked={setPicked}
picked={picked}
items={items}
filteredItems={filteredItems}
setItems={setItems}
setDatetimeBounds={setDatetimeBounds}
cogTileHref={cogTileHref}
setCogTileHref={setCogTileHref}
></Overlay>
</Container>
<Toaster></Toaster>
</StacApiProvider>
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Panel({
);
else if (href) {
if (value) {
return <Value href={href} value={value} setHref={setHref} {...props} />;
return <Value key={href} href={href} value={value} setHref={setHref} {...props} />;
} else {
return <SkeletonText />;
}
Expand Down
42 changes: 24 additions & 18 deletions src/components/value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
import LinksSection from "./sections/links";
import PropertiesSection from "./sections/properties";
import { Prose } from "./ui/prose";
import useStacCollections from "../hooks/stac-collections";
// import useStacCollections from "../hooks/stac-collections";
import type { BBox2D } from "../types/map";
import type { DatetimeBounds, StacSearch, StacValue } from "../types/stac";
import { deconstructStac, fetchStac, getImportantLinks } from "../utils/stac";

import { useCollections } from "@developmentseed/stac-react";

Check failure on line 45 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@developmentseed/stac-react' or its corresponding type declarations.

export interface SharedValueProps {
catalogs: StacCatalog[] | undefined;
setCollections: (collections: StacCollection[] | undefined) => void;
Expand Down Expand Up @@ -96,7 +98,7 @@
// the properties.
if (properties?.description) delete properties["description"];

const { rootLink, collectionsLink, nextLink, prevLink, filteredLinks } =

Check failure on line 101 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / CI

'collectionsLink' is assigned a value but never used

Check failure on line 101 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / build

'collectionsLink' is declared but its value is never read.
useMemo(() => {
return getImportantLinks(links);
}, [links]);
Expand All @@ -111,7 +113,8 @@
return rootData.data?.links?.filter((link) => link.rel === "search");
}, [rootData.data]);

const collectionsResult = useStacCollections(collectionsLink?.href);
const collectionsResult = useCollections();
console.log(`collectionsResult: `, collectionsResult)

const thumbnailAsset = useMemo(() => {
return (
Expand All @@ -124,21 +127,24 @@
}, [assets]);

useEffect(() => {
setCollections(
collectionsResult.data?.pages.flatMap((page) => page?.collections || [])
);
if (collectionsResult.data?.pages.at(0)?.numberMatched)
setNumberOfCollections(collectionsResult.data?.pages[0]?.numberMatched);
}, [collectionsResult.data, setCollections]);
if (fetchAllCollections) {
setCollections((previous) => [...previous, ...collectionsResult.collections?.collections || []]);

Check failure on line 131 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / build

Parameter 'previous' implicitly has an 'any' type.

Check failure on line 131 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type '(previous: any) => any[]' is not assignable to parameter of type 'StacCollection[]'.
} else {
setCollections(
collectionsResult.collections?.collections || []
);
setNumberOfCollections(collectionsResult.collections?.numberMatched);
}
}, [fetchAllCollections, collectionsResult.collections]);

Check warning on line 138 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / CI

React Hook useEffect has a missing dependency: 'setCollections'. Either include it or remove the dependency array. If 'setCollections' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
if (
fetchAllCollections &&
!collectionsResult.isFetching &&
collectionsResult.hasNextPage
)
collectionsResult.fetchNextPage();
}, [fetchAllCollections, collectionsResult]);
collectionsResult.nextPage
) {
collectionsResult.nextPage?.();
}
}, [fetchAllCollections, collectionsResult.nextPage]);

Check warning on line 147 in src/components/value.tsx

View workflow job for this annotation

GitHub Actions / CI

React Hook useEffect has a missing dependency: 'collectionsResult'. Either include it or remove the dependency array

useEffect(() => {
setFetchAllCollections(false);
Expand Down Expand Up @@ -224,21 +230,20 @@
</ButtonGroup>
)}

{collectionsResult.hasNextPage && (
{collectionsResult.nextPage && (
<Card.Root size={"sm"} variant={"outline"}>
<Card.Header>
<Heading size={"sm"}>Collection pagination</Heading>
</Card.Header>
<Card.Body>
<ButtonGroup size={"xs"} variant={"surface"}>
<Button
disabled={fetchAllCollections || collectionsResult.isFetching}
disabled={fetchAllCollections}
onClick={() => {
if (
!collectionsResult.isFetching &&
collectionsResult.hasNextPage
collectionsResult.nextPage
)
collectionsResult.fetchNextPage();
collectionsResult.nextPage?.();
}}
>
Fetch more collections <LuStepForward />
Expand All @@ -261,6 +266,7 @@
</Card.Root>
)}


<Accordion.Root multiple size={"sm"} variant={"enclosed"}>
{catalogs && catalogs.length > 0 && (
<CatalogsSection catalogs={catalogs} setHref={setHref} />
Expand Down
Loading