presque finis #6 vreste plus qu'a avoir un design propres

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-04-29 15:16:17 +02:00
parent 535949a72e
commit 62444d7f7b
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16
4 changed files with 11 additions and 7 deletions

1
.gitignore vendored
View File

@ -17,7 +17,6 @@
# misc # misc
.DS_Store .DS_Store
.env*
# debug # debug
npm-debug.log* npm-debug.log*

View File

@ -1,15 +1,17 @@
import React from 'react' import React from 'react'
import Link from 'next/link'
export default class FluxItem extends React.Component { export default class FluxItem extends React.Component {
render() { render() {
const location = this.props.locations.find((el) => el.id === this.props.item.coinId)
return ( return (
<div> <div>
<img src={this.props.item.path} alt=""/> <img src={this.props.item.path} alt=""/>
<p> <p>
<span>By <a href="#!">{this.props.item.pseudo}</a></span> <span>By <Link as={`/flux?pseudo=${this.props.item.pseudo}`} href={`/flux?pseudo=${this.props.item.pseudo}`}><a>{this.props.item.pseudo}</a></Link></span>
<span>At <a href="#!">{this.props.item.location}</a></span> <span>At <Link as={`/flux?location=${this.props.item.coinId}`} href={`/flux?location=${this.props.item.coinId}`}><a>{location.name}</a></Link></span>
</p> </p>
<style jsx>{` <style jsx>{`
div { div {

View File

@ -42,7 +42,7 @@ export default async (req, res) => {
builder.pseudo = pseudo builder.pseudo = pseudo
} }
if (location) { if (location) {
builder.location = parseInt(location) builder.coinId = parseInt(location)
} }
res.end(JSON.stringify(await Photo.findAll(Object.keys(builder).length > 0 ? {where: builder} : undefined))) res.end(JSON.stringify(await Photo.findAll(Object.keys(builder).length > 0 ? {where: builder} : undefined)))

View File

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