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

Unfinished project - CP #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fetch
  • Loading branch information
chrisphillers committed Nov 2, 2018
commit b1a69b178005c58b8064974dd9f2bea17e3f95d5
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
export function fetchQuestion(){
return function(dispatch){

export function fetchQuestionAPI(){
// console.log()
return function(dispatch, getState){
// const {reduxState} = getState();
fetch(`https://opentdb.com/api.php?amount=1&type=multiple`)
.then(response => response.json())
.then(result => {
console.log(result)
dispatch(receiveQuestions(result))
dispatch()
})
.catch(function(error) {
// something went wrong. let's sort it out
});
}
}
};


export function receiveQuestions(result){
return {
type: 'RECEIVE_QUESTIONS',
questions: result
}
}
10 changes: 9 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React from 'react';
import QuestionsContainer from '../containers/QuestionsContainer';


class App extends React.Component {





render(){
return (
<div>
App contents go here
QUIZ
<QuestionsContainer />
</div>
)
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/Questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";

class Questions extends React.Component {

constructor() {
super();
// this.quizDisplay = this.quizDisplay.bind(this);
}


componentDidMount(){
this.props.fetchQuestion()
}

render() {


return (
<div className="quiz__display">

</div>
);
}

}

export default Questions;
25 changes: 25 additions & 0 deletions src/containers/QuestionsContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { connect } from "react-redux";
import Questions from "../components/Questions";
// import { setQuery, submitQuery } from "../actions"
import { fetchQuestionAPI } from '../actions';

// fetchQuestion={this.props.fetchQuestion}

const mapStateToProps = state => {
return {
// selectedQuery: state.searchInput.selectedQuery
};
}


const mapDispatchToProps = dispatch => {
return {
fetchQuestion: () => dispatch(fetchQuestionAPI())
// selectedQuery: state.searchInput.selectedQuery
};
}


export default connect(
mapStateToProps, mapDispatchToProps
)(Questions);
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';

import thunkMiddleware from 'redux-thunk';
import { createStore, applyMiddleware } from 'redux';
import { createStore, applyMiddleware, compose } from "redux";
import { Provider } from 'react-redux';
import rootReducer from './reducers';

const store = createStore(rootReducer, applyMiddleware(
thunkMiddleware
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, {}, composeEnhancers(
applyMiddleware(thunkMiddleware)
));

ReactDOM.render(
Expand Down
13 changes: 13 additions & 0 deletions src/reducers/questionsResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function questionsResults(state = [], action){
switch (action.type) {
case 'RECEIVE_QUESTIONS':
return action.questions


default:
return state
}
}

export default questionsResults;