This repository has been archived on 2023-06-06. You can view files and clone it, but cannot push or open issues or pull requests.
IMIE_CC/pages/flux.jsx
Florian Bouillon 62444d7f7b
presque finis #6 vreste plus qu'a avoir un design propres
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-04-29 15:16:17 +02:00

30 lines
827 B
JavaScript

import React from 'react'
import FluxItem from '../components/FluxItem'
import fetch from 'isomorphic-unfetch'
export default class Flux extends React.Component {
static async getInitialProps(ctx) {
const coindId = ctx.query.location
const pseudo = ctx.query.pseudo
let hostname = ''
if (ctx.req) {
hostname = `http://${ctx.req.headers.host}`
}
const data = await (await fetch(`${hostname}/api/photos${pseudo ? `?pseudo=${pseudo}${coindId && `&location=${coindId}` || ''}` : `${coindId && `?location=${coindId}` || ''}`}`)).json()
const locations = await (await fetch(`${hostname}/api/coins`)).json()
return {data, locations}
}
render() {
return (
<div>
{this.props.data.map((el, index) => (
<FluxItem key={index} item={el} locations={this.props.locations} />
))}
</div>
)
}
}