Skip to content

Commit

Permalink
wired up redux firebase saga and bounded questions to app
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilt committed Feb 17, 2018
1 parent 21ba3cc commit 74b0734
Show file tree
Hide file tree
Showing 18 changed files with 463 additions and 72 deletions.
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"single-quote": true,
"arrow-parens": "always"
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"firebase": "^4.10.0",
"firebase-admin": "^5.9.0",
"firebase-functions": "^0.8.1",
"highlight.js": "^9.12.0",
"is-empty-object": "^1.1.1",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-highlight": "briancappello/react-highlight#react-v16-compiled",
"react-redux": "^5.0.6",
"react-redux": "^5.0.7",
"react-redux-firebase": "^2.0.4",
"react-remarkable": "^1.1.3",
"react-scripts": "1.1.1",
"redux": "^3.7.2",
"redux-firestore": "^0.2.8",
"redux-saga": "^0.16.0",
"reset-css": "^2.2.1"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

<script>
console.log('Hey buddy. Don\'t cheat. Just do your best.');
</script>

<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">

<!--
Expand Down
5 changes: 3 additions & 2 deletions questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "basic-variable",
"question": "Select the answer below that would set a variable named `myVariable` to `3`",
"incorrectFeedback": "This a very basic question and if this answer wasn't on accident, the rest of the quiz is probably going to be very difficult. Start by reading up on the [fundamentals of Javascript](https://www.w3schools.com/js/)",
"codeFigure":"var name = \"Bill\";\n\nfunction caller(func){\n var myObject = {\n name: \"Joe\"\n};\n\n return func(myObject);\n}\n\n function callee(param) {\n return param.name\n}\n\n var c = caller(callee);",
"codeFigure":"var name = \"Bill\";\n\nfunction caller(func){\n var myObject = {\n name: \"Joe\"\n};\n\n return func(myObject);\n}\n\n function callee(param) {\n return param.name\n}\n\nvar c = caller(callee);",
"answers": [
{
"type": "code",
Expand All @@ -21,6 +21,7 @@
"type": "code",
"text": "var myVariable = {\n 3\n}"
}
]
],
"correctAnswer": 1
}
]
6 changes: 3 additions & 3 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import './App.css';
import React, { Component } from "react";
import "./App.css";

import { Quiz } from 'components';
import { Quiz } from "components";

class App extends Component {
render() {
Expand Down
6 changes: 3 additions & 3 deletions src/components/App/App.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

it(`renders without crashing`, () => {
const div = document.createElement(`div`);
Expand Down
2 changes: 1 addition & 1 deletion src/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as App } from './App.js';
export { default as App } from "./App.js";
10 changes: 5 additions & 5 deletions src/components/QuestionAnswer/QuestionAnswer.component.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { PureComponent } from 'react';
import React, { PureComponent } from "react";

import Highlight from 'react-highlight';
import Highlight from "react-highlight";

import Markdown from 'react-remarkable';
import Markdown from "react-remarkable";

import PropTypes from 'prop-types';
import PropTypes from "prop-types";

import './QuestionAnswer.css';
import "./QuestionAnswer.css";

export default class QuestionAnswer extends PureComponent {
static propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuestionAnswer/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as QuestionAnswer } from './QuestionAnswer.component';
export { default as QuestionAnswer } from "./QuestionAnswer.component";
28 changes: 25 additions & 3 deletions src/components/Quiz/Quiz.component.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import React, { PureComponent } from 'react';
import React, { PureComponent } from "react";

import './Quiz.css';
import isEmptyObject from 'is-empty-object';

import {
QuizQuestion,
} from 'components';

import PropTypes from 'prop-types';

import "./Quiz.css";

export default class Quiz extends PureComponent {
static propTypes = {
questions: PropTypes.object,
};

render() {
return <div className={`Quiz`} />;
const { questions } = this.props;

return questions && !isEmptyObject(questions) ? (
<div className={`Quiz`}>
{Object.values(questions).map((question) => (
<div key={question.id}>
<QuizQuestion {...question} />
</div>
))}
</div>
) : null;
}
}
18 changes: 18 additions & 0 deletions src/components/Quiz/Quiz.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { connect } from 'react-redux'

import { compose } from 'redux'

import { firestoreConnect } from 'react-redux-firebase'

import Quiz from './Quiz.component';

export default compose(
firestoreConnect([
`questions`,
]),
connect(
(state) => ({
questions: state.firestore.data.questions
})
)
)(Quiz)
2 changes: 1 addition & 1 deletion src/components/Quiz/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as Quiz } from './Quiz.component';
export { default as Quiz } from "./Quiz.container";
14 changes: 7 additions & 7 deletions src/components/QuizQuestion/QuizQuestion.component.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, { PureComponent } from 'react';
import React, { PureComponent } from "react";

import Highlight from 'react-highlight';
import Highlight from "react-highlight";

import Markdown from 'react-remarkable';
import Markdown from "react-remarkable";

import { QuestionAnswer } from 'components';
import { QuestionAnswer } from "components";

import 'highlight.js/styles/github-gist.css';
import "highlight.js/styles/github-gist.css";

import PropTypes from 'prop-types';
import PropTypes from "prop-types";

import './QuizQuestion.css';
import "./QuizQuestion.css";

export default class QuizQuestion extends PureComponent {
static propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuizQuestion/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as QuizQuestion } from './QuizQuestion.component';
export { default as QuizQuestion } from "./QuizQuestion.component";
9 changes: 4 additions & 5 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './App';
export * from './QuestionAnswer';
export * from './Questions';
export * from './Quiz';
export * from './QuizQuestion';
export * from "./App";
export * from "./QuestionAnswer";
export * from "./Quiz";
export * from "./QuizQuestion";
24 changes: 17 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import React from 'react';
import ReactDOM from 'react-dom';
import 'reset-css';
import './index.css';
import React from "react";
import ReactDOM from "react-dom";
import "reset-css";
import "./index.css";

import { App } from 'components';
import { Provider } from "react-redux";

import registerServiceWorker from './registerServiceWorker';
import store from "store";

import { App } from "components";

import registerServiceWorker from "./registerServiceWorker";

ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById(`root`)
);

ReactDOM.render(<App />, document.getElementById(`root`));
registerServiceWorker();
37 changes: 37 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createStore, combineReducers, compose } from "redux";

import { reactReduxFirebase } from "react-redux-firebase";

import { reduxFirestore, firestoreReducer } from "redux-firestore";

import firebase from "firebase";

import 'firebase/firestore';

// react-redux-firebase config
const rrfConfig = {
userProfile: `users`,
useFirestoreForProfile: true, // Firestore for Profile instead of Realtime DB
};

firebase.initializeApp({
apiKey: `AIzaSyBVRfPWkOwK2mWquD7-BP4r4v4pXYWL6l8`,
authDomain: `dan-wilt-coaching-assessmen.firebaseapp.com`,
databaseURL: `https://dan-wilt-coaching-assessmen.firebaseio.com`,
projectId: `dan-wilt-coaching-assessmen`,
storageBucket: `dan-wilt-coaching-assessmen.appspot.com`,
messagingSenderId: `92351047707`,
});

firebase.firestore();

const createStoreWithFirebase = compose(
reactReduxFirebase(firebase, rrfConfig), // firebase instance as first argument
reduxFirestore(firebase) // <- needed if using firestore
)(createStore);

const rootReducer = combineReducers({
firestore: firestoreReducer, // <- needed if using firestore
});

export default createStoreWithFirebase(rootReducer, {}, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
Loading

0 comments on commit 74b0734

Please sign in to comment.