-
Notifications
You must be signed in to change notification settings - Fork 64
[DFFA-156] Build a To-Do App with REACT #907
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
Open
PluckyPrecious
wants to merge
2
commits into
Dufuna-CodeCamp:master
Choose a base branch
from
PluckyPrecious:React/todo-app/PluckyPrecious
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
submissions/KelechiPreciousNwachukwu/React/todo-App/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* |
70 changes: 70 additions & 0 deletions
70
submissions/KelechiPreciousNwachukwu/React/todo-App/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Getting Started with Create React App | ||
|
|
||
| This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
|
||
| ## Available Scripts | ||
|
|
||
| In the project directory, you can run: | ||
|
|
||
| ### `npm start` | ||
|
|
||
| Runs the app in the development mode.\ | ||
| Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
|
||
| The page will reload if you make edits.\ | ||
| You will also see any lint errors in the console. | ||
|
|
||
| ### `npm test` | ||
|
|
||
| Launches the test runner in the interactive watch mode.\ | ||
| See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
|
||
| ### `npm run build` | ||
|
|
||
| Builds the app for production to the `build` folder.\ | ||
| It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
|
||
| The build is minified and the filenames include the hashes.\ | ||
| Your app is ready to be deployed! | ||
|
|
||
| See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
|
||
| ### `npm run eject` | ||
|
|
||
| **Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
|
||
| If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
|
||
| Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
|
||
| You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
|
||
| ## Learn More | ||
|
|
||
| You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
|
||
| To learn React, check out the [React documentation](https://reactjs.org/). | ||
|
|
||
| ### Code Splitting | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) | ||
|
|
||
| ### Analyzing the Bundle Size | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) | ||
|
|
||
| ### Making a Progressive Web App | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) | ||
|
|
||
| ### Advanced Configuration | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) | ||
|
|
||
| ### Deployment | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) | ||
|
|
||
| ### `npm run build` fails to minify | ||
|
|
||
| This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) |
38 changes: 38 additions & 0 deletions
38
submissions/KelechiPreciousNwachukwu/React/todo-App/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "hoopla-app", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@testing-library/jest-dom": "^5.12.0", | ||
| "@testing-library/react": "^11.2.7", | ||
| "@testing-library/user-event": "^12.8.3", | ||
| "react": "^17.0.2", | ||
| "react-dom": "^17.0.2", | ||
| "react-scripts": "4.0.3", | ||
| "web-vitals": "^1.1.2" | ||
| }, | ||
| "scripts": { | ||
| "start": "react-scripts start", | ||
| "build": "react-scripts build", | ||
| "test": "react-scripts test", | ||
| "eject": "react-scripts eject" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": [ | ||
| "react-app", | ||
| "react-app/jest" | ||
| ] | ||
| }, | ||
| "browserslist": { | ||
| "production": [ | ||
| ">0.2%", | ||
| "not dead", | ||
| "not op_mini all" | ||
| ], | ||
| "development": [ | ||
| "last 1 chrome version", | ||
| "last 1 firefox version", | ||
| "last 1 safari version" | ||
| ] | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
submissions/KelechiPreciousNwachukwu/React/todo-App/public/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <link rel = "stylesheet" href = "/src/index.css" /> | ||
| <meta | ||
| name="description" | ||
| content="ToDo App created using create-react-app" | ||
| /> | ||
|
|
||
| <title>Hoopla App</title> | ||
| </head> | ||
| <body> | ||
| <noscript>You need to enable JavaScript to run this app.</noscript> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html> |
8 changes: 8 additions & 0 deletions
8
submissions/KelechiPreciousNwachukwu/React/todo-App/public/manifest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "short_name": "ToDo App", | ||
| "name": "Hoopla App", | ||
| "start_url": ".", | ||
| "display": "standalone", | ||
| "theme_color": "#316879, #f47a60, #7fe7dc", | ||
| "background_color": "#ced7d8" | ||
| } |
120 changes: 120 additions & 0 deletions
120
submissions/KelechiPreciousNwachukwu/React/todo-App/src/App.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import React, { Component } from 'react'; | ||
| import { nanoid } from 'nanoid'; | ||
| import Todo from './components/Todo'; | ||
| import Button from './components/Button'; | ||
| import Form from './components/Form'; | ||
| import ClearButton from './components/ClearButton'; | ||
|
|
||
| const filter_functions = { | ||
| All: () => true, | ||
| Active: task => task.status === 'active', | ||
| Completed: task => task.status === 'completed' | ||
| }; | ||
|
|
||
| const filter_names = Object.keys(filter_functions); | ||
|
|
||
| class App extends Component { | ||
| state = { | ||
| tasks: this.props.tasks, | ||
| filter: 'All' | ||
| } | ||
|
|
||
| render() { | ||
| const tasks = this.state.tasks; | ||
|
|
||
| const setFilter = (name) => { | ||
| this.setState({ | ||
| filter: name | ||
| }) | ||
| }; | ||
|
|
||
| const toggleCompleted = (id) => { | ||
| const updatedTasks = tasks.map(task => { | ||
| if (id === task.id) { | ||
| const theStatus = task.status === 'active' ? 'completed' : 'active'; | ||
| return { ...task, status: theStatus } | ||
| } | ||
|
|
||
| return task; | ||
| } ) | ||
| this.setState({ | ||
| tasks: updatedTasks | ||
| }) | ||
| }; | ||
|
|
||
| const tasklist = tasks | ||
| .filter(filter_functions[this.state.filter]) | ||
| .map(task => { | ||
| return ( | ||
| <Todo id = {task.id} name = {task.name} status = {task.status} key = {task.id} toggleStatus = {toggleCompleted} /> | ||
| ) | ||
| }); | ||
|
|
||
| const filterList = filter_names.map(name => { | ||
| return ( | ||
| <Button | ||
| key = {name} | ||
| name = {name} | ||
| isPressed = {name === this.state.filter} | ||
| setFilter = {setFilter} /> | ||
| ) | ||
| }); | ||
|
|
||
|
|
||
| const addTask = (name) => { | ||
| const newTask = { id: `todo-${nanoid()}`, name: name, status: 'active' }; | ||
| const theTasks = this.state.tasks | ||
| this.setState({ | ||
| tasks: [ ...theTasks, newTask] | ||
| }); | ||
| } | ||
|
|
||
| const clearCompleted = () => { | ||
| const updatedTasks = tasks.filter(task => task.status !== 'completed'); | ||
|
|
||
| this.setState({ | ||
| tasks: updatedTasks | ||
| }) | ||
| }; | ||
|
|
||
| const activeTasks = tasks.filter(task => { | ||
| return task.status === 'active'; | ||
| }) | ||
| const tasksNoun = activeTasks.length > 1 ? 'tasks' : 'task'; | ||
| const taskLeft = `${activeTasks.length} ${tasksNoun} left`; | ||
|
|
||
| return ( | ||
| <div className = "todoapp"> | ||
| <h1>HOOPLA</h1> | ||
| <Form addTask = {addTask} /> | ||
| <div className = "todo-container"> | ||
| <div className = "todo-list"> | ||
| <ul aria-labelledby = "list-heading"> | ||
| {tasklist} | ||
| </ul> | ||
|
|
||
| <div className = "todo-extras2 show"> | ||
| <h2 className = "list-number"> | ||
| {taskLeft} | ||
| </h2> | ||
| <ClearButton clear = {clearCompleted} /> | ||
| </div> | ||
| </div> | ||
| <div className = "todo-extras"> | ||
| <h2 className = "list-number"> | ||
| {taskLeft} | ||
| </h2> | ||
| <div className = "filters"> | ||
| {filterList} | ||
| </div> | ||
| <ClearButton clear = {clearCompleted} /> | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export default App; | ||
8 changes: 8 additions & 0 deletions
8
submissions/KelechiPreciousNwachukwu/React/todo-App/src/App.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import App from './App'; | ||
|
|
||
| test('renders learn react link', () => { | ||
| render(<App />); | ||
| const linkElement = screen.getByText(/learn react/i); | ||
| expect(linkElement).toBeInTheDocument(); | ||
| }); |
23 changes: 23 additions & 0 deletions
23
submissions/KelechiPreciousNwachukwu/React/todo-App/src/components/Button.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from 'react'; | ||
|
|
||
| const Button = (props) => { | ||
| const classname = () => { | ||
| if (props.name === 'Active') return 'btn active'; | ||
| else if (props.name === 'Completed') return 'btn completed-button'; | ||
|
|
||
| return 'btn all'; | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| type = "button" | ||
| className = {classname()} | ||
| aria-pressed = {props.isPressed} | ||
| onClick = {() => props.setFilter(props.name)} | ||
| > | ||
| {props.name} | ||
| </button> | ||
| ) | ||
| } | ||
|
|
||
| export default Button; |
18 changes: 18 additions & 0 deletions
18
submissions/KelechiPreciousNwachukwu/React/todo-App/src/components/ClearButton.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from 'react'; | ||
|
|
||
| const ClearButton = (props) => { | ||
| return ( | ||
| <div className = "clear"> | ||
| <button | ||
| type = "button" | ||
| className = "btn clear" | ||
| aria-pressed = {true} | ||
| onClick = {props.clear} | ||
| > | ||
| X Clear Completed | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ClearButton; |
36 changes: 36 additions & 0 deletions
36
submissions/KelechiPreciousNwachukwu/React/todo-App/src/components/Form.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React, { Component } from 'react'; | ||
|
|
||
| class Form extends Component { | ||
| state = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should add your state in a constructor @PluckyPrecious |
||
| inputText: '' | ||
| } | ||
|
|
||
| handleSubmit = (e) => { | ||
| e.preventDefault(); | ||
|
|
||
| if (this.state.inputText !== '') { | ||
| this.props.addTask(this.state.inputText); | ||
| this.setState({ | ||
| inputText: '' | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <form onSubmit = {this.handleSubmit}> | ||
| <input | ||
| type = "text" | ||
| className = "input-todo" | ||
| name = "todo" | ||
| placeholder = "Create a new todo..." | ||
| autoComplete = "off" | ||
| value = {this.state.inputText} | ||
| onChange = {e => this.setState({ inputText: e.target.value})} /> | ||
| <button type = "submit" className = "btn-submit">+</button> | ||
| </form> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Form; | ||
18 changes: 18 additions & 0 deletions
18
submissions/KelechiPreciousNwachukwu/React/todo-App/src/components/Todo.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from 'react'; | ||
|
|
||
| const Todo = (props) => { | ||
| return ( | ||
| <li className = "todo"> | ||
| <div className = "todo-item"> | ||
| <label className = {props.status} htmlFor = {props.id}>{props.name}</label> | ||
| <input | ||
| id = {props.id} | ||
| type = "checkbox" | ||
| onChange = { () => props.toggleStatus(props.id) } | ||
| className = {props.status} /> | ||
| </div> | ||
| </li> | ||
| ) | ||
| } | ||
|
|
||
| export default Todo; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should add your state in a constructor @PluckyPrecious