This app is the second project of the Udacity React Developer Nanodegree and follows the "Would You Rather project specification" listed bellow and all the style guides provided by Udacity:
- CSS Style Guide
- HTML Style Guide
- JavaScript Style Guide
- Git Style Guide
-
For this project I had to build a web app that lets a user play the “Would You Rather?” game. The game goes like this: A user is asked a question in the form: “Would you rather [option A] or [option B] ?”. Answering "neither" or "both" is against the rules.
-
In my app, users will be able to answer questions, see which questions they haven’t answered, see how other people have voted, post questions, and see the ranking of users on the leaderboard.
- The application requires only
npm install
andnpm start
to install and launch. - A README is included with the project. The README includes a description and clear instructions for installing and launching the project.
- There should be a way for the user to impersonate/ log in as an existing user.
- The application works correctly regardless of which user is selected.
- The application allows the user to log out and log back in. The user should be logged in to submit new polling questions, vote, and view the leaderboard.
- Once the user logs in, the home page is shown.
- Whenever the user types something in the address bar, the user is asked to log in before the requested page is shown.
- The answered and unanswered polls are both available at the root.
- The user can alternate between viewing answered and unanswered polls.
- The unanswered questions are shown by default.
- The name of the logged in user is visible on the page.
- The user can navigate to the leaderboard at
/leaderboard
- The user can navigate to the form that allows the user to create a new poll at
/add
- Each polling question resides in the correct category (answered and unanswered).
- A polling question links to details of that poll.
- The polls in both categories are arranged from the most recently created (top) to the least recently created (bottom).
- The details of the poll are available at
questions/:question_id
. - When a poll is clicked on the home page, the following is shown:
- the text “Would You Rather”;
- the picture of the user who posted the polling question;
- and the two options.
- For answered polls, each of the two options contains the following:
- the text of the option;
- the number of people who voted for that option;
- the percentage of people who voted for that option.
- The option selected by the logged in user should be clearly marked.
- When the user is logged in, the details of the poll are shown. If the user is logged out, he/she is asked to log in before before being able to access the poll.
- The application asks the user to sign in and shows a 404 page if that poll does not exist.
- Upon voting in a poll, all of the information of the answered poll is displayed.
- The user’s response is recorded and is clearly visible on the poll details page.
- When the user comes back to the home page, the polling question appears in the “Answered” column.
- The voting mechanism works correctly, and the data on the leaderboard changes appropriately.
- The form is available at
/add
. - The application shows the text “Would You Rather” and has a form for creating two options.
- Upon submitting the form, a new poll is created and the user is taken to the home page.
- The new polling question appears in the correct category on the home page.
- The Leaderboard is available at
/leaderboard
. - Each entry on the leaderboard contains the following:
- the user’s name;
- the user’s picture;
- the number of questions the user asked;
- and the number of questions the user answered.
- Users are ordered in descending order based on the sum of the number of questions they’ve answered and the number of questions they’ve asked.
- The app contains a navigation bar that is visible on all of the pages.
- The user can navigate between the page for creating new polls, and the leaderboard page, and the home page without typing the address into the address bar.
- The data that’s initially displayed is populated correctly from the backend.
- Each user’s answer and each new poll is correctly recorded on the backend.
- The code runs without errors. There are no warnings that resulted from not following the best practices listed in the documentation, such as using key for list items. All code is functional and formatted properly.
- The store is the application’s source of truth.
- Components read the necessary state from the store; they do not have their own versions of the same state.
- There are no direct API calls in the components' lifecycle methods.
- Most application state is managed by the Redux store. State-based props are mapped from the store rather than stored as component state.
- Form inputs and controlled components may have some state handled by the component.
- Updates are triggered by dispatching action creators to reducers.
- Reducers and actions are written properly and correctly return updated state to the store.
- The code is structured and organized in a logical way.
- Components are modular and reusable.
-
The
_DATA.js
file represents a fake database and has methods that let me access the data. -
Using the provided starter code, I built a React/Redux front end for the application using the Create React App to bootstrap the project.
There are two types of objects stored in Udacity's 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 |
My code 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" |
- Download the files, cd into root directory and run:
# Install dependencies
$ npm install
# Run the app
$ npm start
- This project was bootstrapped with Create React App.
- Styles: Styled Components
- Icons: React Icons
- React Documentation
- Redux Documentation
- MDN Documentation