Skip to content

Commit 56cbf80

Browse files
Addition of Post Content Popup
1 parent 71f0320 commit 56cbf80

File tree

10 files changed

+612
-52
lines changed

10 files changed

+612
-52
lines changed

package-lock.json

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"react-toastify": "^6.0.5",
3838
"redux": "^4.0.5",
3939
"redux-thunk": "^2.3.0",
40+
"showdown": "^1.9.1",
4041
"socket.io-client": "^2.3.0"
4142
},
4243
"proxy": "http://localhost:5000",

src/actions/commentAction.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
1-
import { GET_COMMENTS_OF_A_POST } from './types'
2-
import { errorHandler } from '../utils/errorHandler'
3-
import axios from 'axios'
4-
import { setRequestStatus } from '../utils/setRequestStatus'
1+
import { GET_COMMENTS_OF_A_POST, RESET_COMMENTS } from "./types";
2+
import { errorHandler } from "../utils/errorHandler";
3+
import axios from "axios";
4+
import { setRequestStatus } from "../utils/setRequestStatus";
55

6-
// CREATE COMMENT ON A PARTICULAR POST
6+
// CREATE COMMENT ON A PARTICULAR POST
77
export const createComment = (postId, comment) => async (dispatch) => {
88
try {
9-
const res = await axios.post(`/comment/${postId}`, comment)
9+
const res = await axios.post(`/comment/${postId}`, comment);
1010
dispatch(setRequestStatus(false));
11-
if(res.status === 201) {
12-
dispatch(setRequestStatus(true))
13-
console.log('created comment ', res.data.comment)
11+
if (res.status === 201) {
12+
dispatch(setRequestStatus(true));
13+
console.log("created comment ", res.data.comment);
1414
dispatch(getAllCommentsOfPost());
1515
}
16-
} catch(error) {
17-
dispatch(errorHandler(error))
16+
} catch (error) {
17+
dispatch(errorHandler(error));
1818
}
19-
}
19+
};
2020

2121
// GET ALL COMMENTS OF A POST
2222
export const getAllCommentsOfPost = (postId) => async (dispatch) => {
2323
try {
24-
const res = await axios.get(`/comment/${postId}`)
25-
dispatch(setRequestStatus(false))
26-
if(res.status === 200) {
24+
const res = await axios.get(`/comment/${postId}`);
25+
dispatch(setRequestStatus(false));
26+
if (res.status === 200) {
2727
dispatch(setRequestStatus(true));
28-
console.log('fetching comments of ', postId, res.data.comments);
28+
console.log("fetching comments of ", postId, res.data.comments);
2929
dispatch({
3030
type: GET_COMMENTS_OF_A_POST,
31-
payload: res.data.comments
32-
})
31+
payload: res.data.comments,
32+
});
3333
}
34-
} catch(error) {
35-
dispatch(errorHandler(error))
34+
} catch (error) {
35+
dispatch(errorHandler(error));
3636
}
37-
}
37+
};
3838

3939
// UPDATE COMMENT OF A POST
40-
export const updateComment = (commentId, updatedComment) => async (dispatch) => {
40+
export const updateComment = (commentId, updatedComment) => async (
41+
dispatch
42+
) => {
4143
try {
42-
const res = await axios.patch(`/comment/${commentId}`, updatedComment)
43-
dispatch(setRequestStatus(false))
44-
if(res.status === 200) {
45-
dispatch(setRequestStatus(true))
46-
console.log('comment updated ', res.data.comment)
47-
dispatch(getAllCommentsOfPost())
44+
const res = await axios.patch(`/comment/${commentId}`, updatedComment);
45+
dispatch(setRequestStatus(false));
46+
if (res.status === 200) {
47+
dispatch(setRequestStatus(true));
48+
console.log("comment updated ", res.data.comment);
49+
dispatch(getAllCommentsOfPost());
4850
}
49-
} catch(error) {
50-
errorHandler(error)
51+
} catch (error) {
52+
errorHandler(error);
5153
}
52-
}
54+
};
5355

5456
// DELETE COMMENT
5557
export const deleteComment = (commentId) => async (dispatch) => {
5658
try {
57-
const res = await axios.delete(`/comment/${commentId}`)
58-
dispatch(setRequestStatus(false))
59-
if(res.status === 200) {
59+
const res = await axios.delete(`/comment/${commentId}`);
60+
dispatch(setRequestStatus(false));
61+
if (res.status === 200) {
6062
dispatch(setRequestStatus(true));
61-
console.log('comment deleted ', res.data)
62-
dispatch(getAllCommentsOfPost())
63+
console.log("comment deleted ", res.data);
64+
dispatch(getAllCommentsOfPost());
6365
}
64-
} catch(error) {
65-
dispatch(errorHandler(error))
66+
} catch (error) {
67+
dispatch(errorHandler(error));
6668
}
67-
}
69+
};
70+
71+
export const resetComments = () => async (dispatch) => {
72+
dispatch({ type: RESET_COMMENTS });
73+
};

src/actions/types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export const GET_ALL_PINNED_POSTS = "GET_ALL_PINNED_POSTS";
3838
export const GET_EVENT_BY_ID = "GET_EVENT_BY_ID";
3939
export const GET_ADMIN = "GET_ADMIN";
4040
export const GET_COMMENTS_OF_A_POST = "GET_COMMENTS_OF_A_POST";
41+
export const RESET_COMMENTS = "RESET_COMMENTS";
4142
export const GET_SINGLE_PROJECT = "GET_SINGLE_PROJECT";
42-
export const PASSWORD_CHANGE_REQUEST_SUCCESS = "PASSWORD_CHANGE_REQUEST_SUCCESS";
43+
export const PASSWORD_CHANGE_REQUEST_SUCCESS =
44+
"PASSWORD_CHANGE_REQUEST_SUCCESS";
4345
export const PASSWORD_SUCCESSFULLY_CHANGED = "PASSWORD_SUCCESSFULLY_CHANGED";
4446
export const GET_INVITE_LINK = "GET_INVITE_LINK";
4547
export const PROCESS_INVITE_LINK = "PROCESS_INVITE_LINK";

src/reducers/commentReducer.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { GET_COMMENTS_OF_A_POST } from '../actions/types'
1+
import { GET_COMMENTS_OF_A_POST, RESET_COMMENTS } from "../actions/types";
22

33
const initialState = {
4-
allComments: []
5-
}
4+
allComments: [],
5+
};
66

77
export default (state = initialState, action) => {
8-
switch(action.type) {
8+
switch (action.type) {
99
case GET_COMMENTS_OF_A_POST: {
1010
return {
1111
...state,
12-
allComments: action.payload
13-
}
12+
allComments: action.payload,
13+
};
14+
}
15+
case RESET_COMMENTS: {
16+
return {
17+
allComments: [],
18+
};
1419
}
1520
default: {
16-
return state
21+
return state;
1722
}
1823
}
19-
}
24+
};

0 commit comments

Comments
 (0)