Skip to content

Commit 2e352ab

Browse files
authored
Merge pull request #556 from AuraOfDivinity/reactions
Post Reactions
2 parents 9bc2ca6 + 446a765 commit 2e352ab

File tree

12 files changed

+686
-65
lines changed

12 files changed

+686
-65
lines changed

package-lock.json

Lines changed: 67 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
@@ -17,6 +17,7 @@
1717
"chart.js": "^2.9.3",
1818
"dotenv": "^8.2.0",
1919
"env-cmd": "^10.1.0",
20+
"framer-motion": "^2.3.0",
2021
"html-react-parser": "^0.13.0",
2122
"http-proxy-middleware": "^1.0.5",
2223
"jwt-decode": "^2.2.0",

src/actions/postAction.js

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,113 @@
1-
import axios from 'axios';
2-
import { errorHandler } from '../utils/errorHandler';
3-
import { setRequestStatus } from '../utils/setRequestStatus';
4-
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS, GET_SINGLE_POST } from './types';
5-
import { BASE_URL } from './baseApi'
1+
import axios from "axios";
2+
import { errorHandler } from "../utils/errorHandler";
3+
import { setRequestStatus } from "../utils/setRequestStatus";
4+
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS, GET_SINGLE_POST } from "./types";
5+
import { BASE_URL } from "./baseApi";
66

77
// GET ALL POSTS
88
export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
99
try {
10-
const res = await axios.get(`${BASE_URL}/post/all_posts?pagination=${pagination}&page=${page}`)
11-
dispatch(setRequestStatus(false))
12-
if(res.status === 200) {
13-
dispatch(setRequestStatus(true))
14-
console.log('all posts ', res.data.posts)
10+
const res = await axios.get(
11+
`${BASE_URL}/post/all_posts?pagination=${pagination}&page=${page}`
12+
);
13+
dispatch(setRequestStatus(false));
14+
if (res.status === 200) {
15+
dispatch(setRequestStatus(true));
16+
console.log("all posts ", res.data.posts);
1517
dispatch({
1618
type: GET_ALL_POSTS,
17-
payload: res.data.posts
18-
})
19+
payload: res.data.posts,
20+
});
1921
}
20-
} catch(error) {
21-
dispatch(errorHandler(error))
22+
} catch (error) {
23+
dispatch(errorHandler(error));
2224
}
23-
}
25+
};
2426

25-
// GET ALL PINNED POSTS
26-
export const getAllPinnedPosts = (pagination = 10, page = 1) => async (dispatch) => {
27+
// GET ALL PINNED POSTS
28+
export const getAllPinnedPosts = (pagination = 10, page = 1) => async (
29+
dispatch
30+
) => {
2731
try {
28-
const res = await axios.get(`${BASE_URL}/post/all/pinned?pagination=${pagination}&page=${page}`)
29-
dispatch(setRequestStatus(false))
30-
if(res.status === 200){
31-
dispatch(setRequestStatus(true))
32-
console.log('fetching all pinned posts ', res.data.pinnedPost)
32+
const res = await axios.get(
33+
`${BASE_URL}/post/all/pinned?pagination=${pagination}&page=${page}`
34+
);
35+
dispatch(setRequestStatus(false));
36+
if (res.status === 200) {
37+
dispatch(setRequestStatus(true));
38+
console.log("fetching all pinned posts ", res.data.pinnedPost);
3339
dispatch({
3440
type: GET_ALL_PINNED_POSTS,
35-
payload: res.data.pinnedPost
36-
})
41+
payload: res.data.pinnedPost,
42+
});
3743
}
38-
} catch(error) {
39-
dispatch(errorHandler(error))
44+
} catch (error) {
45+
dispatch(errorHandler(error));
4046
}
41-
}
47+
};
4248

4349
// UPVOTE POST
44-
export const upVotePost = (postId) => async (dispatch) => {
50+
export const upVotePost = (postId, type) => async (dispatch) => {
4551
try {
46-
const res = await axios.patch(`${BASE_URL}/post/upvote/${postId}`)
47-
if(res.status === 200) {
48-
console.log('successfully upvoted post ', res.data)
52+
const res = await axios.patch(`${BASE_URL}/post/upvote/${postId}`, type);
53+
if (res.status === 200) {
54+
console.log("successfully upvoted post ", res.data);
4955
dispatch(getAllPosts());
5056
}
5157
} catch (error) {
52-
dispatch(errorHandler(error))
58+
dispatch(errorHandler(error));
5359
}
54-
}
60+
};
5561

56-
// GET POST BY ID
62+
// GET POST BY ID
5763
export const getPostById = (postId) => async (dispatch) => {
5864
try {
59-
console.log('postId from action ', postId)
65+
console.log("postId from action ", postId);
6066
const res = await axios.get(`${BASE_URL}/post/${postId}`);
6167
if (res.status === 200) {
6268
dispatch({
6369
type: GET_SINGLE_POST,
64-
payload: res.data.post
65-
})
70+
payload: res.data.post,
71+
});
6672
}
6773
} catch (error) {
68-
dispatch(errorHandler(error))
74+
dispatch(errorHandler(error));
6975
}
70-
}
76+
};
7177

72-
// UPDATE POST
78+
// UPDATE POST
7379
export const updatePost = (postId, updatedInfo) => async (dispatch) => {
7480
try {
75-
console.log('updatedPostInfo ', updatedInfo)
76-
const res = await axios.patch(`${BASE_URL}/post/${postId}`, updatedInfo)
81+
console.log("updatedPostInfo ", updatedInfo);
82+
const res = await axios.patch(`${BASE_URL}/post/${postId}`, updatedInfo);
7783
if (res.status === 200) {
78-
dispatch(getPostById(postId))
84+
dispatch(getPostById(postId));
7985
}
8086
} catch (error) {
81-
dispatch(errorHandler(error))
87+
dispatch(errorHandler(error));
8288
}
83-
}
89+
};
8490

85-
// DELETE POST
91+
// DELETE POST
8692
export const deletePost = (postId) => async (dispatch) => {
8793
try {
88-
const res = await axios.delete(`${BASE_URL}/post/${postId}`)
89-
if(res.status === 200) {
90-
dispatch(getAllPosts())
94+
const res = await axios.delete(`${BASE_URL}/post/${postId}`);
95+
if (res.status === 200) {
96+
dispatch(getAllPosts());
97+
}
98+
} catch (error) {
99+
dispatch(errorHandler(error));
100+
}
101+
};
102+
103+
// REMOVE REACTION
104+
export const removeReaction = (postId, type) => async (dispatch) => {
105+
try {
106+
const res = await axios.patch(`${BASE_URL}/post/removereaction/${postId}`, type);
107+
if (res.status === 200) {
108+
dispatch(getAllPosts());
91109
}
92110
} catch (error) {
93-
dispatch(errorHandler(error))
111+
dispatch(errorHandler(error));
94112
}
95-
}
113+
};

src/images/DonutReaction.png

951 Bytes
Loading

src/images/Happy.png

691 Bytes
Loading

src/images/Heart.png

478 Bytes
Loading

src/images/Like.png

448 Bytes
Loading

0 commit comments

Comments
 (0)