diff --git a/db.json b/db.json
index 1482809..7802fb1 100644
--- a/db.json
+++ b/db.json
@@ -1,5 +1,5 @@
{
- "movies":[],
+ "movies": [],
"posts": [
{
"id": 1,
diff --git a/src/App.js b/src/App.js
index 9aa2579..b921cf7 100644
--- a/src/App.js
+++ b/src/App.js
@@ -4,37 +4,25 @@ import "./App.css";
import Logo from "./Logo.js";
import TitleList from "./components/TitleList";
import Hero from "./components/Hero";
-import SearchBox from "./components/SearchBox";
+import SearchBox from "./containers/SearchBoxContainer";
+import Navigation from "./components/Navigation"
+import UserProfile from "./components/UserProfile"
+// import {loadMyMovieList} from "./actions"
+
class App extends Component {
+ componentDidMount() {
+ this.props.loadMyMovieList()
+ }
+
render() {
return (
- {/* */}
-
-
-
- {/* */}
+
- {/* */}
-
-
-
Jack Oliver
-
-

-
-
-
- {/* */}
+
res.json())
+ .then((list)=>{
+ dispatch(myMovieListLoaded(list))
+ })
+ }
+}
+
+export function myMovieListLoaded(movies){
+ return{
+ type: "MY_MOVIE_LIST_LOADED",
+ value: movies
+ }
+}
+
+export function loadSearch(searchTerm){
+ return function(dispatch){
+ // dispatch({type : "LOAD_SEARCH"})
+ fetch(`https://api.themoviedb.org/3/search/multi?query=${searchTerm}&api_key=aaeeda9440592bb331a7997a9a20c45e`)
+ .then(res=>res.json())
+ .then((movies)=>{
+ dispatch(searchLoaded(movies))
+ })
+ }
+}
+
+export function searchLoaded(movies){
+ return{
+ type: "SEARCH_RESULTS_LOADED",
+ value: movies.results
+ }
+}
+
+export function saveMyMovie(movie){
+ return function(dispatch){
+ fetch("/movies",{
+ method: 'post',
+ body: JSON.stringify(movie),
+ headers:{
+ 'content-type': 'application/json'
+ }
+ })
+ .then(res=>res.json)
+ .then((movies)=>{
+ dispatch(loadMyMovieList(movies))
+ })
+ }
+}
+
+ export function removeMyMovie(id){
+ return function(dispatch){
+ fetch(`/movies/${id}`,{
+ method: 'delete',
+ headers:{
+ 'content-type': 'application/json'
+ }
+ })
+ .then(res=>res.json)
+ .then((movies)=>{
+ dispatch(loadMyMovieList(movies))
+ })
+ }
+ }
\ No newline at end of file
diff --git a/src/components/Item.js b/src/components/Item.js
index 621c374..80bd842 100644
--- a/src/components/Item.js
+++ b/src/components/Item.js
@@ -1,5 +1,5 @@
import React from "react";
-import ListToggle from "./ListToggle";
+import ListToggle from "../containers/ListToggleContainer";
function Item(props) {
diff --git a/src/components/Navigation.js b/src/components/Navigation.js
new file mode 100644
index 0000000..0ab28e9
--- /dev/null
+++ b/src/components/Navigation.js
@@ -0,0 +1,20 @@
+import React, { Component } from 'react'
+
+export default class Navigation extends Component{
+ render(){
+ return(
+
+
+
+
+
+ )
+ }
+}
\ No newline at end of file
diff --git a/src/components/SearchBox.js b/src/components/SearchBox.js
index 443dfd2..a0ee9eb 100644
--- a/src/components/SearchBox.js
+++ b/src/components/SearchBox.js
@@ -3,7 +3,15 @@ import React, {Component} from "react";
class SearchBox extends Component {
constructor() {
super();
+ this.state = {
+ searchTerm: ''
+ }
}
+
+ handleOnChange = (e) =>{
+ this.setState({searchTerm:e.target.value})
+ }
+
render() {
return (
@@ -15,7 +23,8 @@ class SearchBox extends Component {
this.props.loadSearch(this.state.searchTerm);
}
}
- }
+ }
+ onChange={this.handleOnChange}
type="search"
placeholder="Search for a title..." />
diff --git a/src/components/TitleList.js b/src/components/TitleList.js
index bf7fd54..8848ea5 100644
--- a/src/components/TitleList.js
+++ b/src/components/TitleList.js
@@ -1,4 +1,4 @@
-import React, { Component } from "react";
+import React from "react";
import Item from "./Item";
function TitleList(props) {
diff --git a/src/components/UserProfile.js b/src/components/UserProfile.js
new file mode 100644
index 0000000..a9a9dbf
--- /dev/null
+++ b/src/components/UserProfile.js
@@ -0,0 +1,16 @@
+import React, { Component } from 'react'
+
+export default class UserProfile extends Component{
+ render(){
+ return(
+
+
+
Jack Oliver
+
+

+
+
+
+ )
+ }
+}
\ No newline at end of file
diff --git a/src/containers/AppContainer.js b/src/containers/AppContainer.js
new file mode 100644
index 0000000..e7aa7f0
--- /dev/null
+++ b/src/containers/AppContainer.js
@@ -0,0 +1,18 @@
+import {connect} from 'react-redux'
+import {loadMyMovieList} from '../actions'
+import App from '../App'
+
+const msp = (state) =>{
+ return{
+ searchResults: state.searchResults,
+ myMovieList: state.myMovieList
+ }
+}
+
+const mdp = (dispatch) =>{
+ return{
+ loadMyMovieList: ()=>dispatch(loadMyMovieList())
+ }
+}
+
+export default connect(msp,mdp)(App)
\ No newline at end of file
diff --git a/src/containers/ListToggleContainer.js b/src/containers/ListToggleContainer.js
new file mode 100644
index 0000000..06aa680
--- /dev/null
+++ b/src/containers/ListToggleContainer.js
@@ -0,0 +1,12 @@
+import {connect} from 'react-redux'
+import ListToggle from '../components/ListToggle'
+import {saveMyMovie, removeMyMovie} from '../actions'
+
+const mdp = (dispatch)=>{
+ return{
+ saveMyMovie: (movie)=>dispatch(saveMyMovie(movie)),
+ removeMyMovie: (movie)=>dispatch(removeMyMovie(movie))
+ }
+}
+
+export default connect(null, mdp)(ListToggle)
\ No newline at end of file
diff --git a/src/containers/SearchBoxContainer.js b/src/containers/SearchBoxContainer.js
new file mode 100644
index 0000000..705b28d
--- /dev/null
+++ b/src/containers/SearchBoxContainer.js
@@ -0,0 +1,11 @@
+import {connect} from 'react-redux'
+import SearchBox from '../components/SearchBox'
+import {loadSearch} from '../actions'
+
+const mdp = (dispatch) =>{
+ return{
+ loadSearch: (movie)=>dispatch(loadSearch(movie))
+ }
+}
+
+export default connect(null, mdp)(SearchBox)
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index 332a31e..18691d1 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,10 +1,15 @@
import React from "react";
import ReactDOM from "react-dom";
-import App from "./App";
+import AppContainer from "./containers/AppContainer";
import "./index.css";
+import store from './store'
+
+import {Provider} from 'react-redux'
ReactDOM.render(
- ,
+
+
+ ,
document.getElementById("root")
);
diff --git a/src/reducers/index.js b/src/reducers/index.js
index e69de29..9bfd1b8 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -0,0 +1,21 @@
+import {combineReducers} from 'redux'
+
+const myMovieList = (state = [], action)=>{
+ if(action.type === 'MY_MOVIE_LIST_LOADED'){
+ return action.value
+ }
+ return state
+}
+
+const searchResults = (state = [], action)=>{
+ if(action.type === 'SEARCH_RESULTS_LOADED'){
+ return action.value
+ }
+ return state
+}
+
+const rootReducer = combineReducers({
+ searchResults, myMovieList
+})
+
+export default rootReducer
\ No newline at end of file
diff --git a/src/state.js b/src/state.js
index d1a2c33..5ef5a49 100644
--- a/src/state.js
+++ b/src/state.js
@@ -1,3 +1,4 @@
export default {
-
+ searchResults: [],
+ myMovieList: []
};
diff --git a/src/store.js b/src/store.js
new file mode 100644
index 0000000..89c4a6e
--- /dev/null
+++ b/src/store.js
@@ -0,0 +1,17 @@
+import {createStore, applyMiddleware, compose} from "redux";
+import state from "./state";
+import reducers from "./reducers";
+import thunk from "redux-thunk";
+
+const composeEnhancers =
+ typeof window === "object" &&
+ window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
+ window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
+ : compose;
+
+const enhancer = composeEnhancers(
+ applyMiddleware(thunk)
+);
+
+const store = createStore(reducers,state,enhancer);
+export default store;
\ No newline at end of file