diff --git a/.gitignore b/.gitignore index e43b0f9889..38b19796e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,26 @@ +<<<<<<< HEAD +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + + + +# misc .DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +======= +.DS_Store +>>>>>>> 9375bb04f6e3ec94c87619f85a2995001fe2a578 diff --git a/README.md b/README.md index 3298804c3a..190dfa76d0 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,37 @@ -# Would You Rather Project +# Would You Rather -This is the starter code for the final assessment project for Udacity's React & Redux course. +Would You Rather is a web application that allows users to be able to vote preferred option for a question. The app allows the user the following: -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. +- Sign in +- View all polls +- Select a particular poll and view its details +- Vote for a particular option in a poll +- Create a poll +- View the leaderboard -Using the provided starter code, you'll build a React/Redux front end for the application. We recommend using the [Create React App](https://github.com/facebook/create-react-app) to bootstrap the project. + + + + + -## Data +## Installation -There are two types of objects stored in our database: +- install all project dependencies with `npm install` -* Users -* Questions +- start the development server with `npm start` -### Users +``` +npm install +npm start +``` -Users include: +## Resources Used -| 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. +I learnt how to use create protected routes from [ Implementing Protected Route and Authentication in React-JS](https://dev.to/olumidesamuel_/implementing-protected-route-and-authentication-in-react-js-3cl4) by [Olumide Samuel](https://dev.to/olumidesamuel_) -### Questions +I also benefitted from the guidance of a friend [Qasim-Yusuf](https://github.com/Qausim) who tried as much as possible to make sure I stop doubting myself and just write code. Plus also making fun of me as us. -Questions include: +## Comments & Collaboration -| 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 - -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)` - -1) `_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. - -2) `_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. - -3) `_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| - -4) `_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"`| - -## Contributing - -This repository is the starter code for *all* Udacity students. Therefore, we most likely will not accept pull requests. For details, check out [CONTRIBUTING.md](https://github.com/udacity/reactnd-project-would-you-rather-starter/blob/master/CONTRIBUTING.md). +For comments, suggestions and collaboration all you can reach me on LinkedIn [Adedeji-Adelanwa](https://www.linkedin.com/in/adelanwaadedeji/) diff --git a/_DATA.js b/_DATA.js deleted file mode 100755 index d1b26cb30c..0000000000 --- a/_DATA.js +++ /dev/null @@ -1,202 +0,0 @@ -let users = { - sarahedo: { - id: 'sarahedo', - name: 'Sarah Edo', - avatarURL: , - answers: { - "8xf0y6ziyjabvozdd253nd": 'optionOne', - "6ni6ok3ym7mf1p33lnez": 'optionTwo', - "am8ehyc8byjqgar0jgpub9": 'optionTwo', - "loxhs1bqm25b708cmbf3g": 'optionTwo' - }, - questions: ['8xf0y6ziyjabvozdd253nd', 'am8ehyc8byjqgar0jgpub9'] - }, - tylermcginnis: { - id: 'tylermcginnis', - name: 'Tyler McGinnis', - avatarURL: , - answers: { - "vthrdm985a262al8qx3do": 'optionOne', - "xj352vofupe1dqz9emx13r": 'optionTwo', - }, - questions: ['loxhs1bqm25b708cmbf3g', 'vthrdm985a262al8qx3do'], - }, - johndoe: { - id: 'johndoe', - name: 'John Doe', - avatarURL: , - answers: { - "xj352vofupe1dqz9emx13r": 'optionOne', - "vthrdm985a262al8qx3do": 'optionTwo', - "6ni6ok3ym7mf1p33lnez": 'optionTwo' - }, - questions: ['6ni6ok3ym7mf1p33lnez', 'xj352vofupe1dqz9emx13r'], - } -} - -let questions = { - "8xf0y6ziyjabvozdd253nd": { - id: '8xf0y6ziyjabvozdd253nd', - author: 'sarahedo', - timestamp: 1467166872634, - optionOne: { - votes: ['sarahedo'], - text: 'have horrible short term memory', - }, - optionTwo: { - votes: [], - text: 'have horrible long term memory' - } - }, - "6ni6ok3ym7mf1p33lnez": { - id: '6ni6ok3ym7mf1p33lnez', - author: 'johndoe', - timestamp: 1468479767190, - optionOne: { - votes: [], - text: 'become a superhero', - }, - optionTwo: { - votes: ['johndoe', 'sarahedo'], - text: 'become a supervillain' - } - }, - "am8ehyc8byjqgar0jgpub9": { - id: 'am8ehyc8byjqgar0jgpub9', - author: 'sarahedo', - timestamp: 1488579767190, - optionOne: { - votes: [], - text: 'be telekinetic', - }, - optionTwo: { - votes: ['sarahedo'], - text: 'be telepathic' - } - }, - "loxhs1bqm25b708cmbf3g": { - id: 'loxhs1bqm25b708cmbf3g', - author: 'tylermcginnis', - timestamp: 1482579767190, - optionOne: { - votes: [], - text: 'be a front-end developer', - }, - optionTwo: { - votes: ['sarahedo'], - text: 'be a back-end developer' - } - }, - "vthrdm985a262al8qx3do": { - id: 'vthrdm985a262al8qx3do', - author: 'tylermcginnis', - timestamp: 1489579767190, - optionOne: { - votes: ['tylermcginnis'], - text: 'find $50 yourself', - }, - optionTwo: { - votes: ['johndoe'], - text: 'have your best friend find $500' - } - }, - "xj352vofupe1dqz9emx13r": { - id: 'xj352vofupe1dqz9emx13r', - author: 'johndoe', - timestamp: 1493579767190, - optionOne: { - votes: ['johndoe'], - text: 'write JavaScript', - }, - optionTwo: { - votes: ['tylermcginnis'], - text: 'write Swift' - } - }, -} - -function generateUID () { - return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) -} - -export function _getUsers () { - return new Promise((res, rej) => { - setTimeout(() => res({...users}), 1000) - }) -} - -export function _getQuestions () { - return new Promise((res, rej) => { - setTimeout(() => res({...questions}), 1000) - }) -} - -function formatQuestion ({ optionOneText, optionTwoText, author }) { - return { - id: generateUID(), - timestamp: Date.now(), - author, - optionOne: { - votes: [], - text: optionOneText, - }, - optionTwo: { - votes: [], - text: optionTwoText, - } - } -} - -export function _saveQuestion (question) { - return new Promise((res, rej) => { - const authedUser = question.author; - const formattedQuestion = formatQuestion(question); - - setTimeout(() => { - questions = { - ...questions, - [formattedQuestion.id]: formattedQuestion - } - - users = { - ...users, - [authedUser]: { - ...users[authedUser], - questions: users[authedUser].questions.concat([formattedQuestion.id]) - } - } - - res(formattedQuestion) - }, 1000) - }) -} - -export function _saveQuestionAnswer ({ authedUser, qid, answer }) { - return new Promise((res, rej) => { - setTimeout(() => { - users = { - ...users, - [authedUser]: { - ...users[authedUser], - answers: { - ...users[authedUser].answers, - [qid]: answer - } - } - } - - questions = { - ...questions, - [qid]: { - ...questions[qid], - [answer]: { - ...questions[qid][answer], - votes: questions[qid][answer].votes.concat([authedUser]) - } - } - } - - res() - }, 500) - }) -} diff --git a/build/asset-manifest.json b/build/asset-manifest.json new file mode 100644 index 0000000000..47a54ce35c --- /dev/null +++ b/build/asset-manifest.json @@ -0,0 +1,23 @@ +{ + "files": { + "main.css": "/static/css/main.ff576dba.chunk.css", + "main.js": "/static/js/main.0be6fe67.chunk.js", + "main.js.map": "/static/js/main.0be6fe67.chunk.js.map", + "runtime-main.js": "/static/js/runtime-main.e451e4ca.js", + "runtime-main.js.map": "/static/js/runtime-main.e451e4ca.js.map", + "static/css/2.27175f2b.chunk.css": "/static/css/2.27175f2b.chunk.css", + "static/js/2.727437a6.chunk.js": "/static/js/2.727437a6.chunk.js", + "static/js/2.727437a6.chunk.js.map": "/static/js/2.727437a6.chunk.js.map", + "index.html": "/index.html", + "static/css/2.27175f2b.chunk.css.map": "/static/css/2.27175f2b.chunk.css.map", + "static/css/main.ff576dba.chunk.css.map": "/static/css/main.ff576dba.chunk.css.map", + "static/js/2.727437a6.chunk.js.LICENSE.txt": "/static/js/2.727437a6.chunk.js.LICENSE.txt" + }, + "entrypoints": [ + "static/js/runtime-main.e451e4ca.js", + "static/css/2.27175f2b.chunk.css", + "static/js/2.727437a6.chunk.js", + "static/css/main.ff576dba.chunk.css", + "static/js/main.0be6fe67.chunk.js" + ] +} \ No newline at end of file diff --git a/build/assets/danabramov.jpeg b/build/assets/danabramov.jpeg new file mode 100644 index 0000000000..25fae6e99e Binary files /dev/null and b/build/assets/danabramov.jpeg differ diff --git a/build/assets/saraedo.jpeg b/build/assets/saraedo.jpeg new file mode 100644 index 0000000000..838f9ed771 Binary files /dev/null and b/build/assets/saraedo.jpeg differ diff --git a/build/assets/tylermcginis.jpeg b/build/assets/tylermcginis.jpeg new file mode 100644 index 0000000000..d278a9bf09 Binary files /dev/null and b/build/assets/tylermcginis.jpeg differ diff --git a/build/favicon.ico b/build/favicon.ico new file mode 100644 index 0000000000..a11777cc47 Binary files /dev/null and b/build/favicon.ico differ diff --git a/build/index.html b/build/index.html new file mode 100644 index 0000000000..cf334da217 --- /dev/null +++ b/build/index.html @@ -0,0 +1 @@ +
{authedUser.id}
\n >\n )}\n\n {questions[queId].optionOne.text}\n
\n\n {questions[queId].optionTwo.text}\n
\n{name}
\n\n Number of questions answered:\n {Object.keys(users[userId].answers).length}\n
\n\n Number of questions asked:\n {users[userId].questions.length}\n
\n{question.optionOne.text}
\n\n\n {question.optionOne.votes.length}{\" \"}\n {question.optionTwo.votes.length <= 1 ? \" person \" : \" people \"}\n voted this option\n
\n\n {Math.round(\n (question.optionOne.votes.length /\n (question.optionOne.votes.length +\n question.optionTwo.votes.length)) *\n 100\n )}\n % of the people voted this option\n
\n{question.optionTwo.text}
\n\n\n {question.optionTwo.votes.length}\n {question.optionTwo.votes.length <= 1 ? \" person \" : \" people \"}\n voted this option\n
\n\n {Math.round(\n (question.optionTwo.votes.length /\n (question.optionTwo.votes.length +\n question.optionOne.votes.length)) *\n 100\n )}\n % of the people voted this option\n
\n{question.optionOne.text}
\n \n{question.optionTwo.text}
\n \nKindly Sign In to play
\n{question.optionOne.text}
+ ++ {question.optionOne.votes.length}{" "} + {question.optionTwo.votes.length <= 1 ? " person " : " people "} + voted this option +
++ {Math.round( + (question.optionOne.votes.length / + (question.optionOne.votes.length + + question.optionTwo.votes.length)) * + 100 + )} + % of the people voted this option +
+{question.optionTwo.text}
+ ++ {question.optionTwo.votes.length} + {question.optionTwo.votes.length <= 1 ? " person " : " people "} + voted this option +
++ {Math.round( + (question.optionTwo.votes.length / + (question.optionTwo.votes.length + + question.optionOne.votes.length)) * + 100 + )} + % of the people voted this option +
+{authedUser.id}
+ > + )} +{questions[queId].optionOne.text}
+{questions[queId].optionTwo.text}
+{question.optionOne.text}
+ +{question.optionTwo.text}
+ +{name}
++ Number of questions answered: + {Object.keys(users[userId].answers).length} +
++ Number of questions asked: + {users[userId].questions.length} +
+Kindly Sign In to play
+