-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathApp.js
More file actions
112 lines (88 loc) · 3.57 KB
/
App.js
File metadata and controls
112 lines (88 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React from "react";
import Films from "./Films";
import Search from "./Search";
class App extends React.Component {
constructor() {
super();
this.state = { films: [], pageNum: 1, currentSearchFlim: "love", unFound: {gif: '', h6: ''}, hideButtons: true};
this.handleNext = this.handleNext.bind(this);
this.handlePrevious = this.handlePrevious.bind(this);
this.fetchIMDB = this.fetchIMDB.bind(this);
// this.filmSearch = this.filmSearch.bind(this);
// this.IMDBData= this.IMDBData.bind(this);
this.notFound = this.notFound.bind(this);
// this.searchText = this.searchText.bind(this);
this.receiveSearch = this.receiveSearch.bind(this);
}
componentDidMount() {
this.receiveSearch(this.state.currentSearchFlim);
}
notFound(){
this.setState({unFound:{gif:'/oops.gif', h6:"Terribly sorry, we couldn't find that"}});
}
handleNext() {
// this.setState(prevState =>Object.assign({}, prevState, { pageNum: prevState.pageNum + 1 }))
// this.setState(prevState => ({...prevState, pageNum: prevState.pageNum + 1}));
// this.setState({pageNum: this.state.pageNum + 1})
// this.setState( prevState => ({pageNum: prevState.pageNum + 1}))
// this.receiveSearch(this.state.currentSearchFlim)
this.setState({pageNum:this.state.pageNum + 1}, () => this.receiveSearch(this.state.currentSearchFlim))
}
handlePrevious() {
// event.preventDefault();
// this.setState({pageNum: this.state.pageNum - 1})
// this.receiveSearch(this.state.currentSearchFlim)
this.setState({pageNum:this.state.pageNum - 1}, () => this.receiveSearch(this.state.currentSearchFlim))
}
receiveSearch(filmSearchQuery) {
this.setState( prevState => ({currentSearchFlim: filmSearchQuery}))
// this.setState(prevState => Object.assign({}, prevState, { currentSearchFlim: filmSearchQuery}))
const searchURL = `https://www.omdbapi.com/?s=${filmSearchQuery}&page=${this.state.pageNum}&apikey=73071eff`;
this.fetchIMDB(searchURL);
}
// Initial Search Fetch
fetchIMDB(searchURL) {
fetch(searchURL)
.then(
response => (response.ok ? response.json() : Promise.reject(response))
)
.then(films => {
if (films.Response === "False") {
this.notFound();
// alert("WHOOPS!");
this.setState({ films:[]});
// this.setState({unfound:{gif: '', h6: ''}})
} else {
console.log(films);
this.setState({ films: films.Search, unfound: {gif: '', h6: ''}}); //unforund reset not working
// this.setState({pageNum:1}); //pagenum reset not working
}
})
// .catch(error => console.log("catch error", error));
}
// hideButtonsFunction(){
// this.setState({showSlider: false})
render() {
// const buttonsHider = cx('lower__buttons', {'lower__buttons__hidden': this.state.hidebuttons})
return (
<div>
<a name="top"></a>
<span className="nav">
<Search receiveSearch={this.receiveSearch} />
</span>
<div className="oops">
{this.state.unFound.h6}
<img className="cry" src={this.state.unFound.gif}/>
</div>
<Films films={this.state.films} />
<div></div>
<div className="lower__buttons__wrapper">
<button className="lower__button__2" onClick={this.handlePrevious} href="#top">Back</button>
<button className="lower__button__1" onClick={this.handleNext} href="#top" >Next</button>
</div>
<a className="uparrow" href="#top">˄</a>
</div>
);
}
}
export default App;