Skip to content

Commit

Permalink
fix no result
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelkausari committed Mar 3, 2018
1 parent 5f221f2 commit b482333
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ app.get('/api', (req, res) => {
if (header.startsWith("bingapis-") || header.startsWith("x-msedge-"))
console.log(header + ": " + response.headers[header]);
body = JSON.parse(body);
res.json(body.images.value);
res.json(body.images ? body.images.value : []);
});
response.on('error', function (e) {
console.log('Error: ' + e.message);
Expand Down
11 changes: 7 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { Component } from 'react';
import Img from 'react-image';
import preLoader from './preLoader';
import './App.css';
import { Card, CardText, CardBody, Container, Row, Col, ListGroup, ListGroupItem, Label, Input, FormGroup } from 'reactstrap';

import fetch from 'node-fetch';

const apiUrl = "/";
const extraTerm = "football";

class App extends Component {
state = {
Expand All @@ -21,7 +23,7 @@ class App extends Component {
}
startSearch(term) {
this.setState({ term });
this.makeSearch(term);
this.makeSearch(`${term} ${extraTerm}`);
}

componentDidMount() {
Expand Down Expand Up @@ -77,10 +79,11 @@ class App extends Component {
</ListGroup>
</Col>
<Col xs={9}>
<div>
{images.length === 0 && <h1>No Results Found</h1>}
{images.length > 0 && <div>
<ul>
{images.map((img, i) => <Card key={i} style={{ display: "inline-block", marginBottom: 10 }}>
<Img src={img.contentUrl} style={{ height: 150 }}/>
<Img src={img.contentUrl} style={{ height: 150 }} loader={<preLoader/>}/>
<CardBody>
<CardText>{img.height} x {img.width}</CardText>
<a
Expand All @@ -91,7 +94,7 @@ class App extends Component {
</CardBody>
</Card>)}
</ul>
</div>
</div>}
</Col>
</Row>
</Container>
Expand Down
Binary file added src/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/preLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, {Component} from 'react'

export default () => (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
height: 90,
width: 90
}}
>
<img src="./loader.gif" />
</div>
)

0 comments on commit b482333

Please sign in to comment.