Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bbece4d
Adding all files
rachetm Feb 5, 2020
189ae58
Fixed clear on add
rachetm Feb 5, 2020
cc6c8f3
Added redux functionality
rachetm Feb 5, 2020
9194287
Update README.md
rachetm Feb 5, 2020
fea5d4f
Added search option
rachetm Feb 6, 2020
bfc53d5
Fixed textfield not clearing on adding todo
rachetm Feb 9, 2020
f2b8cab
Changed add.js filename to Add.js
rachetm Feb 14, 2020
f906f0d
Changed Readme
rachetm Feb 14, 2020
8827a00
Merged adding-redux branch
rachetm Feb 14, 2020
eb571e5
Merged branch add-search-capability
rachetm Feb 14, 2020
33f5401
Moved components/Add/Add.js to components/Add.js
rachetm Feb 14, 2020
85d6d6b
Added search icon
rachetm Feb 14, 2020
f6996df
Added hook in Add.js
rachetm Feb 14, 2020
98b297d
Added props validation and made changes to app layout
rachetm Feb 14, 2020
c7e740a
Made Requested changes
rachetm Feb 17, 2020
201b8f7
Minor fix
rachetm Feb 17, 2020
36676b6
Removed unnecessary value key in state
rachetm Feb 18, 2020
b61414b
Used input adornment for search icon
rachetm Feb 18, 2020
eb98a6f
1. Removed unnecessary <div>
rachetm Feb 18, 2020
d013fbe
Modified package.json
rachetm Feb 19, 2020
9b1380b
Removed unnecessary styles used after using material-ui components
rachetm Feb 19, 2020
4a6cb71
Changed title prop value
rachetm Feb 19, 2020
c20adc9
Moved default values to inside cases
rachetm Feb 19, 2020
6f383cb
Changed to Grid layout
rachetm Feb 19, 2020
84254a8
Changed to grid layout and used IconButton component
rachetm Feb 19, 2020
3658697
Moved redundant code to a function
rachetm Feb 19, 2020
84d6368
Used grid layout and Typography
rachetm Feb 19, 2020
210f74e
Used grid layout and Typography
rachetm Feb 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ dist

# TernJS port file
.tern-port

.vscode

.eslintrc.json

package-lock.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# todo-react
A simple todo app written in React
A simple todo app written in React with Redux
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "todo",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.1.3",
"react-scripts": "3.4.0",
"redux": "^4.0.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.18.0"
}
}
22 changes: 22 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<script src="https://kit.fontawesome.com/07ffa00fcf.js" crossorigin="anonymous"></script>
<title>Todo App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
29 changes: 29 additions & 0 deletions src/actions/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const addTodo = content => {
return {
type: "ADD_TODO",
content: content
}
}

const removeTodo = id => {
return {
type: "REMOVE_TODO",
id: id
}
}

const mark_checked = id => {
return {
type: "MARK_CHECKED",
id: id
}
}

const searchTodo = keyword => {
return {
type: "SEARCH",
keyword
}
}

export {addTodo, mark_checked, removeTodo, searchTodo}
69 changes: 69 additions & 0 deletions src/components/Add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useState } from "react";
import { connect } from "react-redux";
import { addTodo } from "../actions/actions";
import { Grid } from "@material-ui/core";
import InputAdornment from "@material-ui/core/InputAdornment";
import Button from "@material-ui/core/Button";
import TextField from "@material-ui/core/TextField";
import PropTypes from "prop-types";
import PlusIcon from "@material-ui/icons/AddRounded";

