Add basic version of post show page

This commit is contained in:
riggraz
2019-09-12 15:51:45 +02:00
parent 5ca113b545
commit f599471af1
18 changed files with 330 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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>