Skip to content
Snippets Groups Projects
Commit d51e851a authored by Manoa Harinjo's avatar Manoa Harinjo
Browse files

Merge branch 'main' of https://git.neogeo.fr/onegeo-suite/libs/gatsby-theme-onegeo into feat/menu

parents 1b81e181 d8771902
No related branches found
No related tags found
No related merge requests found
......@@ -317,6 +317,7 @@ export function Component(props: IComponent): JSX.Element
interface IMaps {
layout?: "row" | "col" | "grid"
size?: "xs" | "base" | "xl"
format?: "mapstore" | "maps"
}
export function Maps(props: IMaps): JSX.Element
......
......@@ -16,6 +16,7 @@ interface IMaps {
classname?: string
}
options?: object
format?: "mapstore" | "maps"
}
const Maps = (props: IMaps) => {
......@@ -26,6 +27,7 @@ const Maps = (props: IMaps) => {
layout = "row",
size = "xs",
limit = 3,
format = "maps",
} = props
const options = props.options ?? {}
......@@ -33,11 +35,10 @@ const Maps = (props: IMaps) => {
const [data, setData] = useState([])
const MAPS_URL =
"/geoportal/rest/geostore/extjs/search/category/MAP/***/thumbnail,details,featured?includeAttributes=true"
const mapsUrl = getMapsUrl(format, limit)
useEffect(() => {
fetch(`${MAPS_URL}&start=0&limit=${limit}`)
fetch(mapsUrl)
.then((res) => {
if (!res.ok) {
throw new Error(res.statusText)
......@@ -59,14 +60,13 @@ const Maps = (props: IMaps) => {
if (!data.length) return null
const dataCards = data.map((data: any) => {
let oData = getDataCardsByFormat(data, format)
return {
name: data.name,
description: data.description,
image: `/geoportal/${data.thumbnail}`,
size: size,
url: `/geoportal/#/context/Admin/${data.id}`,
anime: anime || options.anime,
options: options.card,
...oData,
}
})
......@@ -87,4 +87,42 @@ const Maps = (props: IMaps) => {
)
}
const isFormatMaps = (format: string) => {
return format == "maps"
}
const getMapsUrl = (format: string, limit: number) => {
let url
if (isFormatMaps(format)) {
url = `/fr/maps/maps/?format=json&q=&highlight=true&page=1&page_size=${limit}`
} else {
url = `/geoportal/rest/geostore/extjs/search/category/MAP/***/thumbnail,details,featured?includeAttributes=true&start=0&limit=${limit}`
}
return url
}
const getDataCardsByFormat = (data: any, format: string) => {
let oData
if (isFormatMaps(format)) {
oData = {
name: data.display_name,
description: data.description,
image: data.thumbnail.url,
url: `/maps/#/map/${data.id}`,
}
} else {
oData = {
name: data.name,
description: data.description,
image: `/geoportal/${data.thumbnail}`,
url: `/geoportal/#/context/Admin/${data.id}`,
}
}
return oData
}
export default Maps
......@@ -17,6 +17,7 @@ interface IMaps {
layout?: "row" | "col" | "grid"
size?: "xs" | "base" | "xl"
limit?: number
format?: "mapstore" | "maps"
}
`}</code>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment