mirror of
https://github.com/Noratrieb/hugos-lieblingsflugzeuge.git
synced 2026-01-16 20:55:05 +01:00
dynamic plane info page
This commit is contained in:
parent
0d1cf198b3
commit
295bdd927c
13 changed files with 132 additions and 12 deletions
40
src/Planes.js
Normal file
40
src/Planes.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue