Skip to content
Open

Hw 6 #44

Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# react-intensive
# 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/).
15,133 changes: 15,133 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "hw-6",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"@types/node": "^16.11.47",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/react-redux": "^7.1.24",
"@types/react-router-dom": "^5.3.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
},
"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"
]
},
"devDependencies": {
"@types/jest": "^27.5.2",
"jest": "^28.1.3"
}
}
12 changes: 12 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hw 6</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
17 changes: 17 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 20px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.app {
height: 100vh;
width: 100vw;
}
12 changes: 12 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "./App.css";
import AppRoutes from "./pages/AppRoutes";

const App = () => {
return (
<div className="app">
<AppRoutes />
</div>
);
};

export default App;
14 changes: 14 additions & 0 deletions src/assets/Check.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Check = () => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24"
viewBox="0 0 24 24"
width="24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
);
};

export default Check;
14 changes: 14 additions & 0 deletions src/assets/Delete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Delete = () => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24"
viewBox="0 0 24 24"
width="24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" />
</svg>
);
};

export default Delete;
14 changes: 14 additions & 0 deletions src/assets/Edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Edit = () => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24"
viewBox="0 0 24 24"
width="24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" />
</svg>
);
};

export default Edit;
14 changes: 14 additions & 0 deletions src/assets/Undo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Undo = () => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24"
viewBox="0 0 24 24"
width="24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z" />
</svg>
);
};

export default Undo;
11 changes: 11 additions & 0 deletions src/components/Header/Header.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.header {
display: flex;
justify-content: space-around;
padding-top: 20px;
padding-bottom: 20px;
}

.btn {
font-weight: bold;
cursor: pointer;
}
26 changes: 26 additions & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styles from "./Header.module.css";
import calculateActiveTodos from "./calculateActiveTodos/calculateActiveTodos";
import useTypedSelector from "./../../store/hooks/useTypedSelector";
import useActions from "./../../store/hooks/useActions";

const Header = () => {
const { todos } = useTypedSelector((state) => state.todo);
const { logout } = useActions();
const { username } = useTypedSelector((state) => state.user);
console.log(todos);

return (
<div className={styles.header}>
<div>
Пользователь: {username}
<br />
Активных задач: {calculateActiveTodos(todos)}
</div>
<div onClick={logout} className={styles.btn}>
Выйти
</div>
</div>
);
};

export default Header;
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import calculateActiveTodos from "./calculateActiveTodos";

test("Empty array", () => {
expect(calculateActiveTodos([])).toEqual(0);
});

test("Only active", () => {
expect(
calculateActiveTodos([
{
id: 1660034950746,
isDone: false,
text: "1",
},
])
).toEqual(1);
});

test("Three active todos", () => {
expect(
calculateActiveTodos([
{
id: 1660034950746,
isDone: false,
text: "1",
},
{
id: 1660034952201,
isDone: false,
text: "2",
},
{
id: 1660034953169,
isDone: false,
text: "3",
},
])
).toEqual(3);
});

test("Three inactive todos", () => {
expect(
calculateActiveTodos([
{
id: 1660034950746,
isDone: true,
text: "1",
},
{
id: 1660034952201,
isDone: true,
text: "2",
},
{
id: 1660034953169,
isDone: true,
text: "3",
},
])
).toEqual(0);
});

test("Three active, two inactive", () => {
expect(
calculateActiveTodos([
{
id: 1660034950746,
isDone: false,
text: "1",
},
{
id: 1660034952201,
isDone: true,
text: "2",
},
{
id: 1660034953169,
isDone: false,
text: "3",
},
{
id: 1660035092769,
isDone: true,
text: "4",
},
{
id: 1660035093738,
isDone: false,
text: "5",
},
])
).toEqual(3);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Todo } from '../../../store/reducers/todoReducer'

const calculateActiveTodos = (todos: Todo[]) =>
todos.reduce((prev, curr) => prev + +!curr.isDone, 0);

export default calculateActiveTodos
17 changes: 17 additions & 0 deletions src/components/NewTodo/NewTodo.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.add > input {
width: 280px;
border: 0;
}

.add {
border: 1px solid black;
display: flex;
flex-direction: row;
width: 300px;
margin-bottom: 20px;
}

.add > div {
cursor: pointer;
color: black;
}
Loading