Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 3187f86

Browse files
all eslint errors are fixed
1 parent ac77ad0 commit 3187f86

28 files changed

+182
-94
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run lint-staged

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,47 @@ In the project directory, you can run:
66

77
### `yarn start`
88

9-
Runs the app in the development mode.<br />
10-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
9+
Runs the app in the development mode.<br /> Open [http://localhost:3000](http://localhost:3000) to
10+
view it in the browser.
1111

12-
The page will reload if you make edits.<br />
13-
You will also see any lint errors in the console.
12+
The page will reload if you make edits.<br /> You will also see any lint errors in the console.
1413

1514
### `yarn test`
1615

17-
Launches the test runner in the interactive watch mode.<br />
18-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
16+
Launches the test runner in the interactive watch mode.<br /> See the section about
17+
[running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more
18+
information.
1919

2020
### `yarn build`
2121

22-
Builds the app for production to the `build` folder.<br />
23-
It correctly bundles React in production mode and optimizes the build for the best performance.
22+
Builds the app for production to the `build` folder.<br /> It correctly bundles React in production
23+
mode and optimizes the build for the best performance.
2424

25-
The build is minified and the filenames include the hashes.<br />
26-
Your app is ready to be deployed!
25+
The build is minified and the filenames include the hashes.<br /> Your app is ready to be deployed!
2726

28-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
27+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for
28+
more information.
2929

3030
### `yarn eject`
3131

3232
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
3333

34-
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.
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time.
35+
This command will remove the single build dependency from your project.
3536

36-
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.
37+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel,
38+
ESLint, etc) right into your project so you have full control over them. All of the commands except
39+
`eject` will still work, but they will point to the copied scripts so you can tweak them. At this
40+
point you’re on your own.
3741

38-
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.
42+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle
43+
deployments, and you shouldn’t feel obligated to use this feature. However we understand that this
44+
tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
3945

4046
## Learn More
4147

42-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
48+
You can learn more in the
49+
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
4350

4451
To learn React, check out the [React documentation](https://reactjs.org/).
4552

@@ -49,11 +56,13 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/co
4956

5057
### Analyzing the Bundle Size
5158

52-
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
59+
This section has moved here:
60+
https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
5361

5462
### Making a Progressive Web App
5563

56-
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
64+
This section has moved here:
65+
https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
5766

5867
### Advanced Configuration
5968

@@ -65,4 +74,5 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/de
6574

6675
### `yarn build` fails to minify
6776

68-
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
77+
This section has moved here:
78+
https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

README.old.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# todo-app-hackerearth
1+
# todo-app-hackerearth

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"eslint-plugin-react": "^7.27.1",
7777
"eslint-plugin-react-hooks": "^4.3.0",
7878
"fs": "0.0.1-security",
79-
"husky": "^7.0.4",
79+
"husky": "^7.0.0",
8080
"jest": "^26.6.3",
8181
"lint-staged": "^12.1.2",
8282
"path": "^0.12.7",

public/my-serviceworker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable array-callback-return */
2+
/* eslint-disable consistent-return */
13
const CACHE_NAME = 'version-1';
24
const urlsToCache = [
35
'/',

src/components/common/ErrorBoundary.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react';
2-
// import { Link } from 'react-router-dom';
2+
import { Link } from 'react-router-dom';
3+
import PropTypes from 'prop-types';
34

45
export default class ErrorBoundary extends Component {
56
constructor(props) {
@@ -19,16 +20,23 @@ export default class ErrorBoundary extends Component {
1920
}
2021

2122
render() {
22-
if (this.state.hasError) {
23+
const { hasError } = this.state;
24+
const { children } = this.props;
25+
26+
if (hasError) {
2327
// You can render any custom fallback UI
2428
return (
2529
<div className="center">
2630
<h1 className="center p-20 warn gr-bc">Sorry something went wrong.</h1>
27-
{/* <Link to="/logout">Logout</Link> */}
31+
<Link to="/logout">Logout</Link>
2832
</div>
2933
);
3034
}
3135

32-
return this.props.children;
36+
return children;
3337
}
3438
}
39+
40+
ErrorBoundary.propTypes = {
41+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
42+
};

src/components/common/Loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export default function Loader() {
1616
};
1717

1818
return (
19-
<>
19+
<div>
2020
{loader && (
2121
<div className="loaderbox">
2222
<Lottie options={defaultOptions} height={128} width={128} />
2323
</div>
2424
)}
25-
</>
25+
</div>
2626
);
2727
}

src/components/routes/AuthRoute.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { Route, Redirect } from 'react-router-dom';
3+
import PropTypes from 'prop-types';
34
import { SESSION } from '../../services';
45

56
function AuthRoute({ children, ...rest }) {
@@ -15,4 +16,8 @@ function AuthRoute({ children, ...rest }) {
1516
return <Route {...rest}>{children}</Route>;
1617
}
1718

19+
AuthRoute.propTypes = {
20+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
21+
};
22+
1823
export default AuthRoute;

src/components/routes/PrivateRoute.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Layout } from 'antd';
22
import React, { useEffect } from 'react';
33
import { useDispatch } from 'react-redux';
44
import { Route } from 'react-router-dom';
5+
import PropTypes from 'prop-types';
56
import { SESSION } from '../../services';
67
// import { Sidebar } from '../sidebar';
78
import { HeadNavbar } from '../common';
@@ -42,4 +43,9 @@ function PrivateRoute({ children, location, ...rest }) {
4243
SESSION.logout();
4344
}
4445

46+
PrivateRoute.propTypes = {
47+
location: PropTypes.object,
48+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
49+
};
50+
4551
export default PrivateRoute;

src/components/sidebar/Sidebar.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
import React, { useState, useEffect } from 'react';
22
import { Layout, Menu } from 'antd';
3+
import PropTypes from 'prop-types';
34
import { NavLink, withRouter } from 'react-router-dom';
45
import { PoweroffOutlined, HighlightOutlined } from '@ant-design/icons';
56
import { findUrlPathId, handleLogout } from './Sidebar.controller';
67

78
const { Sider } = Layout;
89

9-
function Sidebar(props) {
10+
function Sidebar({ location }) {
1011
const [collapsed, setCollapsed] = useState(false);
1112
const [key, setKey] = useState();
1213

1314
useEffect(() => {
14-
const path = props.location.pathname;
15-
const pathId = findUrlPathId(path);
15+
const { pathname } = location;
16+
const pathId = findUrlPathId(pathname);
1617
setKey(pathId);
1718
// eslint-disable-next-line react-hooks/exhaustive-deps
18-
}, [props.location.pathname]);
19+
}, [location.pathname]);
1920

20-
function onCollapse(collapsed) {
21-
setCollapsed(collapsed);
21+
function onCollapse(data) {
22+
setCollapsed(data);
2223
}
2324

2425
return (
2526
<Sider collapsible collapsed={collapsed} onCollapse={onCollapse}>
26-
<>
27-
<Menu theme="dark" mode="inline" defaultSelectedKeys={[key]} selectedKeys={[key]}>
28-
<Menu.Item key="1">
29-
<NavLink to="/todo" />
30-
<HighlightOutlined />
31-
<span>Todo</span>
32-
</Menu.Item>
33-
34-
<Menu.Item key="4" onClick={handleLogout}>
35-
<PoweroffOutlined />
36-
<span>Log Out</span>
37-
</Menu.Item>
38-
</Menu>
39-
</>
27+
<Menu theme="dark" mode="inline" defaultSelectedKeys={[key]} selectedKeys={[key]}>
28+
<Menu.Item key="1">
29+
<NavLink to="/todo" />
30+
<HighlightOutlined />
31+
<span>Todo</span>
32+
</Menu.Item>
33+
34+
<Menu.Item key="4" onClick={handleLogout}>
35+
<PoweroffOutlined />
36+
<span>Log Out</span>
37+
</Menu.Item>
38+
</Menu>
4039
</Sider>
4140
);
4241
}
4342

43+
Sidebar.propTypes = {
44+
location: PropTypes.object,
45+
};
46+
4447
export default withRouter(Sidebar);

src/components/todo/TodoBox.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { TodoDate, TodoActionControls, TodoLabel } from '.';
34

45
export default function TodoBox(props) {
@@ -14,3 +15,10 @@ export default function TodoBox(props) {
1415
</div>
1516
);
1617
}
18+
19+
TodoBox.propTypes = {
20+
data: PropTypes.shape({
21+
title: PropTypes.string,
22+
description: PropTypes.string,
23+
}),
24+
};

src/components/todo/TodoDate.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React, { useState, useEffect } from 'react';
22
import { Tag } from 'antd';
33
import { ClockCircleOutlined } from '@ant-design/icons';
44
import moment from 'moment';
5+
import PropTypes from 'prop-types';
56

67
export default function TodoDate({ data }) {
78
const [date, setDate] = useState('Date not available');
89
useEffect(() => {
910
if (data.dueDate) {
10-
const date = moment(data.dueDate).format('DD MMM YYYY');
11-
setDate(date);
11+
const dateNew = moment(data.dueDate).format('DD MMM YYYY');
12+
setDate(dateNew);
1213
}
1314
}, [data]);
1415

@@ -18,3 +19,10 @@ export default function TodoDate({ data }) {
1819
</Tag>
1920
);
2021
}
22+
23+
TodoDate.propTypes = {
24+
data: PropTypes.shape({
25+
dueDate: PropTypes.string,
26+
description: PropTypes.string,
27+
}),
28+
};

src/components/todo/TodoDelete.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { useDispatch } from 'react-redux';
33
import { Button, Popconfirm, message } from 'antd';
44
import { DeleteOutlined } from '@ant-design/icons';
5+
import PropTypes from 'prop-types';
56
import { API } from '../../services';
67
import { updatedTodoList } from '../../store/actions/api.actions';
78

@@ -32,3 +33,9 @@ export default function TodoDelete({ data }) {
3233
</Popconfirm>
3334
);
3435
}
36+
37+
TodoDelete.propTypes = {
38+
data: PropTypes.shape({
39+
_id: PropTypes.string,
40+
}),
41+
};

src/components/todo/TodoEdit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { useDispatch } from 'react-redux';
33
import { Button } from 'antd';
4+
import PropTypes from 'prop-types';
45
import { EditOutlined } from '@ant-design/icons';
56
import { editTodo } from '../../store/actions/api.actions';
67

@@ -13,3 +14,9 @@ export default function TodoEdit({ data }) {
1314

1415
return <Button onClick={handleEdit} icon={<EditOutlined />} />;
1516
}
17+
18+
TodoEdit.propTypes = {
19+
data: PropTypes.shape({
20+
_id: PropTypes.string,
21+
}),
22+
};

src/components/todo/TodoLabel.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useEffect } from 'react';
22
import { Tag } from 'antd';
3+
import PropTypes from 'prop-types';
34
import { TODO_LABEL } from '../../helpers/constants';
45

56
export default function TodoLabel({ data }) {
@@ -18,3 +19,9 @@ export default function TodoLabel({ data }) {
1819
}, [data]);
1920
return <Tag color={state.color}>{state.key}</Tag>;
2021
}
22+
23+
TodoLabel.propTypes = {
24+
data: PropTypes.shape({
25+
label: PropTypes.string,
26+
}),
27+
};

src/components/todo/TodoList.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ export default function TodoList() {
4141
/**
4242
* find label id from selected label checkboxes
4343
*/
44-
const labels = TODO_LABEL.filter((label) => state.checkedList.includes(label.key)).map(
45-
(todo) => todo.id
46-
);
44+
const labelsSelected = TODO_LABEL.filter((label) =>
45+
state.checkedList.includes(label.key)
46+
).map((todo) => todo.id);
4747

4848
/**
4949
* filter out todo based on selected labels
5050
*/
51-
const filtered = todos.filter((todo) => labels.includes(todo.label));
51+
const filtered = todos.filter((todo) => labelsSelected.includes(todo.label));
5252

5353
/**
5454
* Group the todos based on status (New, inprogress, completed)
5555
*/
56-
const grouped = mapValues(groupBy(filtered, 'status'));
57-
setGrouped(grouped);
56+
const groupedFiltered = mapValues(groupBy(filtered, 'status'));
57+
setGrouped(groupedFiltered);
5858
}, [todos, state]);
5959

6060
const onChange = (checkedList) => {

0 commit comments

Comments
 (0)