Skip to content
Merged
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
48 changes: 47 additions & 1 deletion src/components/item-search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { useEffect, useMemo, useState } from "react";
import { LuPause, LuPlay, LuSearch, LuStepForward, LuX } from "react-icons/lu";
import {
LuDownload,
LuPause,
LuPlay,
LuSearch,
LuStepForward,
LuX,
} from "react-icons/lu";
import {
Alert,
Button,
ButtonGroup,
createListCollection,
DownloadTrigger,
Field,
Group,
Heading,
Expand All @@ -25,6 +33,7 @@ import type {
StacLink,
TemporalExtent,
} from "stac-ts";
import * as stac_wasm from "stac-wasm";
import { SpatialExtent } from "./extent";
import useStacSearch from "../hooks/stac-search";
import type { BBox2D } from "../types/map";
Expand Down Expand Up @@ -175,6 +184,16 @@ function Search({
setItems(items);
}, [items, setItems]);

const downloadJson = () => {
return JSON.stringify(
items ? { type: "FeatureCollection", features: items } : {}
);
};

const downloadStacGeoparquet = () => {
return new Blob(items ? [stac_wasm.stacJsonToParquet(items)] : []);
};

return (
<Stack gap={4}>
<Heading size={"md"}>Search results</Heading>
Expand Down Expand Up @@ -230,6 +249,33 @@ function Search({
Clear <LuX />
</Button>
</ButtonGroup>
{items && items.length > 0 && (
<>
<Heading size={"sm"}>Download</Heading>
<ButtonGroup variant={"surface"} size={"xs"}>
<DownloadTrigger
data={downloadJson}
fileName="search.json"
mimeType="application/json"
asChild
>
<Button>
JSON <LuDownload />
</Button>
</DownloadTrigger>
<DownloadTrigger
data={downloadStacGeoparquet}
fileName="search.parquet"
mimeType="application/json"
asChild
>
<Button>
stac-geoparquet <LuDownload />
</Button>
</DownloadTrigger>
</ButtonGroup>
</>
)}
</Stack>
);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ describe("app", () => {
.element(app.getByRole("heading", { name: "Planet" }))
.toBeVisible();
});

test("renders download buttons", async () => {
window.history.pushState(
{},
"",
"?href=https://stac.eoapi.dev/collections/MAXAR_yellowstone_flooding22"
);
const app = renderApp();
await app.getByRole("button", { name: "Item search" }).click();
await app.getByRole("button", { name: "Search", exact: true }).click();
await expect
.element(app.getByRole("button", { name: "JSON" }))
.toBeVisible();
await expect
.element(app.getByRole("button", { name: "stac-geoparquet" }))
.toBeVisible();
});
});