From d545e3e65e4a4351b90f8da7f59d526496d643cb Mon Sep 17 00:00:00 2001 From: Nix13 Date: Tue, 13 Oct 2020 14:37:25 +0300 Subject: [PATCH] redux ducks --- src/pages/ActivateAccount.tsx | 6 ++-- src/pages/AdminPanel/News/APModifyPost.tsx | 5 +-- src/pages/AdminPanel/Users/ModifyUser.tsx | 4 +-- src/pages/App/App.tsx | 6 ++-- src/pages/Comments/Comments.tsx | 14 ++++---- src/pages/Modals/LoginModal.tsx | 4 ++- src/pages/Modals/RegisterModal.tsx | 3 +- src/pages/Navbar/Navbar.tsx | 3 +- src/pages/Novel/Novel.tsx | 4 +-- src/pages/User/Settings/Appearance.tsx | 17 +++++++-- src/pages/User/Settings/Settings.tsx | 4 +-- src/pages/User/User.tsx | 5 ++- src/store/actionTypes.ts | 9 ----- src/store/actions.ts | 27 -------------- src/store/{reducers => ducks}/currentUser.ts | 26 +++++++++----- src/store/ducks/index.ts | 6 ++++ src/store/ducks/modal.ts | 36 +++++++++++++++++++ .../{reducers => ducks}/notifications.ts | 24 +++++++++---- src/store/reducers/modal.ts | 21 ----------- src/store/reducers/reducers.ts | 6 ---- src/store/store.ts | 2 +- src/ui/ConfirmPopout/ConfirmPopout.tsx | 4 +-- src/ui/Modal/Modal.tsx | 2 +- 23 files changed, 124 insertions(+), 114 deletions(-) delete mode 100644 src/store/actionTypes.ts delete mode 100644 src/store/actions.ts rename src/store/{reducers => ducks}/currentUser.ts (55%) create mode 100644 src/store/ducks/index.ts create mode 100644 src/store/ducks/modal.ts rename src/store/{reducers => ducks}/notifications.ts (50%) delete mode 100644 src/store/reducers/modal.ts delete mode 100644 src/store/reducers/reducers.ts diff --git a/src/pages/ActivateAccount.tsx b/src/pages/ActivateAccount.tsx index 621e2ac..06791b4 100644 --- a/src/pages/ActivateAccount.tsx +++ b/src/pages/ActivateAccount.tsx @@ -1,14 +1,14 @@ import React from "react"; import {activateAccount} from "../api/users"; import {connect} from "react-redux"; -import {addNotification} from "../store/actions"; import errors from "../api/errors"; import Loading from "../ui/Loading"; +import {addNotification} from "../store/ducks/notifications"; type Props = { history: { push: (path: string) => void } match: { params: { token: string } } - addNotification: (notification: React.ReactNode) => void + addNotification: AddNotification }; type State = { @@ -64,4 +64,4 @@ export default connect(null, dispatch => ({ addNotification: (notification: React.ReactNode) => dispatch(addNotification(notification)) }) -)(ActivateAccount); \ No newline at end of file +)(ActivateAccount); diff --git a/src/pages/AdminPanel/News/APModifyPost.tsx b/src/pages/AdminPanel/News/APModifyPost.tsx index 6174ff1..aa2c66f 100644 --- a/src/pages/AdminPanel/News/APModifyPost.tsx +++ b/src/pages/AdminPanel/News/APModifyPost.tsx @@ -11,9 +11,10 @@ import BBEditor from "../../../ui/BBEditor/BBEditor"; import parser from 'bbcode-to-react'; import Title from "../../../ui/Title/Title"; import {connect} from "react-redux"; -import {addNotification, setModal} from "../../../store/actions"; import ConfirmPopout from "../../../ui/ConfirmPopout/ConfirmPopout"; import NotificationMessage from "../../../ui/Notifications/NotificationMessage"; +import {setModal} from "../../../store/ducks/modal"; +import {addNotification} from "../../../store/ducks/notifications"; type Props = { postId: number @@ -147,4 +148,4 @@ export default connect(null, setPopout: (modal: React.ReactNode | null) => dispatch(setModal(modal)), addNotification: (notification: React.ReactNode) => dispatch(addNotification(notification)) }) -)(APModifyPost); \ No newline at end of file +)(APModifyPost); diff --git a/src/pages/AdminPanel/Users/ModifyUser.tsx b/src/pages/AdminPanel/Users/ModifyUser.tsx index e76f527..7b75980 100644 --- a/src/pages/AdminPanel/Users/ModifyUser.tsx +++ b/src/pages/AdminPanel/Users/ModifyUser.tsx @@ -3,9 +3,9 @@ import {connect} from "react-redux"; import {fetchUser, updateUser} from "../../../api/users"; import Loading from "../../../ui/Loading"; import './APUser.sass'; -import {addNotification} from "../../../store/actions"; import NotificationMessage from "../../../ui/Notifications/NotificationMessage"; import Button from "../../../ui/Button/Button"; +import {addNotification} from "../../../store/ducks/notifications"; type Props = { userId: number @@ -90,4 +90,4 @@ export default connect( dispatch(addNotification(notification)) } }) -)(ModifyUser); \ No newline at end of file +)(ModifyUser); diff --git a/src/pages/App/App.tsx b/src/pages/App/App.tsx index 6fbde8e..eae012d 100644 --- a/src/pages/App/App.tsx +++ b/src/pages/App/App.tsx @@ -8,7 +8,6 @@ import Main from "../Main/Main" import NotFoundError from "../NotFoundError"; import {fetchCurrentUser, fetchUserSettings} from "../../api/users"; import {connect} from "react-redux"; -import {setUser} from "../../store/actions"; import Character from "../Character/Character"; // @ts-ignore import parser from 'bbcode-to-react'; @@ -26,6 +25,7 @@ import PasswordRestore from "../PasswordRestore/PasswordRestore"; import Users from "../Users/Users"; import {getVersion, version} from "../../api/api"; import Settings from "../User/Settings/Settings"; +import {setUser} from "../../store/ducks/currentUser"; type Props = { notifications: React.ReactNode[] @@ -130,8 +130,6 @@ export default connect( modal: state.modal }), dispatch => ({ - setUser: (userData: UserType) => { - dispatch(setUser(userData)) - } + setUser: (userData: UserType) => dispatch(setUser(userData)) }) )(App); diff --git a/src/pages/Comments/Comments.tsx b/src/pages/Comments/Comments.tsx index 961394b..759a14e 100644 --- a/src/pages/Comments/Comments.tsx +++ b/src/pages/Comments/Comments.tsx @@ -6,9 +6,9 @@ import './Comments.sass'; import Loading from "../../ui/Loading"; import {fetchUser} from "../../api/users"; import {connect} from "react-redux"; -import {addNotification} from "../../store/actions"; import NotificationMessage from "../../ui/Notifications/NotificationMessage"; import Button from "../../ui/Button/Button"; +import {addNotification} from "../../store/ducks/notifications"; type Props = { comments: CommentType[] @@ -48,7 +48,7 @@ class Comments extends React.Component { event.preventDefault(); const { sendComment, addNotification } = this.props; const { commentText } = this.state; - + if(commentText === '') { const notification = ( @@ -84,7 +84,7 @@ class Comments extends React.Component { const { users, commentText } = this.state; if(!user) return ; - return ( + return (
{user.authorized &&
@@ -96,7 +96,7 @@ class Comments extends React.Component { this.addTagToComment(event, 'spoiler')} icon={faExclamationTriangle}/> this.addTagToComment(event, 'color', 'white')} icon={faTint}/>
-