Would You Rather is a game in which the user has to choose one of two options. This React-based version includes questions on various topics.
This project was bootstrapped with Create React App.
- Node.js
- Download or clone the repo.
- cd into the project directory.
- Run
npm install
to install dependencies. - Run
npm start
to start the server. - Open
http://localhost:3000
and start playing!
The project contains a number of important files:
- _DATA.JS - The mock backend. Check this part for more details.
- index.js - the base JavaScript file, which renders the whole app.
Located in: src/actions
Contains the Redux store actions required to run the app. Actions are divided into three files (mirroring the three parts of the store):
- currentUser.js - Contains actions relating to the currently logged in user, such as login and logout.
- questions.js - Contains actions relating to the game questions, such as adding initial data and adding new questions.
- shared.js - Contains async action creators relating to both questions and users.
- users.js - Contains actions relating to the list of currently registered users, such as getting initial data.
Located in: src/components
Contains the app's components. These include:
- App.js (as well as App.css and App.test.js) - The App component. Includes all components in the app.
- Home.js - The Home component. Displays a list of links to answered and unanswered questions to the logged-in user.
- Leaderboard.js - The Leaderboard component. Displays a table with the stats for all existing users.
- LoginPage.js - The LoginPage component. Contains a login page in which the user can set the currentUser.
- NewQuestion.js - The NewQuestion component. Contains a form with which the user can add a new question to the mock database.
- Question.js The Question component. Contains a Would You Rather question.
Located in: src/middleware
Contains the middleware used by this app's store. As of right now, includes two files:
- index.js - The entry point for middleware; contains the Redux
applyMiddleware
call, which applies thunk (from Redux-Thunk) and any middleware in this directory. - logger.js - A logger middleware (for development only!). Logs actions and current store state to the console.
Located in: src/reducers
Contains the reducers used by this app's store. There are currently three reducers, mirroring the three parts of the store, as well as an entry point:
- currentUser.js - Contains the reducer updating currently logged in user. Responsible for the 'currentUser' part of the store.
- index.js - Entry point for reducers. Contains the
combineReducers
call, combining the three reducers and returning a single reducer to be used by the store. - questions.js - Contains the reducer updating the list of game questions. Responsible for the 'questions' part of the store.
- users.js - Contains the reducer updating the list of registered users. Responsible for the 'users' part of the store.
This project utilises several dependencies:
- react - the React framework.
- react-dom - React's package of DOM-specific methods.
- react-scripts - Configuration and scripts for Create React App (the base of this project).
- redux and react-redux - Redux store and React-specific Redux bindings.
- react-router-dom - React's router.
- redux-thunk - A Redux middleware for handling asynchronous requests.
- Font Awesome - An icon library and toolkit (Official site). Contains the following dependencies:
- @fortawesome/fontawesome-svg-core - Library core package.
- @fortawesome/free-solid-svg-icons - The library's free solid icons.
- @fortawesome/react-fontawesome - The library's React integration.
The _DATA.js
file represents a fake database and methods that let you access the data. The only thing you need to edit in the _DATA.js
file is the value of avatarURL
. Each user should have an avatar, so you’ll need to add the path to each user’s avatar.
Mock server provided by Udacity (see original here).
There are two types of objects stored in our database:
- Users
- Questions
Users include:
Attribute | Type | Description |
---|---|---|
id | String | The user’s unique identifier |
name | String | The user’s first name and last name |
avatarURL | String | The path to the image file |
questions | Array | A list of ids of the polling questions this user created |
answers | Object | The object's keys are the ids of each question this user answered. The value of each key is the answer the user selected. It can be either 'optionOne' or 'optionTwo' since each question has two options. |
Questions include:
Attribute | Type | Description |
---|---|---|
id | String | The question’s unique identifier |
author | String | The author’s unique identifier |
timestamp | String | The time when the question was created |
optionOne | Object | The first voting option |
optionTwo | Object | The second voting option |
Voting options are attached to questions. They include:
Attribute | Type | Description |
---|---|---|
votes | Array | A list that contains the id of each user who voted for that option |
text | String | The text of the option |
Your code will talk to the database via 4 methods:
_getUsers()
_getQuestions()
_saveQuestion(question)
_saveQuestionAnswer(object)
_getUsers()
Method
Description: Get all of the existing users from the database.
Return Value: Object where the key is the user’s id and the value is the user object.
_getQuestions()
Method
Description: Get all of the existing questions from the database.
Return Value: Object where the key is the question’s id and the value is the question object.
_saveQuestion(question)
Method
Description: Save the polling question in the database.
Parameters: Object that includes the following properties: author
, optionOneText
, and optionTwoText
. More details about these properties:
Attribute | Type | Description |
---|---|---|
author | String | The id of the user who posted the question |
optionOneText | String | The text of the first option |
optionTwoText | String | The text of the second option |
Return Value: An object that has the following properties: id
, author
, optionOne
, optionTwo
, timestamp
. More details about these properties:
Attribute | Type | Description |
---|---|---|
id | String | The id of the question that was posted |
author | String | The id of the user who posted the question |
optionOne | Object | The object has a text property and a votes property, which stores an array of the ids of the users who voted for that option |
optionTwo | Object | The object has a text property and a votes property, which stores an array of the ids of the users who voted for that option |
timestamp | String | The time when the question was created |
_saveQuestionAnswer(object)
Method
Description: Save the answer to a particular polling question in the database.
Parameters: Object that contains the following properties: authedUser
, qid
, and answer
. More details about these properties:
Attribute | Type | Description |
---|---|---|
authedUser | String | The id of the user who answered the question |
qid | String | The id of the question that was answered |
answer | String | The option the user selected. The value should be either "optionOne" or "optionTwo" |
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
There are no current issues at the time.