1- import { useEffect , useState } from "react" ;
2- import { LuDownload } from "react-icons/lu" ;
3- import {
4- Button ,
5- ButtonGroup ,
6- Card ,
7- Checkbox ,
8- Collapsible ,
9- DataList ,
10- HStack ,
11- Image ,
12- Span ,
13- } from "@chakra-ui/react" ;
14- import type { StacAsset } from "stac-ts" ;
15- import Properties from "./properties" ;
1+ import { LuFiles } from "react-icons/lu" ;
2+ import { DataList } from "@chakra-ui/react" ;
163import type { StacAssets } from "../../types/stac" ;
17- import { isCog , isVisual } from "../../utils/stac" ;
4+ import AssetCard from "../cards/asset" ;
5+ import Section from "../section" ;
186
19- export default function Assets ( {
20- assets,
21- cogTileHref,
22- setCogTileHref,
23- } : {
7+ interface AssetsProps {
248 assets : StacAssets ;
259 cogTileHref : string | undefined ;
2610 setCogTileHref : ( href : string | undefined ) => void ;
27- } ) {
11+ }
12+
13+ export default function AssetsSection ( { ...props } : AssetsProps ) {
14+ return (
15+ < Section title = "Assets" TitleIcon = { LuFiles } value = "assets" >
16+ < Assets { ...props } />
17+ </ Section >
18+ ) ;
19+ }
20+
21+ function Assets ( { assets, cogTileHref, setCogTileHref } : AssetsProps ) {
2822 return (
2923 < DataList . Root >
3024 { Object . keys ( assets ) . map ( ( key ) => (
3125 < DataList . Item key = { "asset-" + key } >
3226 < DataList . ItemLabel > { key } </ DataList . ItemLabel >
3327 < DataList . ItemValue >
34- < Asset
28+ < AssetCard
3529 asset = { assets [ key ] }
3630 cogTileHref = { cogTileHref }
3731 setCogTileHref = { setCogTileHref }
@@ -42,83 +36,3 @@ export default function Assets({
4236 </ DataList . Root >
4337 ) ;
4438}
45-
46- function Asset ( {
47- asset,
48- cogTileHref,
49- setCogTileHref,
50- } : {
51- asset : StacAsset ;
52- cogTileHref : string | undefined ;
53- setCogTileHref : ( href : string | undefined ) => void ;
54- } ) {
55- const [ imageError , setImageError ] = useState ( false ) ;
56- const [ checked , setChecked ] = useState ( false ) ;
57- // eslint-disable-next-line
58- const { href, roles, type, title, ...properties } = asset ;
59-
60- useEffect ( ( ) => {
61- setChecked ( cogTileHref === asset . href ) ;
62- } , [ cogTileHref , asset . href ] ) ;
63-
64- return (
65- < Card . Root size = { "sm" } w = "full" >
66- < Card . Header >
67- { asset . title && < Card . Title > { asset . title } </ Card . Title > }
68- </ Card . Header >
69- < Card . Body gap = { 6 } >
70- { ! imageError && (
71- < Image src = { asset . href } onError = { ( ) => setImageError ( true ) } />
72- ) }
73- < DataList . Root orientation = { "horizontal" } >
74- { asset . roles && (
75- < DataList . Item >
76- < DataList . ItemLabel > Roles</ DataList . ItemLabel >
77- < DataList . ItemValue > { asset . roles ?. join ( ", " ) } </ DataList . ItemValue >
78- </ DataList . Item >
79- ) }
80- { asset . type && (
81- < DataList . Item >
82- < DataList . ItemLabel > Type</ DataList . ItemLabel >
83- < DataList . ItemValue > { asset . type } </ DataList . ItemValue >
84- </ DataList . Item >
85- ) }
86- </ DataList . Root >
87- { Object . keys ( properties ) . length > 0 && (
88- < Collapsible . Root >
89- < Collapsible . Trigger > Properties</ Collapsible . Trigger >
90- < Collapsible . Content >
91- < Properties properties = { properties } />
92- </ Collapsible . Content >
93- </ Collapsible . Root >
94- ) }
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-
113- < ButtonGroup size = "sm" variant = "outline" >
114- < Button asChild >
115- < a href = { asset . href } target = "_blank" >
116- < LuDownload /> Download
117- </ a >
118- </ Button >
119- </ ButtonGroup >
120- </ HStack >
121- </ Card . Body >
122- </ Card . Root >
123- ) ;
124- }
0 commit comments