mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Post follow and updates notifications V1 (#111)
* It is now possible to follow a post in order to receive updates about it * Notifications are now sent when updates are published * Post status changes are now tracked * Update sidebar now shows the post status history * Mark a comment as a post update using the comment form * ... more ...
This commit is contained in:
committed by
GitHub
parent
ce7be1b30c
commit
dad382d2b1
@@ -11,6 +11,7 @@ import {
|
||||
HandleCommentRepliesType,
|
||||
TOGGLE_COMMENT_REPLY,
|
||||
SET_COMMENT_REPLY_BODY,
|
||||
TOGGLE_COMMENT_IS_POST_UPDATE_FLAG,
|
||||
} from '../actions/Comment/handleCommentReplies';
|
||||
|
||||
import {
|
||||
@@ -82,6 +83,7 @@ const commentsReducer = (
|
||||
|
||||
case TOGGLE_COMMENT_REPLY:
|
||||
case SET_COMMENT_REPLY_BODY:
|
||||
case TOGGLE_COMMENT_IS_POST_UPDATE_FLAG:
|
||||
return {
|
||||
...state,
|
||||
replyForms: replyFormsReducer(state.replyForms, action),
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
HandleCommentRepliesType,
|
||||
TOGGLE_COMMENT_REPLY,
|
||||
SET_COMMENT_REPLY_BODY,
|
||||
TOGGLE_COMMENT_IS_POST_UPDATE_FLAG,
|
||||
} from '../actions/Comment/handleCommentReplies';
|
||||
|
||||
import {
|
||||
@@ -52,21 +53,40 @@ import {
|
||||
TOGGLE_COMMENT_IS_UPDATE_SUCCESS,
|
||||
} from '../actions/Comment/updateComment';
|
||||
|
||||
import { FollowActionTypes, FOLLOW_SUBMIT_SUCCESS } from '../actions/Follow/submitFollow';
|
||||
import { FollowRequestActionTypes, FOLLOW_REQUEST_SUCCESS } from '../actions/Follow/requestFollow';
|
||||
|
||||
import {
|
||||
PostStatusChangesRequestActionTypes,
|
||||
POST_STATUS_CHANGES_REQUEST_START,
|
||||
POST_STATUS_CHANGES_REQUEST_SUCCESS,
|
||||
POST_STATUS_CHANGES_REQUEST_FAILURE,
|
||||
} from '../actions/PostStatusChange/requestPostStatusChanges';
|
||||
|
||||
import {
|
||||
PostStatusChangeSubmitted,
|
||||
POST_STATUS_CHANGE_SUBMITTED
|
||||
} from '../actions/PostStatusChange/submittedPostStatusChange';
|
||||
|
||||
import postReducer from './postReducer';
|
||||
import likesReducer from './likesReducer';
|
||||
import commentsReducer from './commentsReducer';
|
||||
|
||||
import { LikesState } from './likesReducer';
|
||||
import { CommentsState } from './commentsReducer';
|
||||
import postStatusChangesReducer, { PostStatusChangesState } from './postStatusChangesReducer';
|
||||
|
||||
import IPost from '../interfaces/IPost';
|
||||
|
||||
|
||||
interface CurrentPostState {
|
||||
item: IPost;
|
||||
isLoading: boolean;
|
||||
error: string;
|
||||
likes: LikesState;
|
||||
followed: boolean;
|
||||
comments: CommentsState;
|
||||
postStatusChanges: PostStatusChangesState,
|
||||
}
|
||||
|
||||
const initialState: CurrentPostState = {
|
||||
@@ -74,7 +94,9 @@ const initialState: CurrentPostState = {
|
||||
isLoading: false,
|
||||
error: '',
|
||||
likes: likesReducer(undefined, {} as LikesRequestActionTypes),
|
||||
followed: false,
|
||||
comments: commentsReducer(undefined, {} as CommentsRequestActionTypes),
|
||||
postStatusChanges: postStatusChangesReducer(undefined, {} as PostStatusChangesRequestActionTypes),
|
||||
};
|
||||
|
||||
const currentPostReducer = (
|
||||
@@ -88,7 +110,11 @@ const currentPostReducer = (
|
||||
CommentsRequestActionTypes |
|
||||
HandleCommentRepliesType |
|
||||
CommentSubmitActionTypes |
|
||||
ToggleIsUpdateSuccessAction
|
||||
ToggleIsUpdateSuccessAction |
|
||||
FollowActionTypes |
|
||||
FollowRequestActionTypes |
|
||||
PostStatusChangesRequestActionTypes |
|
||||
PostStatusChangeSubmitted
|
||||
): CurrentPostState => {
|
||||
switch (action.type) {
|
||||
case POST_REQUEST_START:
|
||||
@@ -137,11 +163,33 @@ const currentPostReducer = (
|
||||
case COMMENT_SUBMIT_SUCCESS:
|
||||
case COMMENT_SUBMIT_FAILURE:
|
||||
case TOGGLE_COMMENT_IS_UPDATE_SUCCESS:
|
||||
case TOGGLE_COMMENT_IS_POST_UPDATE_FLAG:
|
||||
return {
|
||||
...state,
|
||||
comments: commentsReducer(state.comments, action),
|
||||
};
|
||||
|
||||
case FOLLOW_REQUEST_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
followed: action.follow.user_id ? true : false,
|
||||
};
|
||||
|
||||
case FOLLOW_SUBMIT_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
followed: action.isFollow,
|
||||
};
|
||||
|
||||
case POST_STATUS_CHANGES_REQUEST_START:
|
||||
case POST_STATUS_CHANGES_REQUEST_SUCCESS:
|
||||
case POST_STATUS_CHANGES_REQUEST_FAILURE:
|
||||
case POST_STATUS_CHANGE_SUBMITTED:
|
||||
return {
|
||||
...state,
|
||||
postStatusChanges: postStatusChangesReducer(state.postStatusChanges, action),
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
71
app/javascript/reducers/postStatusChangesReducer.ts
Normal file
71
app/javascript/reducers/postStatusChangesReducer.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
PostStatusChangesRequestActionTypes,
|
||||
POST_STATUS_CHANGES_REQUEST_START,
|
||||
POST_STATUS_CHANGES_REQUEST_SUCCESS,
|
||||
POST_STATUS_CHANGES_REQUEST_FAILURE,
|
||||
} from "../actions/PostStatusChange/requestPostStatusChanges";
|
||||
|
||||
import {
|
||||
PostStatusChangeSubmitted,
|
||||
POST_STATUS_CHANGE_SUBMITTED
|
||||
} from '../actions/PostStatusChange/submittedPostStatusChange';
|
||||
|
||||
import IPostStatusChange from "../interfaces/IPostStatusChange";
|
||||
|
||||
export interface PostStatusChangesState {
|
||||
items: Array<IPostStatusChange>;
|
||||
areLoading: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const initialState: PostStatusChangesState = {
|
||||
items: [],
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
const postStatusChangesReducer = (
|
||||
state = initialState,
|
||||
action:
|
||||
PostStatusChangesRequestActionTypes |
|
||||
PostStatusChangeSubmitted
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case POST_STATUS_CHANGES_REQUEST_START:
|
||||
return {
|
||||
...state,
|
||||
areLoading: true,
|
||||
};
|
||||
|
||||
case POST_STATUS_CHANGES_REQUEST_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
items: action.postStatusChanges.map(postStatusChange => ({
|
||||
postStatusId: postStatusChange.post_status_id,
|
||||
userFullName: postStatusChange.user_full_name,
|
||||
userEmail: postStatusChange.user_email,
|
||||
updatedAt: postStatusChange.updated_at,
|
||||
})),
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case POST_STATUS_CHANGES_REQUEST_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
areLoading: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case POST_STATUS_CHANGE_SUBMITTED:
|
||||
return {
|
||||
...state,
|
||||
items: [action.postStatusChange, ...state.items],
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default postStatusChangesReducer;
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
HandleCommentRepliesType,
|
||||
TOGGLE_COMMENT_REPLY,
|
||||
SET_COMMENT_REPLY_BODY,
|
||||
TOGGLE_COMMENT_IS_POST_UPDATE_FLAG,
|
||||
} from '../actions/Comment/handleCommentReplies';
|
||||
|
||||
import {
|
||||
@@ -20,6 +21,7 @@ export interface ReplyFormState {
|
||||
commentId: number;
|
||||
isOpen: boolean;
|
||||
body: string;
|
||||
isPostUpdate: boolean;
|
||||
isSubmitting: boolean;
|
||||
error: string;
|
||||
}
|
||||
@@ -28,6 +30,7 @@ const initialState: ReplyFormState = {
|
||||
commentId: undefined,
|
||||
isOpen: false,
|
||||
body: '',
|
||||
isPostUpdate: false,
|
||||
isSubmitting: false,
|
||||
error: '',
|
||||
}
|
||||
@@ -58,6 +61,12 @@ const replyFormReducer = (
|
||||
body: action.body,
|
||||
};
|
||||
|
||||
case TOGGLE_COMMENT_IS_POST_UPDATE_FLAG:
|
||||
return {
|
||||
...state,
|
||||
isPostUpdate: !state.isPostUpdate,
|
||||
};
|
||||
|
||||
case COMMENT_SUBMIT_START:
|
||||
return {
|
||||
...state,
|
||||
@@ -69,6 +78,7 @@ const replyFormReducer = (
|
||||
...state,
|
||||
isOpen: false,
|
||||
body: '',
|
||||
isPostUpdate: false,
|
||||
isSubmitting: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
HandleCommentRepliesType,
|
||||
TOGGLE_COMMENT_REPLY,
|
||||
SET_COMMENT_REPLY_BODY,
|
||||
TOGGLE_COMMENT_IS_POST_UPDATE_FLAG,
|
||||
} from '../actions/Comment/handleCommentReplies';
|
||||
|
||||
import {
|
||||
@@ -42,6 +43,7 @@ const ReplyFormsReducer = (
|
||||
|
||||
case TOGGLE_COMMENT_REPLY:
|
||||
case SET_COMMENT_REPLY_BODY:
|
||||
case TOGGLE_COMMENT_IS_POST_UPDATE_FLAG:
|
||||
return (
|
||||
state.map(
|
||||
replyForm => (
|
||||
|
||||
Reference in New Issue
Block a user