function Add(props) {
const [value, setValue] = useState("");

function onKeyDown(e) {
if (e.keyCode === 13 && !/^\s*$/.test(e.target.value)) {
props.addTodo(e.target.value);
setValue("");
}
}

function onClick() {
if (!/^\s*$/.test(value)) {
props.addTodo(value);
setValue("");
}
}

return (
<Grid container spacing={2} justify="center" alignItems="flex-end">
<Grid item>
<TextField
id="add-todo-field"
label="Add an item"
className="add-todo"
onKeyDown={e => onKeyDown(e)}
onChange={e => {
setValue(e.target.value);
}}
value={value}
autoFocus={true}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<PlusIcon />
</InputAdornment>
)
}}
/>
</Grid>
<Grid item>
<Button variant="contained" id="addBtn" onClick={onClick}>
Add
</Button>
</Grid>
</Grid>
);
}

const mapDispatchToProps = dispatch => {
return {
addTodo: id => dispatch(addTodo(id))
};
};

Add.propTypes = {
addTodo: PropTypes.func
};

export default connect(null, mapDispatchToProps)(Add);
58 changes: 58 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from "react";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import Add from "./Add";
import Items from "./Items/items";
import Search from "./Search";
import Counter from "./Counter";
import PropTypes from "prop-types";
class App extends React.Component {
render() {
return (
<>
<Grid container direction="column">
<Typography variant="h1" gutterBottom className="title">
Todo
</Typography>
<Grid container style={{ flex: "1", flexWrap: "nowrap" }}>
<Grid
container
item
sm={6}
direction="column"
style={{ flex: "1" }}
>
<Add />
<Counter />
</Grid>
<Grid container item sm={6} direction="column" alignItems="center">
<Search />
<Grid
container
item
direction="column"
spacing={2}
sm={10}
style={{
marginTop: "5%",
overflow: "auto",
flexWrap: "nowrap",
flex: "1 1 1px",
marginBottom: "20px"
}}
>
<Items />
</Grid>
</Grid>
</Grid>
</Grid>
</>
);
}
}

App.propTypes = {
title: PropTypes.string
};

export default App;
93 changes: 93 additions & 0 deletions src/components/Counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from "react";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
function Counter(props) {
const { totalCount, doneCount, notDoneCount } = props;
return (
<>
<Grid
container
spacing={2}
alignItems="center"
justify="center"
style={{ marginTop: "10%" }}
direction="column"
>
<Grid
container
item
spacing={2}
alignItems="baseline"
justify="space-between"
sm={3}
>
<Grid item>
<Typography variant="h2">
{totalCount > 9 ? totalCount : "0" + totalCount}
</Typography>
</Grid>
<Grid container style={{ flex: 1, marginLeft: "4px" }} item>
<Typography variant="h5">
Todo{totalCount > 1 || totalCount === 0 ? "s" : ""}
</Typography>
</Grid>
</Grid>
<Grid
container
item
spacing={2}
alignItems="baseline"
justify="space-between"
sm={3}
>
<Grid item>
<Typography variant="h2">
{doneCount > 9 ? doneCount : "0" + doneCount}
</Typography>
</Grid>
<Grid container style={{ flex: 1, marginLeft: "4px" }} item>
<Typography variant="h5">Done</Typography>
</Grid>
</Grid>
<Grid
container
item
spacing={2}
alignItems="baseline"
justify="space-between"
sm={3}
>
<Grid item>
<Typography variant="h2">
{notDoneCount > 9 ? notDoneCount : "0" + notDoneCount}
</Typography>
</Grid>
<Grid container style={{ flex: 1, marginLeft: "4px" }} item>
<Typography variant="h5">Not Done</Typography>
</Grid>
</Grid>
</Grid>
</>
);
}

const mapStateToProps = state => {
let totalCount = state.items ? state.items.length : 0,
doneCount = 0,
notDoneCount = 0;
if (state.items)
state.items.forEach(item => {
item.checked === true ? doneCount++ : notDoneCount++;
});
return { totalCount, doneCount, notDoneCount };
};

Counter.propTypes = {
totalCount: PropTypes.number,
doneCount: PropTypes.number,
notDoneCount: PropTypes.number
};

export default connect(mapStateToProps, null)(Counter);
Loading