-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathCatalogGrid.js
More file actions
88 lines (82 loc) · 2.71 KB
/
Copy pathCatalogGrid.js
File metadata and controls
88 lines (82 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { useEffect, useState } from "react";
import { ComponentsWrapper } from "./Component.style";
import { CatalogCard, SistentThemeProviderWithoutBaseLine } from "@sistent/sistent";
import axios from "axios";
import { useStyledDarkMode } from "../../../../theme/app/useStyledDarkMode";
import Button from "../../../../reusecore/Button";
const CatalogGrid = ({ frontmatter }) => {
const [designs, setDesign] = useState();
const technology = frontmatter.docURL.split("/");
const [designSize, setDesignSize] = useState(5);
const { isDark } = useStyledDarkMode();
useEffect(() => {
const CLOUD_FETCH_DESIGN = `https://cloud.layer5.io/api/catalog/content/pattern?technology=${
technology[technology.length - 1]
}&page=0&pagesize=${designSize}&search=&order=&metrics=true`;
const fetchData = async () => {
try {
// const token = getCookieValue("provider_token");
const response = await axios.get(CLOUD_FETCH_DESIGN);
if (response.status !== 200) {
throw new Error("Network response was not ok");
}
const data = response.data;
setDesign(data);
} catch (error) {
console.error("There was a problem with your fetch operation:", error);
}
};
fetchData();
}, [designSize]);
return designs && designs.total_count > 0 ? (
<ComponentsWrapper
style={{
display: "flex",
alignItems: "center",
flexDirection: "column",
}}
>
<section className="heading">
<h1>
{frontmatter.title} Designs ({designs.total_count})
</h1>
</section>
<section className="componentsSection">
<SistentThemeProviderWithoutBaseLine initialMode={isDark ? "dark" : "light"}>
{designs?.patterns?.map((item, index) => {
return (
<CatalogCard
key={index}
onCardClick={() => {
window.open(
`https://cloud.layer5.io/catalog/content/catalog/${item?.id}`,
"_blank",
"noopener,noreferrer"
);
}}
cardHeight="20rem"
cardWidth="16rem"
pattern={item}
type="Catalog"
patternType={item?.catalog_data?.type}
/>
);
})}
</SistentThemeProviderWithoutBaseLine>
</section>
{designSize <= designs?.total_count && (
<Button
$primary
className="loadmore"
title="Load More"
onClick={() => {
setDesignSize((prev) => prev + 5);
}}
/>
)}
</ComponentsWrapper>
) : (
<></>
);
};
export default CatalogGrid;