mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add post status administration (#105)
This commit is contained in:
committed by
GitHub
parent
c5148147e3
commit
5256ea911a
81
app/javascript/reducers/SiteSettings/postStatusesReducer.ts
Normal file
81
app/javascript/reducers/SiteSettings/postStatusesReducer.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
PostStatusOrderUpdateActionTypes,
|
||||
POSTSTATUS_ORDER_UPDATE_START,
|
||||
POSTSTATUS_ORDER_UPDATE_SUCCESS,
|
||||
POSTSTATUS_ORDER_UPDATE_FAILURE,
|
||||
} from '../../actions/updatePostStatusOrder';
|
||||
|
||||
import {
|
||||
PostStatusDeleteActionTypes,
|
||||
POST_STATUS_DELETE_START,
|
||||
POST_STATUS_DELETE_SUCCESS,
|
||||
POST_STATUS_DELETE_FAILURE,
|
||||
} from '../../actions/deletePostStatus';
|
||||
|
||||
import {
|
||||
PostStatusSubmitActionTypes,
|
||||
POSTSTATUS_SUBMIT_START,
|
||||
POSTSTATUS_SUBMIT_SUCCESS,
|
||||
POSTSTATUS_SUBMIT_FAILURE,
|
||||
} from '../../actions/submitPostStatus';
|
||||
|
||||
import {
|
||||
PostStatusUpdateActionTypes,
|
||||
POSTSTATUS_UPDATE_START,
|
||||
POSTSTATUS_UPDATE_SUCCESS,
|
||||
POSTSTATUS_UPDATE_FAILURE,
|
||||
} from '../../actions/updatePostStatus';
|
||||
|
||||
export interface SiteSettingsPostStatusesState {
|
||||
areUpdating: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const initialState: SiteSettingsPostStatusesState = {
|
||||
areUpdating: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
const siteSettingsPostStatusesReducer = (
|
||||
state = initialState,
|
||||
action: PostStatusOrderUpdateActionTypes |
|
||||
PostStatusDeleteActionTypes |
|
||||
PostStatusSubmitActionTypes |
|
||||
PostStatusUpdateActionTypes
|
||||
): SiteSettingsPostStatusesState => {
|
||||
switch (action.type) {
|
||||
case POSTSTATUS_SUBMIT_START:
|
||||
case POSTSTATUS_UPDATE_START:
|
||||
case POSTSTATUS_ORDER_UPDATE_START:
|
||||
case POST_STATUS_DELETE_START:
|
||||
return {
|
||||
...state,
|
||||
areUpdating: true,
|
||||
};
|
||||
|
||||
case POSTSTATUS_SUBMIT_SUCCESS:
|
||||
case POSTSTATUS_UPDATE_SUCCESS:
|
||||
case POSTSTATUS_ORDER_UPDATE_SUCCESS:
|
||||
case POST_STATUS_DELETE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
areUpdating: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case POSTSTATUS_SUBMIT_FAILURE:
|
||||
case POSTSTATUS_UPDATE_FAILURE:
|
||||
case POSTSTATUS_ORDER_UPDATE_FAILURE:
|
||||
case POST_STATUS_DELETE_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
areUpdating: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default siteSettingsPostStatusesReducer;
|
||||
@@ -5,6 +5,26 @@ import {
|
||||
POST_STATUSES_REQUEST_FAILURE,
|
||||
} from '../actions/requestPostStatuses';
|
||||
|
||||
import {
|
||||
PostStatusOrderUpdateActionTypes,
|
||||
POSTSTATUS_ORDER_UPDATE_START,
|
||||
} from '../actions/updatePostStatusOrder';
|
||||
|
||||
import {
|
||||
PostStatusDeleteActionTypes,
|
||||
POST_STATUS_DELETE_SUCCESS,
|
||||
} from '../actions/deletePostStatus';
|
||||
|
||||
import {
|
||||
PostStatusSubmitActionTypes,
|
||||
POSTSTATUS_SUBMIT_SUCCESS,
|
||||
} from '../actions/submitPostStatus';
|
||||
|
||||
import {
|
||||
PostStatusUpdateActionTypes,
|
||||
POSTSTATUS_UPDATE_SUCCESS,
|
||||
} from '../actions/updatePostStatus';
|
||||
|
||||
import IPostStatus from '../interfaces/IPostStatus';
|
||||
|
||||
export interface PostStatusesState {
|
||||
@@ -21,7 +41,11 @@ const initialState: PostStatusesState = {
|
||||
|
||||
const postStatusesReducer = (
|
||||
state = initialState,
|
||||
action: PostStatusesRequestActionTypes,
|
||||
action: PostStatusesRequestActionTypes |
|
||||
PostStatusOrderUpdateActionTypes |
|
||||
PostStatusDeleteActionTypes |
|
||||
PostStatusSubmitActionTypes |
|
||||
PostStatusUpdateActionTypes
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case POST_STATUSES_REQUEST_START:
|
||||
@@ -49,6 +73,33 @@ const postStatusesReducer = (
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case POSTSTATUS_SUBMIT_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: [...state.items, action.postStatus],
|
||||
};
|
||||
|
||||
case POSTSTATUS_UPDATE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: state.items.map(postStatus => {
|
||||
if (postStatus.id !== action.postStatus.id) return postStatus;
|
||||
return {...postStatus, name: action.postStatus.name, color: action.postStatus.color};
|
||||
}),
|
||||
};
|
||||
|
||||
case POST_STATUS_DELETE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: state.items.filter(postStatus => postStatus.id !== action.id),
|
||||
};
|
||||
|
||||
case POSTSTATUS_ORDER_UPDATE_START:
|
||||
return {
|
||||
...state,
|
||||
items: action.newOrder,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
COMMENT_SUBMIT_FAILURE,
|
||||
} from '../actions/submitComment';
|
||||
|
||||
|
||||
import replyFormReducer, { ReplyFormState } from './replyFormReducer';
|
||||
|
||||
import ICommentJSON from '../interfaces/json/IComment';
|
||||
|
||||
@@ -3,11 +3,13 @@ import { combineReducers } from 'redux';
|
||||
import postsReducer from './postsReducer';
|
||||
import postStatusesReducer from './postStatusesReducer';
|
||||
import currentPostReducer from './currentPostReducer';
|
||||
import siteSettingsReducer from './siteSettingsReducer';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
posts: postsReducer,
|
||||
postStatuses: postStatusesReducer,
|
||||
currentPost: currentPostReducer,
|
||||
siteSettings: siteSettingsReducer,
|
||||
});
|
||||
|
||||
export type State = ReturnType<typeof rootReducer>
|
||||
|
||||
68
app/javascript/reducers/siteSettingsReducer.ts
Normal file
68
app/javascript/reducers/siteSettingsReducer.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
PostStatusOrderUpdateActionTypes,
|
||||
POSTSTATUS_ORDER_UPDATE_START,
|
||||
POSTSTATUS_ORDER_UPDATE_SUCCESS,
|
||||
POSTSTATUS_ORDER_UPDATE_FAILURE,
|
||||
} from '../actions/updatePostStatusOrder';
|
||||
|
||||
import {
|
||||
PostStatusDeleteActionTypes,
|
||||
POST_STATUS_DELETE_START,
|
||||
POST_STATUS_DELETE_SUCCESS,
|
||||
POST_STATUS_DELETE_FAILURE,
|
||||
} from '../actions/deletePostStatus';
|
||||
|
||||
import {
|
||||
PostStatusSubmitActionTypes,
|
||||
POSTSTATUS_SUBMIT_START,
|
||||
POSTSTATUS_SUBMIT_SUCCESS,
|
||||
POSTSTATUS_SUBMIT_FAILURE,
|
||||
} from '../actions/submitPostStatus';
|
||||
|
||||
import {
|
||||
PostStatusUpdateActionTypes,
|
||||
POSTSTATUS_UPDATE_START,
|
||||
POSTSTATUS_UPDATE_SUCCESS,
|
||||
POSTSTATUS_UPDATE_FAILURE,
|
||||
} from '../actions/updatePostStatus';
|
||||
|
||||
import siteSettingsPostStatusesReducer, { SiteSettingsPostStatusesState } from './SiteSettings/postStatusesReducer';
|
||||
|
||||
interface SiteSettingsState {
|
||||
postStatuses: SiteSettingsPostStatusesState;
|
||||
}
|
||||
|
||||
const initialState: SiteSettingsState = {
|
||||
postStatuses: siteSettingsPostStatusesReducer(undefined, {} as any),
|
||||
};
|
||||
|
||||
const siteSettingsReducer = (
|
||||
state = initialState,
|
||||
action: PostStatusOrderUpdateActionTypes |
|
||||
PostStatusDeleteActionTypes |
|
||||
PostStatusSubmitActionTypes |
|
||||
PostStatusUpdateActionTypes
|
||||
): SiteSettingsState => {
|
||||
switch (action.type) {
|
||||
case POSTSTATUS_ORDER_UPDATE_START:
|
||||
case POSTSTATUS_ORDER_UPDATE_SUCCESS:
|
||||
case POSTSTATUS_ORDER_UPDATE_FAILURE:
|
||||
case POST_STATUS_DELETE_START:
|
||||
case POST_STATUS_DELETE_SUCCESS:
|
||||
case POST_STATUS_DELETE_FAILURE:
|
||||
case POSTSTATUS_SUBMIT_START:
|
||||
case POSTSTATUS_SUBMIT_SUCCESS:
|
||||
case POSTSTATUS_SUBMIT_FAILURE:
|
||||
case POSTSTATUS_UPDATE_START:
|
||||
case POSTSTATUS_UPDATE_SUCCESS:
|
||||
case POSTSTATUS_UPDATE_FAILURE:
|
||||
return {
|
||||
postStatuses: siteSettingsPostStatusesReducer(state.postStatuses, action)
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default siteSettingsReducer;
|
||||
Reference in New Issue
Block a user