#7 done (c'est moche mais TG)

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-04-29 16:01:21 +02:00
parent 62444d7f7b
commit 4fb0eaa4dd
2 changed files with 91 additions and 0 deletions

32
pages/coins.jsx Normal file
View File

@ -0,0 +1,32 @@
import React from 'react'
import CoinItem from '../components/CoinItem'
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`)).json()
const locations = await (await fetch(`${hostname}/api/coins`)).json()
return {data, locations}
}
render() {
return (
<div>
{this.props.locations.map((el, index) => {
// console.log(el, this.props.data.filter((item) => item.coinId == el.id))
return (
<CoinItem key={index} item={el} photos={this.props.data.filter((item) => item.coinId == el.id)} />
)
})}
</div>
)
}
}