Hi,
How can i list tv shows in search by name, description and images fetching from TVMaze API ?
I can not fetch images with title and description. Please help
import React, { Component } from 'react';
import Showlist from '../Showlist';
import icon from '../../images/find-icon.svg';
import Spinner from '../Spinner';
class Tvshows extends Component {
state = {
shows: [],
showName: '',
isFetching: false
}
onShowsInputChange = e => {
this.setState({ showName: e.target.value, isFetching: true});
fetch(`http://api.tvmaze.com/search/shows?q=${e.target.value}`)
.then(response => response.json())
.then(json => this.setState({ shows: json, isFetching: false }));
}
render () {
const { shows, showName, isFetching } = this.state;
return (
<div className="row justify-content-center my-5">
<div className="col-sm-6 col-sm-6-offset my-5">
<p className="text-center text-monospace h2">
<img src={icon} width="30" height="30" className="icon align-top mr-3" alt="icon" />
Search TV Shows</p>
<div className="input-group mb-3 my-3 w-25 mx-auto">
<input
className="form-control"
value={showName}
type="text"
onChange={this.onShowsInputChange}
placeholder="Enter a TV show" />
</div>
{
!isFetching && shows.length === 0 && showName.trim() !== ''
&&
<div class="alert alert-danger" role="alert">
TV show has not been found!
</div>
}
{
isFetching && <Spinner />
}
{
!isFetching && <Showlist list={this.state.shows} />
}
</div>
</div>
)
}
}
export default Tvshows;
Showlist
import React from 'react';
import './style.css';
import { Link } from 'react-router-dom';
const ShowsListItem = ({ shows }) => (
<div>
<Link to={`/shows/${shows.show.id}`}>
{shows.show.name}
</Link>
</div>
)
const Showlist = (props) => {
return (
<div>
{props.list.map(shows => (
<ShowsListItem shows={shows} key={shows.show.id}/>
))}
</div>
)
}
export default Showlist;
Main
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Shows from '../Shows';
import SingleShow from '../SingleShow';
const Main = props => (
<Switch>
<Route exact path="/" component={Shows} />
<Route path="/shows/:id" component={SingleShow} />
</Switch>
);
export default Main;