From f14d1fd016c629eea0f352b10ab69cd44f422737 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Thu, 2 Oct 2025 15:48:07 -0600 Subject: [PATCH] fix: re-add download buttons --- src/components/item-search.tsx | 48 +++++++++++++++++++++++++++++++++- tests/app.spec.tsx | 17 ++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/components/item-search.tsx b/src/components/item-search.tsx index 40ffcb0..d7e7c1d 100644 --- a/src/components/item-search.tsx +++ b/src/components/item-search.tsx @@ -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, @@ -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"; @@ -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 ( Search results @@ -230,6 +249,33 @@ function Search({ Clear + {items && items.length > 0 && ( + <> + Download + + + + + + + + + + )} ); } diff --git a/tests/app.spec.tsx b/tests/app.spec.tsx index a3d8806..1daf83b 100644 --- a/tests/app.spec.tsx +++ b/tests/app.spec.tsx @@ -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(); + }); });