mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add basic version of post show page
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
import {
|
||||
POST_REQUEST_START,
|
||||
POST_REQUEST_SUCCESS,
|
||||
POST_REQUEST_FAILURE,
|
||||
} from '../actions/requestPost';
|
||||
|
||||
import {
|
||||
CHANGE_POST_STATUS_SUCCESS,
|
||||
} from '../actions/changePostStatus';
|
||||
|
||||
import IPost from '../interfaces/IPost';
|
||||
|
||||
const initialState: IPost = {
|
||||
@@ -15,7 +25,7 @@ const postReducer = (
|
||||
action,
|
||||
): IPost => {
|
||||
switch (action.type) {
|
||||
case 'CONVERT':
|
||||
case POST_REQUEST_SUCCESS:
|
||||
return {
|
||||
id: action.post.id,
|
||||
title: action.post.title,
|
||||
@@ -26,6 +36,14 @@ const postReducer = (
|
||||
createdAt: action.post.created_at,
|
||||
};
|
||||
|
||||
case CHANGE_POST_STATUS_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
postStatusId: action.newPostStatusId,
|
||||
};
|
||||
|
||||
case POST_REQUEST_START:
|
||||
case POST_REQUEST_FAILURE:
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
POSTS_REQUEST_FAILURE,
|
||||
} from '../actions/requestPosts';
|
||||
|
||||
import { postRequestSuccess } from '../actions/requestPost';
|
||||
|
||||
import {
|
||||
ChangeFiltersActionTypes,
|
||||
SET_SEARCH_FILTER,
|
||||
@@ -54,9 +56,9 @@ const postsReducer = (
|
||||
return {
|
||||
...state,
|
||||
items: action.page === 1 ?
|
||||
action.posts.map(post => postReducer(undefined, {type: 'CONVERT', post})) //improve
|
||||
action.posts.map(post => postReducer(undefined, postRequestSuccess(post)))
|
||||
:
|
||||
[...state.items, ...action.posts.map(post => postReducer(undefined, {type: 'CONVERT', post}))],
|
||||
[...state.items, ...action.posts.map(post => postReducer(undefined, postRequestSuccess(post)))],
|
||||
page: action.page,
|
||||
haveMore: action.posts.length === 15,
|
||||
areLoading: false,
|
||||
|
||||
@@ -2,10 +2,12 @@ import { combineReducers } from 'redux';
|
||||
|
||||
import postsReducer from './postsReducer';
|
||||
import postStatusesReducer from './postStatusesReducer';
|
||||
import postReducer from './postReducer';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
posts: postsReducer,
|
||||
postStatuses: postStatusesReducer,
|
||||
currentPost: postReducer,
|
||||
});
|
||||
|
||||
export type State = ReturnType<typeof rootReducer>
|
||||
|
||||
Reference in New Issue
Block a user