Skip to content

Commit 9a81194

Browse files
authored
fix: collection search for collections too (#118)
1 parent 2b7a9ef commit 9a81194

File tree

3 files changed

+69
-71
lines changed

3 files changed

+69
-71
lines changed

src/components/catalog.tsx

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,13 @@
1-
import { HStack, Icon, Stack } from "@chakra-ui/react";
2-
import { LuFolderPlus, LuFolderSearch } from "react-icons/lu";
1+
import { Stack } from "@chakra-ui/react";
32
import type { StacCatalog } from "stac-ts";
4-
import useStacMap from "../hooks/stac-map";
5-
import { ChildCard } from "./children";
6-
import { CollectionSearch } from "./search/collection";
7-
import Section from "./section";
3+
import { Children } from "./children";
84
import Value from "./value";
95

106
export function Catalog({ catalog }: { catalog: StacCatalog }) {
11-
const { catalogs, collections } = useStacMap();
12-
const selfHref = catalog.links?.find((link) => link.rel === "self")?.href;
137
return (
148
<Stack>
159
<Value value={catalog}></Value>
16-
{collections && collections?.length > 0 && (
17-
<Section
18-
title={
19-
<HStack>
20-
<Icon>
21-
<LuFolderSearch></LuFolderSearch>
22-
</Icon>{" "}
23-
Collection search
24-
</HStack>
25-
}
26-
>
27-
<CollectionSearch
28-
href={selfHref}
29-
collections={collections}
30-
></CollectionSearch>
31-
</Section>
32-
)}
33-
{catalogs && catalogs.length > 0 && (
34-
<Section title="Catalogs">
35-
<Stack>
36-
{catalogs.map((catalog) => (
37-
<ChildCard
38-
child={catalog}
39-
key={"catalog-" + catalog.id}
40-
></ChildCard>
41-
))}
42-
</Stack>
43-
</Section>
44-
)}
45-
{collections && collections.length > 0 && (
46-
<Section
47-
title={
48-
<HStack>
49-
<Icon>
50-
<LuFolderPlus></LuFolderPlus>
51-
</Icon>{" "}
52-
Collections ({collections.length})
53-
</HStack>
54-
}
55-
>
56-
<Stack>
57-
{collections.map((collection) => (
58-
<ChildCard
59-
child={collection}
60-
key={"collection-" + collection.id}
61-
></ChildCard>
62-
))}
63-
</Stack>
64-
</Section>
65-
)}
10+
<Children value={catalog}></Children>
6611
</Stack>
6712
);
6813
}

src/components/children.tsx

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,71 @@
1-
import { Card, Heading, Link, Stack, Text } from "@chakra-ui/react";
1+
import { Card, HStack, Icon, Link, Stack, Text } from "@chakra-ui/react";
22
import type { ReactNode } from "react";
3+
import { LuFolderPlus, LuFolderSearch } from "react-icons/lu";
34
import { MarkdownHooks } from "react-markdown";
45
import type { StacCatalog, StacCollection } from "stac-ts";
56
import useStacMap from "../hooks/stac-map";
7+
import { CollectionSearch } from "./search/collection";
8+
import Section from "./section";
9+
10+
export function Children({ value }: { value: StacCatalog | StacCollection }) {
11+
const { catalogs, collections } = useStacMap();
12+
const selfHref = value?.links?.find((link) => link.rel === "self")?.href;
613

7-
export function Children({
8-
heading,
9-
children,
10-
}: {
11-
heading: string;
12-
children: ReactNode;
13-
}) {
1414
return (
15-
<Stack>
16-
<Heading size={"md"}>{heading}</Heading>
17-
{children}
18-
</Stack>
15+
<>
16+
{collections && collections?.length > 0 && (
17+
<Section
18+
title={
19+
<HStack>
20+
<Icon>
21+
<LuFolderSearch></LuFolderSearch>
22+
</Icon>{" "}
23+
Collection search
24+
</HStack>
25+
}
26+
>
27+
<CollectionSearch
28+
href={selfHref}
29+
collections={collections}
30+
></CollectionSearch>
31+
</Section>
32+
)}
33+
34+
{catalogs && catalogs.length > 0 && (
35+
<Section title="Catalogs">
36+
<Stack>
37+
{catalogs.map((catalog) => (
38+
<ChildCard
39+
child={catalog}
40+
key={"catalog-" + catalog.id}
41+
></ChildCard>
42+
))}
43+
</Stack>
44+
</Section>
45+
)}
46+
47+
{collections && collections.length > 0 && (
48+
<Section
49+
title={
50+
<HStack>
51+
<Icon>
52+
<LuFolderPlus></LuFolderPlus>
53+
</Icon>{" "}
54+
Collections ({collections.length})
55+
</HStack>
56+
}
57+
>
58+
<Stack>
59+
{collections.map((collection) => (
60+
<ChildCard
61+
child={collection}
62+
key={"collection-" + collection.id}
63+
></ChildCard>
64+
))}
65+
</Stack>
66+
</Section>
67+
)}
68+
</>
1969
);
2070
}
2171

src/components/collection.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
TemporalExtent as StacTemporalExtent,
77
} from "stac-ts";
88
import useStacMap from "../hooks/stac-map";
9-
import { ChildCard } from "./children";
9+
import { ChildCard, Children } from "./children";
1010
import ItemSearch from "./search/item";
1111
import Section from "./section";
1212
import Value from "./value";
@@ -15,6 +15,7 @@ export function Collection({ collection }: { collection: StacCollection }) {
1515
const { root } = useStacMap();
1616
const searchLinks =
1717
(root && root.links?.filter((link) => link.rel == "search")) || [];
18+
1819
return (
1920
<Stack>
2021
<Value value={collection}>
@@ -35,6 +36,8 @@ export function Collection({ collection }: { collection: StacCollection }) {
3536
<ItemSearch collection={collection} links={searchLinks}></ItemSearch>
3637
</Section>
3738
)}
39+
40+
<Children value={collection}></Children>
3841
</Stack>
3942
);
4043
}

0 commit comments

Comments
 (0)