Bläddra i källkod

Change name of reducers, folders and continue sorting the code into folders

LenDoc 2 år sedan
förälder
incheckning
2d4f23db90

+ 2 - 4
src/App.js

@@ -2,7 +2,7 @@ import './App.scss'
 import { Provider, connect } from 'react-redux'
 import { Router, Route, Redirect, Switch } from 'react-router-dom'
 import React from 'react'
-import { store } from './redux/reducers'
+import { store } from './redux'
 import 'antd/dist/antd.css'
 import { actionFullProfilePage } from './redux/saga'
 import { actionFullAllGetPosts } from './actions'
@@ -18,9 +18,7 @@ console.log('ABOUT ME', store.getState().auth?.payload?.sub?.id)
 function App() {
   if (store.getState().auth?.token) {
     console.log('токен', store.getState().auth?.payload?.sub?.id)
-    store.dispatch(
-      actionFullProfilePage()
-    )
+    store.dispatch(actionFullProfilePage())
     }
   return (
     <Router history={history}>

+ 1 - 1
src/components/EditAvatar.js

@@ -75,7 +75,7 @@ export const CEditAvatar = connect(
   (state) => ({
     myId: state?.auth.payload.sub?.id,
     fileStatus: state.promise?.uploadFile,
-    info: state?.profileData?.aboutMe?.avatar,
+    info: state?.myData?.aboutMe?.avatar,
   }),
   {
     onSaveAvatar: actionSetAvatar,

+ 20 - 0
src/components/EditPostButton.js

@@ -0,0 +1,20 @@
+import { Link } from 'react-router-dom'
+import { Button } from 'antd'
+import React, { useState, useEffect } from 'react'
+
+export const EditMyPostButton = ({ _id }) => {
+  return (
+    <>
+      <Link to={`/edit/post/${_id}`}>
+        <Button
+          style={{ marginLeft: '200px',marginTop:'10px', width: '100px' }}
+          size="large"
+          type="primary"
+        >
+          Edit Post
+        </Button>
+      </Link>
+    </>
+  )
+}
+

+ 2 - 2
src/components/Header.js

@@ -5,7 +5,6 @@ import { CSearch } from './Search_Users'
 import { Link } from 'react-router-dom'
 import { connect } from 'react-redux'
 import React, { useEffect,useState } from 'react'
-
 export const AddPost = ({ children }) => {
   const [state, setState] = useState(false)
 
@@ -39,6 +38,7 @@ export const Explore = () => (
     </a>
   </Link>
 )
+
 const User = ({ my_Id, aboutMe: { _id, login, avatar } = {}, onMyPage }) => {
   // console.log('_id in user', _id)
   
@@ -60,7 +60,7 @@ const User = ({ my_Id, aboutMe: { _id, login, avatar } = {}, onMyPage }) => {
 export const CUser = connect(
   (state) => ({
     my_Id: state.auth?.payload?.sub?.id,
-    aboutMe: state.profileData.aboutMe,
+    aboutMe: state.myData.aboutMe,
   }),
   { onMyPage: actionFullProfilePageUser },
 )(User)

+ 1 - 1
src/components/Routing.js

@@ -4,7 +4,7 @@ import { CExplorePosts } from '../pages/explorePosts'
 import { CPostForFeed, Feed } from '../pages/feedPosts'
 import { CPostEditor } from '../pages/createAndEditPost'
 import { CPageAboutUser } from '../pages/profilePage'
-import { CPost } from './Post'
+import { CPost } from '../pages/onePost'
 import { Provider, connect } from 'react-redux'
 
 const Routing = ({ token }) => {

+ 1 - 1
src/components/Search_Users.js

@@ -55,7 +55,7 @@ const SearchUser = ({ my_Id, onSearch, searchUser, onPageData }) => {
 }
 export const CSearch = connect(
   (state) => ({
-    aboutUser: state.profilePage?.aboutUser,
+    aboutUser: state.userData?.aboutUser,
     searchUser: state.promise?.searchUser?.payload,
     my_Id: state.auth?.payload?.sub?.id || '',
   }),

+ 2 - 2
src/components/Subscribe.js

@@ -42,8 +42,8 @@ const Subscribe = ({
 }
 export const CSubscribe = connect((state) => ({
     my_Id: state.auth?.payload?.sub?.id,
-    aboutMeFollowing: state.profileData?.aboutMe?.following,
-    followId: state.profilePage?.aboutUser?._id,
+    aboutMeFollowing: state.myData?.aboutMe?.following,
+    followId: state.userData?.aboutUser?._id,
 }),
     {
         addSubscribe: actionFullSubscribe,

+ 3 - 3
src/pages/createAndEditPost/index.js

@@ -23,7 +23,7 @@ const PostEditor = ({
   match: {
     params: { _id },
   },
-  myID,
+  myId,
   post = {},
   onSave,
   onFileDrop,
@@ -104,7 +104,7 @@ const PostEditor = ({
   const savePost = () =>
     onSave(state, state?._id) &&
     message.success(`Post published success!`) &&
-    history.push(`/profile/${myID}`)
+    history.push(`/profile/${myId}`)
   useEffect(() => {
     return () => {
       clearPromise('uploadFiles')
@@ -193,7 +193,7 @@ export const CPostEditor = connect(
   (state) => ({
     fileStatus: state.promise?.uploadFiles,
     post: state?.post?.onePost,
-    myID: state?.profileData?.aboutMe?._id,
+    myId: state?.myData?.aboutMe?._id,
   }),
   {
     onSave: actionPostUpsert,

+ 3 - 3
src/pages/feedPosts/index.js

@@ -25,7 +25,7 @@ import { Link } from 'react-router-dom'
 import { Provider, connect } from 'react-redux'
 import { Upload, Button, DatePicker, Space } from 'antd'
 import { Avatar, Image, Divider, Radio } from 'antd'
-import { CPost } from '../../components/Post'
+import { CPost } from '../onePost'
 import { Row, Col } from 'antd'
 import LinkToUser from '../../components/LinkToUser'
 import { AddComment, Comments } from '../../components/Comment'
@@ -34,7 +34,7 @@ import { MyCarousel } from '../../components/Carousel'
 import load from '../../materials/load.gif'
 
 const MyPostFeed = ({
-  profileData,
+  // myData,
   postsFeed = [],
   onPostsFeed,
   addComment,
@@ -141,7 +141,7 @@ const CCommentsForFeed = connect(
 
 export const CPostForFeed = connect(
   (state) => ({
-    profileData:  state?.profileData.aboutMe || '',
+    // myData:  state?.myData.aboutMe || '',
     postsFeed: state.feed?.postsFeed || [],
     addComment: state.promise?.addComment?.payload,
     postsFeedPromise :state.promise?.postsFeed

+ 1 - 1
src/pages/header/index.js

@@ -1,7 +1,7 @@
 
 import { CLogout } from '../../components/LoginRegisterLogout'
 import { CSearch } from '../../components/Search_Users'
-import { Feed, AddPost, Explore, CUser } from '../../components/Header'
+import { Feed, AddPost, Explore, CUser } from '../../components/HeaderButtons'
 import { connect } from 'react-redux'
 
 export const Header = () => {

+ 14 - 30
src/components/Post.js

@@ -3,40 +3,25 @@ import {
   actionAddSubFullComment,
   actionDeleteFullLike,
   actionAddFullLike,
-} from '../actions'
+} from '../../actions'
 
 import { Avatar, Divider, Input, Button } from 'antd'
-import user from '../materials/user.png'
+import user from '../../materials/user.png'
 import { connect } from 'react-redux'
 import { Row, Col } from 'antd'
-import { CComments, AddComment } from './Comment'
-import { CPostEditor } from '../pages/createAndEditPost'
+import { CComments, AddComment } from '../../components/Comment'
+import { CPostEditor } from '../createAndEditPost'
 
-import { actionFullOnePostSaga,actionAddFullCommentSaga } from '../actions/typeSaga/postActionSaga'
-import { CLike} from './Like'
-import { ConstructorModal } from '../helpers'
+import { actionFullOnePostSaga,actionAddFullCommentSaga } from '../../actions/typeSaga/postActionSaga'
+import { CLike} from '../../components/Like'
+import { ConstructorModal } from '../../helpers'
 import React, { useState, useEffect } from 'react'
 import {
   actionAddFullCommentFeed,
-} from '../redux/saga'
-import { LinkToUser } from './LinkToUser'
-import { MyCarousel } from './Carousel'
-
-const EditMyPost = ({ _id }) => {
-  return (
-    <>
-      <Link to={`/edit/post/${_id}`}>
-        <Button
-          style={{ marginLeft: '200px',marginTop:'10px', width: '100px' }}
-          size="large"
-          type="primary"
-        >
-          Edit Post
-        </Button>
-      </Link>
-    </>
-  )
-}
+} from '../../redux/saga'
+import { LinkToUser } from '../../components/LinkToUser'
+import { MyCarousel } from '../../components/Carousel'
+import {EditMyPostButton} from '../../components/EditPostButton'
 
 
 export const PagePost = ({
@@ -86,7 +71,7 @@ export const PagePost = ({
               key={_id}
             size={50} padding={'0px'} />
             <Row span={1}>
-              {my_Id === onePost?.owner?._id && <EditMyPost _id={_id} />}
+              {my_Id === onePost?.owner?._id && <EditMyPostButton _id={_id} />}
             </Row>
           </div>
 
@@ -113,10 +98,9 @@ export const PagePost = ({
 
 export const CPost = connect(
   (state) => ({
-    onePost: state.promise?.onePost?.payload,
+    onePost: state?.post.onePost,
     my_Id: state.auth.payload?.sub?.id || '',
-    aboutUser: state.profilePage?.aboutUser,
-    addComment: state.promise?.addComment?.payload,
+    aboutUser: state.userData?.aboutUser,
   }),
   {
     addComment: actionAddFullCommentSaga,

+ 2 - 2
src/pages/profilePage/index.js

@@ -124,9 +124,9 @@ export const PageAboutUser = ({
 export const CPageAboutUser = connect(
   (state) => ({
     my_Id: state.auth?.payload?.sub?.id,
-    aboutUser: state.profilePage?.aboutUser,
+    aboutUser: state.userData?.aboutUser,
     countAllPostsUser: state.promise?.countAllPostsUser?.payload,
-    allPosts: state.profilePage?.allPosts,
+    allPosts: state.userData?.allPosts,
   }),
   {
     onAboutUser: actionFullProfilePageUser,

+ 1 - 1
src/pages/setting/index.js

@@ -186,7 +186,7 @@ const EditSetting = ({ info, myId, onSaveUserUpsert,
   export const CEditSetting = connect(
     (state) => ({
       myId: state?.auth.payload.sub?.id,
-      info: state?.profileData?.aboutMe,
+      info: state?.myData?.aboutMe,
       changePassword : state.promise?.newPassword
     }),
     {

+ 10 - 10
src/redux/reducers/index.js

@@ -1,12 +1,12 @@
 import { createStore, combineReducers, applyMiddleware } from 'redux'
 import thunk from 'redux-thunk'
-import { promiseReducer } from './promise/promiseReducer'
-import { authReducer } from './auth/authReducer'
-import { profileReducer } from './profileData/profileReducer'
-import { profileUserReducer } from './profileUserPage/profileUserReducer'
-import { feedReducer } from './feed/feedReducer'
-import { postReducer } from './post/postReducer'
-import { exploreReducer } from './explore/exploreReducer'
+import { promiseReducer } from './reducers/promise/promiseReducer'
+import { authReducer } from './reducers/auth/authReducer'
+import { myProfileReducer } from './reducers/myData/myProfileReducer'
+import { userProfileReducer } from './reducers/userData/userProfileReducer'
+import { feedReducer } from './reducers/feed/feedReducer'
+import { postReducer } from './reducers/post/postReducer'
+import { exploreReducer } from './reducers/explore/exploreReducer'
 import {
   promiseWatcher,
   fullProfilePageWatcher,
@@ -18,7 +18,7 @@ onePostWatcher,
   addCommentFeedWatcher,
   addCommentOnePostWatcher,
   changeLikePostWatcher
-} from '../saga'
+} from './saga'
 import createSagaMiddleware from 'redux-saga' //функция по созданию middleware
 import {
   all,
@@ -34,8 +34,8 @@ export const store = createStore(
   combineReducers({
     promise: promiseReducer,
     auth: authReducer,
-    profileData: profileReducer,
-    profilePage: profileUserReducer,
+    myData: myProfileReducer,
+    userData: userProfileReducer,
     feed: feedReducer,
     post: postReducer,
     explore: exploreReducer,

+ 1 - 1
src/redux/reducers/profileData/profileReducer.js

@@ -1,5 +1,5 @@
 
-export const profileReducer = (state = {}, { type, aboutMe, newResult }) => {
+export const myProfileReducer = (state = {}, { type, aboutMe, newResult }) => {
     const types = {
       'PROFILE-PAGE': () => {
         return {

+ 1 - 1
src/redux/reducers/profileUserPage/profileUserReducer.js

@@ -1,5 +1,5 @@
 
-export const profileUserReducer = (
+export const userProfileReducer = (
     state = {},
     { type, aboutUser, allPosts, newPosts, countPosts },
   ) => {

+ 7 - 7
src/redux/saga/index.js

@@ -21,8 +21,8 @@ import {
   // actionOnePost
   } from '../../actions'
 import { history } from '../../helpers'
-  import{actionClearDataUserType} from '../reducers/profileUserPage/profileUserReducer'
-import { actionProfilePageDataType } from '../reducers/profileData/profileReducer'
+  import{actionClearDataUserType} from '../reducers/userData/userProfileReducer'
+import { actionProfilePageDataType } from '../reducers/myData/myProfileReducer'
 import { actionFullAllGetPosts } from '../../actions'
 import {
   actionAddLikePostInTape,
@@ -31,8 +31,8 @@ import {
   actionClearFeedPosts,
   actionFeedType
 } from '../reducers/feed/feedReducer'
-import { actionProfilePageDataTypeUser,actionCountPostsType } from '../reducers/profileUserPage/profileUserReducer'
-import { actionRemoveDataAboutMe } from '../reducers/profileData/profileReducer'
+import { actionProfilePageDataTypeUser,actionCountPostsType } from '../reducers/userData/userProfileReducer'
+import { actionRemoveDataAboutMe } from '../reducers/myData/myProfileReducer'
 import {actionExploreType,actionClearExplorePosts} from '../reducers/explore/exploreReducer'
 import { all, put,take, fork, takeEvery, takeLatest, takeLeading, select,call, join } from 'redux-saga/effects'; //
 import {actionPending,actionFulfilled,actionRejected,actionExplorePosts,actionExplorePostsCount} from '../../actions'
@@ -118,7 +118,7 @@ export function* fullPageAboutUserWatcher() {
 function* feedWorker() {
   const {
     feed: { postsFeed, postsFeedCount },
-    profileData: { aboutMe},
+    myData: { aboutMe},
     
   }  = yield select()
   let myFollowing = aboutMe?.following && aboutMe?.following?.map(({ _id }) => _id)
@@ -127,8 +127,8 @@ function* feedWorker() {
   if (!aboutMe) {
     yield call(fullProfilePageWorker, actionFullProfilePage())
   }
-  myFollowing = (yield select()).profileData.aboutMe?.following &&
-    (yield select()).profileData.aboutMe?.following?.map(({ _id }) => _id)
+  myFollowing = (yield select()).myData.aboutMe?.following &&
+    (yield select()).myData.aboutMe?.following?.map(({ _id }) => _id)
   // console.log('myFollowing after if', myFollowing)
   if (postsFeed?.length !== (postsFeedCount ? postsFeedCount : 1)) {
     const newPosts = yield call(promiseWorker,