|
@@ -1,140 +1,140 @@
|
|
-import thunk from 'redux-thunk';
|
|
|
|
|
|
+import thunk from 'redux-thunk'
|
|
import {
|
|
import {
|
|
- actionAuthLogin, gql, actionPromise,
|
|
|
|
- actionAllPosts, actionAboutMe, actionAllPostsUser, actionAboutUser,
|
|
|
|
- actionPostsFeed, actionPostsFeedCount, actionOnePost, actionAddComment,
|
|
|
|
- actionAddLike,actionDeleteLike,actionPostsCount,actionAuthLogout
|
|
|
|
|
|
+ actionAboutMe,
|
|
|
|
+ actionAllPostsUser,
|
|
|
|
+ actionAboutUser,
|
|
|
|
+ actionPostsFeed,
|
|
|
|
+ actionPostsFeedCount,
|
|
|
|
+ actionOnePost,
|
|
|
|
+ actionAddComment,
|
|
|
|
+ actionAddLike,
|
|
|
|
+ actionDeleteLike,
|
|
|
|
+ actionPostsCount,
|
|
|
|
+ actionAuthLogout,
|
|
} from '../actions'
|
|
} from '../actions'
|
|
-import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
|
|
-
|
|
|
|
|
|
+import { createStore, combineReducers, applyMiddleware } from 'redux'
|
|
|
|
+import { history } from '../App'
|
|
function promiseReducer(state = {}, { type, name, status, payload, error }) {
|
|
function promiseReducer(state = {}, { type, name, status, payload, error }) {
|
|
- if (type === 'PROMISE') {
|
|
|
|
- return {
|
|
|
|
- ...state,
|
|
|
|
- [name]: { status, payload, error },
|
|
|
|
- }
|
|
|
|
|
|
+ if (type === 'PROMISE') {
|
|
|
|
+ return {
|
|
|
|
+ ...state,
|
|
|
|
+ [name]: { status, payload, error },
|
|
}
|
|
}
|
|
- return state
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ return state
|
|
|
|
+}
|
|
|
|
+
|
|
const jwtDecode = (token) => {
|
|
const jwtDecode = (token) => {
|
|
- try {
|
|
|
|
- return JSON.parse(atob(token.split('.')[1]))
|
|
|
|
- } catch (e) {
|
|
|
|
- return null
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ return JSON.parse(atob(token.split('.')[1]))
|
|
|
|
+ } catch (e) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-export const actionProfilePageDataTypeUser= (aboutUser, allPosts) =>
|
|
|
|
- ({ type: 'PROFILE-PAGE-USER', aboutUser, allPosts })
|
|
|
|
|
|
+export const actionProfilePageDataTypeUser = (aboutUser, allPosts) => ({
|
|
|
|
+ type: 'PROFILE-PAGE-USER',
|
|
|
|
+ aboutUser,
|
|
|
|
+ allPosts,
|
|
|
|
+})
|
|
|
|
|
|
export const actionProfilePageData = (id) => ({ type: 'DATA_PROFILE', id })
|
|
export const actionProfilePageData = (id) => ({ type: 'DATA_PROFILE', id })
|
|
-
|
|
|
|
- export const actionProfilePageDataType= (aboutMe) =>
|
|
|
|
- ({ type: 'PROFILE-PAGE', aboutMe })
|
|
|
|
|
|
|
|
- export const actionAvatarUpdate= (aboutUser) =>
|
|
|
|
- ({ type: 'CHANGE-AVATAR-USER', aboutUser })
|
|
|
|
|
|
+export const actionProfilePageDataType = (aboutMe) => ({
|
|
|
|
+ type: 'PROFILE-PAGE',
|
|
|
|
+ aboutMe,
|
|
|
|
+})
|
|
|
|
|
|
- export const actionFullProfilePageUser = (_id) =>
|
|
|
|
- async dispatch => {
|
|
|
|
- const aboutUser = await dispatch(actionAboutUser(_id))
|
|
|
|
- console.log('ABOUTUSER ', aboutUser)
|
|
|
|
- const allPosts = await dispatch(actionAllPostsUser(_id))
|
|
|
|
- await dispatch(actionPostsCount(_id))
|
|
|
|
- console.log('ALLPOSTS ', allPosts )
|
|
|
|
- if (aboutUser && allPosts) {
|
|
|
|
- await dispatch(actionProfilePageDataTypeUser(aboutUser, allPosts))
|
|
|
|
- }
|
|
|
|
|
|
+export const actionAvatarUpdate = (aboutUser) => ({
|
|
|
|
+ type: 'CHANGE-AVATAR-USER',
|
|
|
|
+ aboutUser,
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+export const actionFullProfilePageUser = (_id) => async (dispatch) => {
|
|
|
|
+ const aboutUser = await dispatch(actionAboutUser(_id))
|
|
|
|
+ const allPosts = await dispatch(actionAllPostsUser(_id))
|
|
|
|
+ await dispatch(actionPostsCount(_id))
|
|
|
|
+ if (aboutUser && allPosts) {
|
|
|
|
+ await dispatch(actionProfilePageDataTypeUser(aboutUser, allPosts))
|
|
}
|
|
}
|
|
- export const actionClearDataUserType= () =>
|
|
|
|
- ({ type: 'CLEAR-DATA' })
|
|
|
|
|
|
+}
|
|
|
|
+export const actionClearDataUserType = () => ({ type: 'CLEAR-DATA' })
|
|
|
|
|
|
- export const actionClearUserData = () =>
|
|
|
|
- async dispatch => {
|
|
|
|
- const logOut = await dispatch(actionAuthLogout())
|
|
|
|
- console.log('logOut ', logOut)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if (logOut) {
|
|
|
|
- const clearData = await dispatch(actionClearDataUserType())
|
|
|
|
- console.log('clearData ', clearData )
|
|
|
|
- // await dispatch(actionClearDataUserType())
|
|
|
|
- }
|
|
|
|
|
|
+export const actionClearUserData = () => async (dispatch) => {
|
|
|
|
+ const logOut = await dispatch(actionAuthLogout())
|
|
|
|
+ if (logOut) {
|
|
|
|
+ history.push('/input')
|
|
|
|
+ await dispatch(actionClearDataUserType())
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- export const actionFullProfilePage = (_id) =>
|
|
|
|
- async dispatch => {
|
|
|
|
- const aboutMe = await dispatch(actionAboutMe(_id))
|
|
|
|
- console.log('попало ли в запрос на єбоут ми ', aboutMe)
|
|
|
|
- // const allPostsMe = await dispatch(actionAllPosts(_id))
|
|
|
|
- if (aboutMe) {
|
|
|
|
- await dispatch(actionProfilePageDataType(aboutMe))
|
|
|
|
- }
|
|
|
|
|
|
+export const actionFullProfilePage = (_id) => async (dispatch) => {
|
|
|
|
+ const aboutMe = await dispatch(actionAboutMe(_id))
|
|
|
|
+ if (aboutMe) {
|
|
|
|
+ await dispatch(actionProfilePageDataType(aboutMe))
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- export const actionRemoveDataUser= () =>
|
|
|
|
- ({ type: 'REMOVE-DATA' })
|
|
|
|
-export const profileUserReducer = (state = {}, { type, aboutUser, allPosts,newPosts }) => {
|
|
|
|
|
|
+export const actionRemoveDataUser = () => ({ type: 'REMOVE-DATA' })
|
|
|
|
+export const profileUserReducer = (
|
|
|
|
+ state = {},
|
|
|
|
+ { type, aboutUser, allPosts, newPosts },
|
|
|
|
+) => {
|
|
const types = {
|
|
const types = {
|
|
'PROFILE-PAGE-USER': () => {
|
|
'PROFILE-PAGE-USER': () => {
|
|
return {
|
|
return {
|
|
- ...state, aboutUser, allPosts
|
|
|
|
|
|
+ ...state,
|
|
|
|
+ aboutUser,
|
|
|
|
+ allPosts,
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'CLEAR-DATA': () => {
|
|
'CLEAR-DATA': () => {
|
|
return {
|
|
return {
|
|
- ...state = {},
|
|
|
|
|
|
+ ...(state = {}),
|
|
aboutUser: {},
|
|
aboutUser: {},
|
|
- allPosts: []
|
|
|
|
|
|
+ allPosts: [],
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'CHANGE-AVATAR-USER': () => {
|
|
'CHANGE-AVATAR-USER': () => {
|
|
return {
|
|
return {
|
|
- ...state, aboutUser
|
|
|
|
|
|
+ ...state,
|
|
|
|
+ aboutUser,
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- ,
|
|
|
|
|
|
+ },
|
|
}
|
|
}
|
|
|
|
|
|
- if (type in types) {
|
|
|
|
- return types[type]()
|
|
|
|
- }
|
|
|
|
- return state
|
|
|
|
|
|
+ if (type in types) {
|
|
|
|
+ return types[type]()
|
|
}
|
|
}
|
|
- export const actionFeedType= (newPosts) =>
|
|
|
|
- ({ type: 'ADD-POSTS', newPosts })
|
|
|
|
|
|
+ return state
|
|
|
|
+}
|
|
|
|
+export const actionFeedType = (newPosts) => ({ type: 'ADD-POSTS', newPosts })
|
|
|
|
|
|
-export const actionAddCommentPostInTape = (postId, newResult) =>
|
|
|
|
- ({ type: 'ADD-COMMENT-POSTS', postId, newResult })
|
|
|
|
-
|
|
|
|
|
|
+export const actionAddCommentPostInTape = (postId, newResult) => ({
|
|
|
|
+ type: 'ADD-COMMENT-POSTS',
|
|
|
|
+ postId,
|
|
|
|
+ newResult,
|
|
|
|
+})
|
|
|
|
|
|
export const actionAddFullCommentFeed = (postId, newResult) => async (
|
|
export const actionAddFullCommentFeed = (postId, newResult) => async (
|
|
- dispatch,
|
|
|
|
- getState,
|
|
|
|
- ) => {
|
|
|
|
- await dispatch(actionAddComment(postId, newResult))
|
|
|
|
- const {
|
|
|
|
- promise: {
|
|
|
|
- addComment: { status },
|
|
|
|
- },
|
|
|
|
- } = getState()
|
|
|
|
- if (status === 'FULFILLED') {
|
|
|
|
- const onePost = await dispatch(actionOnePost(postId))
|
|
|
|
- if (onePost)
|
|
|
|
- await dispatch((actionAddCommentPostInTape(postId,newResult)))
|
|
|
|
- }
|
|
|
|
- // await dispatch(actionOnePost(postId));
|
|
|
|
-}
|
|
|
|
-const actionAddLikePostInTape = (postId,) =>
|
|
|
|
- ({ type: 'ADD-LIKE-POSTS', postId })
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-export const actionAddFullLikeFeed = (postId) => async (
|
|
|
|
dispatch,
|
|
dispatch,
|
|
getState,
|
|
getState,
|
|
) => {
|
|
) => {
|
|
|
|
+ await dispatch(actionAddComment(postId, newResult))
|
|
|
|
+ const {
|
|
|
|
+ promise: {
|
|
|
|
+ addComment: { status },
|
|
|
|
+ },
|
|
|
|
+ } = getState()
|
|
|
|
+ if (status === 'FULFILLED') {
|
|
|
|
+ const onePost = await dispatch(actionOnePost(postId))
|
|
|
|
+ if (onePost) await dispatch(actionAddCommentPostInTape(postId, newResult))
|
|
|
|
+ }
|
|
|
|
+ // await dispatch(actionOnePost(postId));
|
|
|
|
+}
|
|
|
|
+const actionAddLikePostInTape = (postId) => ({ type: 'ADD-LIKE-POSTS', postId })
|
|
|
|
+
|
|
|
|
+export const actionAddFullLikeFeed = (postId) => async (dispatch, getState) => {
|
|
await dispatch(actionAddLike(postId))
|
|
await dispatch(actionAddLike(postId))
|
|
const {
|
|
const {
|
|
promise: {
|
|
promise: {
|
|
@@ -143,184 +143,171 @@ export const actionAddFullLikeFeed = (postId) => async (
|
|
} = getState()
|
|
} = getState()
|
|
if (status === 'FULFILLED') {
|
|
if (status === 'FULFILLED') {
|
|
const onePost = await dispatch(actionOnePost(postId))
|
|
const onePost = await dispatch(actionOnePost(postId))
|
|
- if (onePost)
|
|
|
|
- await dispatch((actionAddLikePostInTape(postId)))
|
|
|
|
|
|
+ if (onePost) await dispatch(actionAddLikePostInTape(postId))
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+const actionDeleteLikePostInTape = (likeId, postId) => ({
|
|
|
|
+ type: 'DELETE-LIKE-POSTS',
|
|
|
|
+ likeId,
|
|
|
|
+ postId,
|
|
|
|
+})
|
|
|
|
+export const actionDeleteFullLikeFeed = (likeId, postId) => async (
|
|
|
|
+ dispatch,
|
|
|
|
+ getState,
|
|
|
|
+) => {
|
|
|
|
+ await dispatch(actionDeleteLike(likeId, postId))
|
|
|
|
+ const {
|
|
|
|
+ promise: {
|
|
|
|
+ deleteLike: { status },
|
|
|
|
+ },
|
|
|
|
+ } = getState()
|
|
|
|
+ if (status === 'FULFILLED') {
|
|
|
|
+ const onePost = await dispatch(actionOnePost(postId))
|
|
|
|
+ if (onePost) await dispatch(actionDeleteLikePostInTape(likeId, postId))
|
|
}
|
|
}
|
|
- const actionDeleteLikePostInTape = (likeId,postId) =>
|
|
|
|
- ({ type: 'DELETE-LIKE-POSTS',likeId,postId })
|
|
|
|
- export const actionDeleteFullLikeFeed = (likeId,postId) => async (
|
|
|
|
- dispatch,
|
|
|
|
- getState,
|
|
|
|
- ) => {
|
|
|
|
- await dispatch(actionDeleteLike(likeId,postId))
|
|
|
|
- const {
|
|
|
|
- promise: {
|
|
|
|
- deleteLike: { status },
|
|
|
|
- },
|
|
|
|
- } = getState()
|
|
|
|
- if (status === 'FULFILLED') {
|
|
|
|
- const onePost = await dispatch(actionOnePost(postId))
|
|
|
|
- if (onePost)
|
|
|
|
- await dispatch((actionDeleteLikePostInTape(likeId,postId)))
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- export const actionFullFeed = () =>
|
|
|
|
- async (dispatch, getState) => {
|
|
|
|
- const postsFeed = await dispatch(actionPostsFeed(getState))
|
|
|
|
- const skip = postsFeed.length
|
|
|
|
- console.log('postsFeed ', postsFeed)
|
|
|
|
- const postsFeedCount = await dispatch(actionPostsFeedCount(getState))
|
|
|
|
- console.log('postsFeedCount ', postsFeedCount)
|
|
|
|
- if (skip < postsFeedCount)
|
|
|
|
- {
|
|
|
|
- // console.log('SKIIIP ', skip)
|
|
|
|
- const newPosts = await dispatch(actionPostsFeed(getState, skip))
|
|
|
|
- if (newPosts) {
|
|
|
|
- await dispatch(actionFeedType(newPosts));
|
|
|
|
- // const postsFeedCount = await dispatch(actionPostsFeedCount(getState))
|
|
|
|
- // console.log('postsFeedCount ', postsFeedCount)
|
|
|
|
- }
|
|
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+export const actionFullFeed = () => async (dispatch, getState) => {
|
|
|
|
+ const postsFeed = await dispatch(actionPostsFeed(getState))
|
|
|
|
+ const skip = postsFeed.length
|
|
|
|
+ const postsFeedCount = await dispatch(actionPostsFeedCount(getState))
|
|
|
|
+ if (skip < postsFeedCount) {
|
|
|
|
+ const newPosts = await dispatch(actionPostsFeed(getState, skip))
|
|
|
|
+ if (newPosts) {
|
|
|
|
+ await dispatch(actionFeedType(newPosts))
|
|
}
|
|
}
|
|
- export const actionOnePostType= (onePost) =>
|
|
|
|
- ({ type: 'ONE-POST', onePost })
|
|
|
|
-
|
|
|
|
- export const actionClearFeedPosts = () => ({ type: 'DELETE-POSTS' });
|
|
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+export const actionOnePostType = (onePost) => ({ type: 'ONE-POST', onePost })
|
|
|
|
+
|
|
|
|
+export const actionClearFeedPosts = () => ({ type: 'DELETE-POSTS' })
|
|
|
|
|
|
- export const actionFullClearFeedPosts = () => (dispatch) => {
|
|
|
|
- return dispatch(actionClearFeedPosts())
|
|
|
|
|
|
+export const actionFullClearFeedPosts = () => (dispatch) => {
|
|
|
|
+ return dispatch(actionClearFeedPosts())
|
|
|
|
+}
|
|
|
|
+export const actionFullOnePost = (_id) => async (dispatch) => {
|
|
|
|
+ const onePost = await dispatch(actionOnePost(_id))
|
|
|
|
+ if (onePost) {
|
|
|
|
+ await dispatch(actionOnePostType(onePost))
|
|
|
|
+ // await dispatch(actionClearDataUserType())
|
|
}
|
|
}
|
|
- export const actionFullOnePost = (_id) =>
|
|
|
|
- async (dispatch) => {
|
|
|
|
- console.log('ID POST ', _id)
|
|
|
|
- const onePost = await dispatch(actionOnePost(_id))
|
|
|
|
- console.log(' one post ', onePost)
|
|
|
|
-
|
|
|
|
- // const skip = postsFeed.length
|
|
|
|
- // console.log('postsFeed ', postsFeed)
|
|
|
|
- // const postsFeedCount = await dispatch(actionPostsFeedCount(getState))
|
|
|
|
- // console.log('postsFeedCount ', postsFeedCount)
|
|
|
|
- // if (skip < postsFeedCount)
|
|
|
|
- // {
|
|
|
|
- // console.log('SKIIIP ', skip)
|
|
|
|
- // const newPosts = await dispatch(actionPostsFeed(getState, skip))
|
|
|
|
- if (onePost) {
|
|
|
|
- console.log('УСПЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕХ')
|
|
|
|
- await dispatch(actionOnePostType(onePost));
|
|
|
|
- console.log('onePost ', onePost)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-export const feedReducer = (state = {}, {skip, type, newPosts=[], postId, postsFeed,postsFeedCount,newResult }) => {
|
|
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+export const feedReducer = (
|
|
|
|
+ state = {},
|
|
|
|
+ { skip, type, newPosts = [], postId, postsFeed, postsFeedCount, newResult },
|
|
|
|
+) => {
|
|
const types = {
|
|
const types = {
|
|
'ADD-POSTS': () => {
|
|
'ADD-POSTS': () => {
|
|
return {
|
|
return {
|
|
...state,
|
|
...state,
|
|
- postsFeed: postsFeed ? [...postsFeed, ...newPosts] : [...newPosts]
|
|
|
|
|
|
+ postsFeed: postsFeed ? [...postsFeed, ...newPosts] : [...newPosts],
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'DELETE-POSTS': () => {
|
|
'DELETE-POSTS': () => {
|
|
return {
|
|
return {
|
|
...state,
|
|
...state,
|
|
- postsFeed: []
|
|
|
|
|
|
+ postsFeed: [],
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
'ADD-LIKE-POSTS': () => ({
|
|
'ADD-LIKE-POSTS': () => ({
|
|
...state,
|
|
...state,
|
|
- postsFeed: postsFeed?.map(p => p._id === postId ? p = { ...p, likes: [...newResult] } : p)
|
|
|
|
|
|
+ postsFeed: postsFeed?.map((p) =>
|
|
|
|
+ p._id === postId ? (p = { ...p, likes: [...newResult] }) : p,
|
|
|
|
+ ),
|
|
}),
|
|
}),
|
|
'DELETE-LIKE-POSTS': () => ({
|
|
'DELETE-LIKE-POSTS': () => ({
|
|
...state,
|
|
...state,
|
|
- postsFeed: postsFeed?.map(p => p._id === postId ? p = { ...p, likes: [...newResult] } : p)
|
|
|
|
|
|
+ postsFeed: postsFeed?.map((p) =>
|
|
|
|
+ p._id === postId ? (p = { ...p, likes: [...newResult] }) : p,
|
|
|
|
+ ),
|
|
}),
|
|
}),
|
|
|
|
|
|
- 'ADD-COMMENT-POSTS': () => ({
|
|
|
|
|
|
+ 'ADD-COMMENT-POSTS': () => ({
|
|
...state,
|
|
...state,
|
|
- postsFeed: postsFeed?.map(p => p._id === postId ? p = { ...p, comments: [...newResult] } : p)
|
|
|
|
|
|
+ postsFeed: postsFeed?.map((p) =>
|
|
|
|
+ p._id === postId ? (p = { ...p, comments: [...newResult] }) : p,
|
|
|
|
+ ),
|
|
}),
|
|
}),
|
|
-
|
|
|
|
- }
|
|
|
|
- if (type in types) {
|
|
|
|
- return types[type]()
|
|
|
|
- }
|
|
|
|
- return state
|
|
|
|
}
|
|
}
|
|
- export const postReducer = (state = {}, {skip, type, newPosts=[],onePost, postsFeed,postsFeedCount }) => {
|
|
|
|
- const types = {
|
|
|
|
- 'ONE-POST': () => {
|
|
|
|
- return {
|
|
|
|
- ...state,onePost
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- 'CLEAR-POST-ONE': () => {
|
|
|
|
- return {
|
|
|
|
- ...state,
|
|
|
|
- onePost: {}
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ if (type in types) {
|
|
|
|
+ return types[type]()
|
|
|
|
+ }
|
|
|
|
+ return state
|
|
|
|
+}
|
|
|
|
+export const postReducer = (
|
|
|
|
+ state = {},
|
|
|
|
+ { skip, type, newPosts = [], onePost, postsFeed, postsFeedCount },
|
|
|
|
+) => {
|
|
|
|
+ const types = {
|
|
|
|
+ 'ONE-POST': () => {
|
|
|
|
+ return {
|
|
|
|
+ ...state,
|
|
|
|
+ onePost,
|
|
}
|
|
}
|
|
- if (type in types) {
|
|
|
|
- return types[type]()
|
|
|
|
|
|
+ },
|
|
|
|
+ 'CLEAR-POST-ONE': () => {
|
|
|
|
+ return {
|
|
|
|
+ ...state,
|
|
|
|
+ onePost: {},
|
|
}
|
|
}
|
|
- return state
|
|
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ if (type in types) {
|
|
|
|
+ return types[type]()
|
|
|
|
+ }
|
|
|
|
+ return state
|
|
|
|
+}
|
|
|
|
|
|
export const profileReducer = (state = {}, { type, aboutMe, newResult }) => {
|
|
export const profileReducer = (state = {}, { type, aboutMe, newResult }) => {
|
|
const types = {
|
|
const types = {
|
|
- 'PROFILE-PAGE': () => {
|
|
|
|
- return {
|
|
|
|
- ...state, aboutMe
|
|
|
|
- }
|
|
|
|
|
|
+ 'PROFILE-PAGE': () => {
|
|
|
|
+ return {
|
|
|
|
+ ...state,
|
|
|
|
+ aboutMe,
|
|
|
|
+ }
|
|
},
|
|
},
|
|
'REMOVE-DATA': () => {
|
|
'REMOVE-DATA': () => {
|
|
return {
|
|
return {
|
|
- ...state = {},
|
|
|
|
- aboutMe: {}
|
|
|
|
|
|
+ ...(state = {}),
|
|
|
|
+ aboutMe: {},
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ },
|
|
}
|
|
}
|
|
if (type in types) {
|
|
if (type in types) {
|
|
- return types[type]()
|
|
|
|
|
|
+ return types[type]()
|
|
}
|
|
}
|
|
return state
|
|
return state
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- function authReducer(state, { type, token }) {
|
|
|
|
- if (state === undefined && localStorage.authToken) {
|
|
|
|
- token = localStorage.authToken
|
|
|
|
- type = 'AUTH_LOGIN'
|
|
|
|
- }
|
|
|
|
- if (type === 'AUTH_LOGIN') {
|
|
|
|
- if (jwtDecode(token)) {
|
|
|
|
- localStorage.authToken = token
|
|
|
|
- return { token, payload: jwtDecode(token) }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (type === 'AUTH_LOGOUT') {
|
|
|
|
- localStorage.authToken = ''
|
|
|
|
- return {}
|
|
|
|
|
|
+function authReducer(state, { type, token }) {
|
|
|
|
+ if (state === undefined && localStorage.authToken) {
|
|
|
|
+ token = localStorage.authToken
|
|
|
|
+ type = 'AUTH_LOGIN'
|
|
|
|
+ }
|
|
|
|
+ if (type === 'AUTH_LOGIN') {
|
|
|
|
+ if (jwtDecode(token)) {
|
|
|
|
+ localStorage.authToken = token
|
|
|
|
+ return { token, payload: jwtDecode(token) }
|
|
}
|
|
}
|
|
- return state || {}
|
|
|
|
}
|
|
}
|
|
- export const actionClearPostsOne = () => ({ type: 'CLEAR-POST-ONE' })
|
|
|
|
|
|
+ if (type === 'AUTH_LOGOUT') {
|
|
|
|
+ localStorage.authToken = ''
|
|
|
|
+ return {}
|
|
|
|
+ }
|
|
|
|
+ return state || {}
|
|
|
|
+}
|
|
|
|
+export const actionClearPostsOne = () => ({ type: 'CLEAR-POST-ONE' })
|
|
|
|
|
|
- export const store = createStore(
|
|
|
|
- combineReducers({
|
|
|
|
- promise: promiseReducer,
|
|
|
|
- auth: authReducer,
|
|
|
|
- profileData: profileReducer,
|
|
|
|
- profilePage: profileUserReducer,
|
|
|
|
- feed:feedReducer,
|
|
|
|
- post:postReducer
|
|
|
|
-
|
|
|
|
- }),
|
|
|
|
- applyMiddleware(thunk),
|
|
|
|
|
|
+export const store = createStore(
|
|
|
|
+ combineReducers({
|
|
|
|
+ promise: promiseReducer,
|
|
|
|
+ auth: authReducer,
|
|
|
|
+ profileData: profileReducer,
|
|
|
|
+ profilePage: profileUserReducer,
|
|
|
|
+ feed: feedReducer,
|
|
|
|
+ post: postReducer,
|
|
|
|
+ }),
|
|
|
|
+ applyMiddleware(thunk),
|
|
)
|
|
)
|
|
-
|
|
|