Skip to content

Hotfix/2021 07 24 add config redux devtools #2

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-redux": "^7.2.2",
"react-scripts": "4.0.1",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.3.0",
"typescript": "^4.1.3",
"web-vitals": "^0.2.4"
Expand Down
19 changes: 10 additions & 9 deletions src/components/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, {useEffect} from 'react';
import {useTypedSelector} from "../hooks/useTypedSelector";
import {useActions} from "../hooks/useActions";
import { useEffect, FC } from 'react';
import { useTypedSelector } from "../hooks/useTypedSelector";
import { useActions } from "../hooks/useActions";
import { TodoModel } from '../types/todo';

const TodoList: React.FC = () => {
const {page, error, loading, todos, limit} = useTypedSelector(state => state.todo)
const {fetchTodos, setTodoPage} = useActions()
const TodoList: FC = () => {
const { page, error, loading, todos, limit } = useTypedSelector(state => state.todo)
const { fetchTodos, setTodoPage } = useActions()
const pages = [1, 2, 3, 4, 5]

useEffect(() => {
Expand All @@ -20,14 +21,14 @@ const TodoList: React.FC = () => {

return (
<div>
{todos.map(todo =>
{todos.map((todo: TodoModel) =>
<div key={todo.id}>{todo.id} - {todo.title}</div>
)}
<div style={{display: "flex"}}>
<div style={{ display: "flex" }}>
{pages.map(p =>
<div
onClick={() => setTodoPage(p)}
style={{border:p === page ? '2px solid green' : '1px solid gray', padding: 10}}
style={{ border: p === page ? '2px solid green' : '1px solid gray', padding: 10 }}
>
{p}
</div>
Expand Down
18 changes: 9 additions & 9 deletions src/components/UserList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {useEffect} from 'react';
import {useTypedSelector} from "../hooks/useTypedSelector";
import {fetchUsers} from "../store/action-creators/user";
import {useActions} from "../hooks/useActions";
import { useEffect, FC } from 'react';
import { useTypedSelector } from "../hooks/useTypedSelector";
import { useActions } from "../hooks/useActions";
import { UserModel } from '../types/user';

const UserList: React.FC = () => {
const {users, error, loading} = useTypedSelector(state => state.user)
const {fetchUsers} = useActions()
const UserList: FC = () => {
const { users, error, loading } = useTypedSelector(state => state.user)
const { fetchUsers } = useActions()

useEffect(() => {
fetchUsers()
Expand All @@ -20,8 +20,8 @@ const UserList: React.FC = () => {

return (
<div>
{users.map(user =>
<div key={user.id}>{user.name}</div>
{users.map((user: UserModel) =>
<div key={user.id}>Name: {user.name} - company: {user.company.name}</div>
)}
</div>
);
Expand Down
13 changes: 10 additions & 3 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import {applyMiddleware, createStore} from "redux";
import { createStore, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import {rootReducer} from "./reducers";
import { rootReducer } from "./reducers";

declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
}
}

export const store = createStore(rootReducer, applyMiddleware(thunk))
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

export const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));
12 changes: 9 additions & 3 deletions src/types/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface TodoState {
}

export enum TodoActionTypes {
FETCH_TODOS= 'FETCH_TODOS',
FETCH_TODOS_SUCCESS= 'FETCH_TODOS_SUCCESS',
FETCH_TODOS_ERROR= 'FETCH_TODOS_ERROR',
FETCH_TODOS = 'FETCH_TODOS',
FETCH_TODOS_SUCCESS = 'FETCH_TODOS_SUCCESS',
FETCH_TODOS_ERROR = 'FETCH_TODOS_ERROR',
SET_TODO_PAGE = 'SET_TODO_PAGE'
}
interface FetchTodoAction {
Expand All @@ -27,6 +27,12 @@ interface SetTodoPage {
type: TodoActionTypes.SET_TODO_PAGE;
payload: number;
}
export interface TodoModel {
id: number;
userId: number;
title: string;
completed: boolean;
}

export type TodoAction =
FetchTodoAction
Expand Down
31 changes: 31 additions & 0 deletions src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,35 @@ interface FetchUsersErrorAction {
type: UserActionTypes.FETCH_USERS_ERROR;
payload: string;
}

export interface UserModel {
id: number;
name: string;
username: string;
email: string;
address: Address;
phone: string;
website: string;
company: Company;
}

interface Address {
street: string;
suite: string;
city: string;
zipcode: string;
geo: Geo;
}

interface Geo {
lat: string;
lng: string;
}

interface Company {
name: string;
catchPhrase: string;
bs: string;
}

export type UserAction = FetchUsersAction | FetchUsersErrorAction | FetchUsersSuccessAction