dynamic plane info page

This commit is contained in:
Nilstrieb 2021-02-14 15:09:42 +01:00
parent 0d1cf198b3
commit 295bdd927c
13 changed files with 132 additions and 12 deletions

40
src/Planes.js Normal file
View file

@ -0,0 +1,40 @@
import React, {Component} from 'react';
import planes from './planes.json'
class Planes extends Component {
render() {
const loc = this.props.location.pathname;
const planeName = loc.replaceAll('/flugzeug/', '');
let plane;
for (const e of planes) {
if (e.category + e.name === planeName) {
plane = e;
break;
}
}
let content;
if (plane === undefined) {
content =
<div>
<h2>Flugzeug nicht gefunden.</h2>
</div>
;
} else {
const imgPath = process.env.PUBLIC_URL + '/img/' + plane.category + plane.img;
content =
<div>
<h2>{plane.name}</h2>
<img src={imgPath} alt={'Bild von ' + plane.name}/>
<p>{plane.description}</p>
</div>
;
}
return (
content
);
}
}
export default Planes;