Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mk search bar2 #4

Merged
merged 4 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MovieSearch from './components/MovieSearch.js';
import MovieLibrary from './components/MovieLibrary.js';
import CustomerList from './components/CustomerList.js';
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
import axios from 'axios'

class App extends Component {
constructor(props){
Expand Down
3 changes: 1 addition & 2 deletions src/Nav.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react';
import React from 'react';
import {Link} from 'react-router-dom'
// import './App.css';

function Nav(){
return (
Expand Down
1 change: 0 additions & 1 deletion src/components/CustomerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Customer from './Customer'
import {Route, Link} from 'react-router-dom'
import axios from 'axios';


class CustomerList extends Component {
constructor(props){
super(props)
Expand Down
5 changes: 0 additions & 5 deletions src/components/Movie.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React, { Component } from 'react';
import axios from 'axios'

class Movie extends Component {
// constructor(props){
// super(props)
// }

render() {
return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MovieLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MovieLibrary extends Component {
render() {
return (
<div className="App">
<h1>MovieLibrary</h1>
<h1>Movie Library</h1>
{this.displayMovies()}
</div>
);
Expand Down
33 changes: 24 additions & 9 deletions src/components/MovieSearch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import Movie from './Movie.js'
import axios from 'axios'

class MovieSearch extends Component {
Expand All @@ -7,19 +8,18 @@ class MovieSearch extends Component {

this.state = {
searchValue: '',
results: [],
error: '',
}
}



findMovie = (title) => {
// const title = this.state.searchValue;
console.log('it worked?????!')
axios.get(`http://localhost:3000/movies`, {params: {query: title}})
.then((response) => {
console.log('it worked!')
console.log(response)
const responseResults = response.data.map((entry) => {
return (entry)
})
this.setState({results: responseResults})
})
.catch((error) => {
this.setState({ error: error.message });
Expand All @@ -42,20 +42,32 @@ class MovieSearch extends Component {
const newSearch = {
searchValue: this.state.searchValue,
}
console.log('now???')
console.log(newSearch)

this.findMovie(newSearch.searchValue);

this.setState({
searchValue: '',
});
}

searchResults = () => {
if (this.state.results.length > 0){
const foundResults = this.state.results.map((movie, i) => {
return (
<Movie
key = {i}
title = {movie.title}
/>
)
})
return foundResults
}
}

render() {
return (
<div>
<h1>MovieSearch</h1>
<h1>Movie Search</h1>
<section>
<form onSubmit={this.onSubmitSearch}>
<input
Expand All @@ -69,6 +81,9 @@ class MovieSearch extends Component {
</div>
</form>
</section>
<section>
{this.searchResults()}
</section>
</div>
);
}
Expand Down