Newer
Older
import Map from "../core/Map"
import News from "../News"
import Stats from "../Stats"
import Hero from "../Hero"
import Image from "../core/Image"
interface IAction {
actions_id: {
name: string
url: string
style: string
}
}
interface IService {
services_id: {
name: string
url: string
description: string
image: {
}
}
}
interface Iimage {
directus_files_id: {
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
}
}
interface IComponent {
type: string
actions: IAction[] | []
mapdid: string
title: string
subtitle: string
content: string
url_dataviz: string
url_map: string
layout: string
length: number
size: string
services: IService[] | []
images: Iimage[] | []
}
const getActions = (actionsProps: IAction[] | []) => {
if (!actionsProps.length) return undefined
return actionsProps.map((action_id) => {
let action = action_id.actions_id
return {
...action,
classname: action.style,
}
})
}
const getServices = (servicesProps: IService[] | []) => {
if (!servicesProps.length) return undefined
return servicesProps.map((services_id) => {
let service = services_id.services_id
return {
...service,
}
})
}
const getImages = (imagesProps: Iimage[] | []) => {
if (!imagesProps.length) return undefined
return imagesProps.map((images) => {
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
})
}
const Component = (props: IComponent) => {
const {
type,
actions: actionsProps = [],
services: servicesProps = [],
images: imagesProps = [],
mapdid,
...restProps
} = props
const actions = getActions(actionsProps)
const services = getServices(servicesProps)
const images = getImages(imagesProps)
switch (type) {
case "news":
let newsaction = actions?.length ? actions[0] : undefined
return (
<div>
<News {...restProps} action={newsaction} />
</div>
)
case "maps":
return <div>Liste des cartes</div>
case "map":
if (!mapdid) return <div>Map</div>
return (
<div className="h-full w-full min-h-[500px]">
<Map {...restProps} mapid={parseInt(mapdid)} />
</div>
)
case "data":
return <div>Liste des données</div>
case "stats":
return <Stats {...restProps} />
case "hero":
let heroaction = actions?.length
? actions[0]
: { title: "", to: "" }
return (
<Hero
services={services!}
{...restProps}
action={heroaction!}
/>
)
case "text":
return <div>Texte</div>
case "image":
let img = images?.length ? images[0] : undefined
return (
<>
<Image image={img} />
</>
)
case "mapgl":
return <div>Carte Maplibre</div>
case "geoportal":
return <div>Cartes, Tableaux de bord, Geostories</div>
case "dataviz":
return <div>Data visualisation</div>
case "events":
return <div>Liste des événements</div>
}
return <div></div>
}
export default Component