|
1 | | -import { useState } from "react"; |
| 1 | +import { useEffect, useState } from "react"; |
2 | 2 | import { LuDownload } from "react-icons/lu"; |
3 | 3 | import { |
4 | 4 | Button, |
5 | 5 | ButtonGroup, |
6 | 6 | Card, |
| 7 | + Checkbox, |
7 | 8 | Collapsible, |
8 | 9 | DataList, |
9 | 10 | HStack, |
10 | 11 | Image, |
| 12 | + Span, |
11 | 13 | } from "@chakra-ui/react"; |
12 | 14 | import type { StacAsset } from "stac-ts"; |
13 | 15 | import Properties from "./properties"; |
14 | 16 | import type { StacAssets } from "../types/stac"; |
| 17 | +import { isCog, isVisual } from "../utils/stac"; |
15 | 18 |
|
16 | | -export default function Assets({ assets }: { assets: StacAssets }) { |
| 19 | +export default function Assets({ |
| 20 | + assets, |
| 21 | + cogTileHref, |
| 22 | + setCogTileHref, |
| 23 | +}: { |
| 24 | + assets: StacAssets; |
| 25 | + cogTileHref: string | undefined; |
| 26 | + setCogTileHref: (href: string | undefined) => void; |
| 27 | +}) { |
17 | 28 | return ( |
18 | 29 | <DataList.Root> |
19 | 30 | {Object.keys(assets).map((key) => ( |
20 | 31 | <DataList.Item key={"asset-" + key}> |
21 | 32 | <DataList.ItemLabel>{key}</DataList.ItemLabel> |
22 | 33 | <DataList.ItemValue> |
23 | | - <Asset asset={assets[key]} /> |
| 34 | + <Asset |
| 35 | + asset={assets[key]} |
| 36 | + cogTileHref={cogTileHref} |
| 37 | + setCogTileHref={setCogTileHref} |
| 38 | + /> |
24 | 39 | </DataList.ItemValue> |
25 | 40 | </DataList.Item> |
26 | 41 | ))} |
27 | 42 | </DataList.Root> |
28 | 43 | ); |
29 | 44 | } |
30 | 45 |
|
31 | | -function Asset({ asset }: { asset: StacAsset }) { |
| 46 | +function Asset({ |
| 47 | + asset, |
| 48 | + cogTileHref, |
| 49 | + setCogTileHref, |
| 50 | +}: { |
| 51 | + asset: StacAsset; |
| 52 | + cogTileHref: string | undefined; |
| 53 | + setCogTileHref: (href: string | undefined) => void; |
| 54 | +}) { |
32 | 55 | const [imageError, setImageError] = useState(false); |
| 56 | + const [checked, setChecked] = useState(false); |
33 | 57 | // eslint-disable-next-line |
34 | 58 | const { href, roles, type, title, ...properties } = asset; |
35 | 59 |
|
| 60 | + useEffect(() => { |
| 61 | + setChecked(cogTileHref === asset.href); |
| 62 | + }, [cogTileHref, asset.href]); |
| 63 | + |
36 | 64 | return ( |
37 | 65 | <Card.Root size={"sm"} w="full"> |
38 | 66 | <Card.Header> |
@@ -64,7 +92,24 @@ function Asset({ asset }: { asset: StacAsset }) { |
64 | 92 | </Collapsible.Content> |
65 | 93 | </Collapsible.Root> |
66 | 94 | )} |
67 | | - <HStack justify={"right"}> |
| 95 | + <HStack> |
| 96 | + {isCog(asset) && isVisual(asset) && ( |
| 97 | + <Checkbox.Root |
| 98 | + checked={checked} |
| 99 | + onCheckedChange={(e) => { |
| 100 | + setChecked(!!e.checked); |
| 101 | + if (e.checked) setCogTileHref(asset.href); |
| 102 | + else setCogTileHref(undefined); |
| 103 | + }} |
| 104 | + > |
| 105 | + <Checkbox.HiddenInput /> |
| 106 | + <Checkbox.Control /> |
| 107 | + <Checkbox.Label>Visualize</Checkbox.Label> |
| 108 | + </Checkbox.Root> |
| 109 | + )} |
| 110 | + |
| 111 | + <Span flex={"1"} /> |
| 112 | + |
68 | 113 | <ButtonGroup size="sm" variant="outline"> |
69 | 114 | <Button asChild> |
70 | 115 | <a href={asset.href} target="_blank"> |
|
0 commit comments