elstat/priv/frontend/src/components/Incidents.js

42 lines
830 B
JavaScript
Raw Normal View History

import React from 'react'
import Page from './Page'
import Incident from './Incident'
import { strictFetch } from '../util'
import { domain as DOMAIN } from '../config.json'
export default class Incidents extends React.Component {
state = {
incidents: null,
page: 0,
}
2018-08-08 23:43:53 +00:00
componentDidMount() {
this.fetchIncidents()
}
2018-08-08 23:43:53 +00:00
async fetchIncidents() {
const resp = await strictFetch(`${DOMAIN}/api/incidents/${this.state.page}`)
this.setState({ incidents: await resp.json() })
}
2018-08-08 23:43:53 +00:00
renderIncidents() {
if (!this.state.incidents) {
return null
}
2018-08-08 23:43:53 +00:00
return this.state.incidents.map((incident) => (
<Incident key={incident.id} incident={incident} />
))
}
2018-08-08 23:43:53 +00:00
render() {
return (
<Page>
<h1>Incidents</h1>
{this.renderIncidents()}
</Page>
)
}
}