Skip to content

Commit f59eb21

Browse files
committed
init commit
1 parent 155f415 commit f59eb21

25 files changed

+343
-158
lines changed

Diff for: README.md

+2-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
1-
# Getting Started with Create React App
1+
## Если воспользовался репозиторием, дай обратную связь - поставь звезду
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4-
5-
## Available Scripts
6-
7-
In the project directory, you can run:
8-
9-
### `npm start`
10-
11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13-
14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
16-
17-
### `npm test`
18-
19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `npm run build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `npm run eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35-
36-
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.
37-
38-
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.
39-
40-
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.
41-
42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
3+
### npm start - запуск

Diff for: package-lock.json

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
"@types/node": "^12.19.15",
1111
"@types/react": "^16.14.2",
1212
"@types/react-dom": "^16.9.10",
13+
"@types/react-redux": "^7.1.16",
14+
"axios": "^0.21.1",
1315
"react": "^17.0.1",
1416
"react-dom": "^17.0.1",
17+
"react-redux": "^7.2.2",
1518
"react-scripts": "4.0.1",
19+
"redux": "^4.0.5",
20+
"redux-thunk": "^2.3.0",
1621
"typescript": "^4.1.3",
1722
"web-vitals": "^0.2.4"
1823
},

Diff for: src/App.css

-38
This file was deleted.

Diff for: src/App.test.tsx

-9
This file was deleted.

Diff for: src/App.tsx

+11-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
2+
import UserList from "./components/UserList";
3+
import TodoList from "./components/TodoList";
44

5-
function App() {
6-
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
23-
);
24-
}
5+
const App = () => {
6+
return (
7+
<div>
8+
<UserList/>
9+
<hr/>
10+
<TodoList/>
11+
</div>
12+
);
13+
};
2514

2615
export default App;

Diff for: src/components/TodoList.tsx

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, {useEffect} from 'react';
2+
import {useTypedSelector} from "../hooks/useTypedSelector";
3+
import {useActions} from "../hooks/useActions";
4+
5+
const TodoList: React.FC = () => {
6+
const {page, error, loading, todos, limit} = useTypedSelector(state => state.todo)
7+
const {fetchTodos, setTodoPage} = useActions()
8+
const pages = [1, 2, 3, 4, 5]
9+
10+
useEffect(() => {
11+
fetchTodos(page, limit)
12+
}, [page])
13+
14+
if (loading) {
15+
return <h1>Идет загрузка...</h1>
16+
}
17+
if (error) {
18+
return <h1>{error}</h1>
19+
}
20+
21+
return (
22+
<div>
23+
{todos.map(todo =>
24+
<div key={todo.id}>{todo.id} - {todo.title}</div>
25+
)}
26+
<div style={{display: "flex"}}>
27+
{pages.map(p =>
28+
<div
29+
onClick={() => setTodoPage(p)}
30+
style={{border:p === page ? '2px solid green' : '1px solid gray', padding: 10}}
31+
>
32+
{p}
33+
</div>
34+
)}
35+
</div>
36+
</div>
37+
);
38+
};
39+
40+
export default TodoList;

Diff for: src/components/UserList.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, {useEffect} from 'react';
2+
import {useTypedSelector} from "../hooks/useTypedSelector";
3+
import {fetchUsers} from "../store/action-creators/user";
4+
import {useActions} from "../hooks/useActions";
5+
6+
const UserList: React.FC = () => {
7+
const {users, error, loading} = useTypedSelector(state => state.user)
8+
const {fetchUsers} = useActions()
9+
10+
useEffect(() => {
11+
fetchUsers()
12+
}, [])
13+
14+
if (loading) {
15+
return <h1>Идет загрузка...</h1>
16+
}
17+
if (error) {
18+
return <h1>{error}</h1>
19+
}
20+
21+
return (
22+
<div>
23+
{users.map(user =>
24+
<div key={user.id}>{user.name}</div>
25+
)}
26+
</div>
27+
);
28+
};
29+
30+
export default UserList;

Diff for: src/hooks/useActions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {useDispatch} from "react-redux";
2+
import {bindActionCreators} from "redux";
3+
import ActionCreators from '../store/action-creators/'
4+
5+
export const useActions = () => {
6+
const dispatch = useDispatch()
7+
return bindActionCreators(ActionCreators, dispatch)
8+
}

Diff for: src/hooks/useTypedSelector.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {TypedUseSelectorHook, useSelector} from "react-redux";
2+
import {RootState} from "../store/reducers";
3+
4+
5+
export const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector

Diff for: src/index.css

-13
This file was deleted.

Diff for: src/index.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import './index.css';
43
import App from './App';
5-
import reportWebVitals from './reportWebVitals';
4+
import {Provider} from "react-redux";
5+
import {store} from "./store";
66

77
ReactDOM.render(
8-
<React.StrictMode>
9-
<App />
10-
</React.StrictMode>,
8+
<Provider store={store}>
9+
<App />
10+
</Provider>,
1111
document.getElementById('root')
1212
);
1313

14-
// If you want to start measuring performance in your app, pass a function
15-
// to log results (for example: reportWebVitals(console.log))
16-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17-
reportWebVitals();

Diff for: src/logo.svg

-1
This file was deleted.

Diff for: src/react-app-env.d.ts

-1
This file was deleted.

0 commit comments

Comments
 (0)