Factorise code

This commit is contained in:
Adrien Vannson 2023-03-06 11:23:24 +01:00
parent 6bef1fa4c7
commit 878f0fd50a
No known key found for this signature in database
GPG Key ID: FE2E66FD978C1A55

View File

@ -184,45 +184,43 @@ function newPolygon(element, positions, selectedRoom, callbackRoomSelected, call
// as well as a callback to display the room informations when the user clicks on the room // as well as a callback to display the room informations when the user clicks on the room
// and for S or L, we add a Popup with the list of connected floors and possibility to load the // and for S or L, we add a Popup with the list of connected floors and possibility to load the
// map of a connected floor // map of a connected floor
const color = selectedRoom === element["id"] ? 'red' : 'grey'; const color = selectedRoom === element['id'] ? 'red' : 'grey';
if (element["type"] === "S") {
// In this case, the room is a staircase so we add a Stairs component if (element['type'] === 'C') { // Corridor
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}> return <Polygon positions={positions} key={element['id'] + color} color={'peru'} />
<Tooltip>{roomNameList(element["names"])}</Tooltip>
<Stairs position={polygonCenter(positions)} size={logoSize(positions)} body={<Popup>
{floorList(element["connectedFloors"], callbackChangeFloor)}
</Popup>
}
/>
</Polygon>
} }
else if (element["type"] === "L") {
// In this case the room is a lift so we add a Lift component var content = <></>
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}> if (element['type'] === 'S') { // Stair
<Tooltip>{roomNameList(element["names"])}</Tooltip> content = <Stairs
<Lift position={polygonCenter(positions)} size={logoSize(positions)} body={<Popup> position={polygonCenter(positions)}
{floorList(element["connectedFloors"], callbackChangeFloor)} size={logoSize(positions)}
</Popup> body={<Popup>
} {floorList(element['connectedFloors'], callbackChangeFloor)}
/> </Popup>}
</Polygon> />
} } else if (element['type'] === 'L') { // Lift
else if (element["type"] === "T") { content = <Lift
return <Polygon positions={positions} key={element["id"] + color} color={color} evenHandlers={{ click: () => callbackRoomSelected(element["id"]) }}> position={polygonCenter(positions)}
<Tooltip>{roomNameList(element["names"])}</Tooltip> size={logoSize(positions)}
<Toilet position={polygonCenter(positions)} size={logoSize(positions)} /> body={<Popup>
</Polygon> {floorList(element['connectedFloors'], callbackChangeFloor)}
} </Popup>}
else if (element["type"] === "R") { />
// In this case it is a regular room } else if (element['type'] === 'T') { // Toilets
return <Polygon positions={positions} key={element["id"] + color} color={color} eventHandlers={{ click: () => callbackRoomSelected(element["id"]) }}> content = <Toilet position={polygonCenter(positions)} size={logoSize(positions)} />
<Tooltip>{roomNameList(element["names"])}</Tooltip>
</Polygon>
}
else if (element["type"] === "C") {
// In this case it is a corridor
return <Polygon positions={positions} key={element["id"] + color} color={"peru"} />
} }
return <Polygon
positions={positions}
key={element["id"] + color}
color={color}
eventHandlers={{ click: () => callbackRoomSelected(element["id"]) }}
>
<Tooltip>{roomNameList(element["names"])}</Tooltip>
{content}
</Polygon>
} }
function list_polygons(request, center, callbackRoomSelected, selectedRoom, callbackChangeFloor) { function list_polygons(request, center, callbackRoomSelected, selectedRoom, callbackChangeFloor) {