Skip to content

Post Reactions #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"chart.js": "^2.9.3",
"dotenv": "^8.2.0",
"env-cmd": "^10.1.0",
"framer-motion": "^2.3.0",
"html-react-parser": "^0.13.0",
"http-proxy-middleware": "^1.0.5",
"jwt-decode": "^2.2.0",
Expand Down
120 changes: 69 additions & 51 deletions src/actions/postAction.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,113 @@
import axios from 'axios';
import { errorHandler } from '../utils/errorHandler';
import { setRequestStatus } from '../utils/setRequestStatus';
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS, GET_SINGLE_POST } from './types';
import { BASE_URL } from './baseApi'
import axios from "axios";
import { errorHandler } from "../utils/errorHandler";
import { setRequestStatus } from "../utils/setRequestStatus";
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS, GET_SINGLE_POST } from "./types";
import { BASE_URL } from "./baseApi";

// GET ALL POSTS
export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
try {
const res = await axios.get(`${BASE_URL}/post/all_posts?pagination=${pagination}&page=${page}`)
dispatch(setRequestStatus(false))
if(res.status === 200) {
dispatch(setRequestStatus(true))
console.log('all posts ', res.data.posts)
const res = await axios.get(
Copy link
Member

@Rupeshiya Rupeshiya Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AuraOfDivinity Please remove these unnecessary format changes, this is a pretty annoying issue. Its destroying uniformity in the code style

`${BASE_URL}/post/all_posts?pagination=${pagination}&page=${page}`
);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
console.log("all posts ", res.data.posts);
dispatch({
type: GET_ALL_POSTS,
payload: res.data.posts
})
payload: res.data.posts,
});
}
} catch(error) {
dispatch(errorHandler(error))
} catch (error) {
dispatch(errorHandler(error));
}
}
};

// GET ALL PINNED POSTS
export const getAllPinnedPosts = (pagination = 10, page = 1) => async (dispatch) => {
// GET ALL PINNED POSTS
export const getAllPinnedPosts = (pagination = 10, page = 1) => async (
dispatch
) => {
try {
const res = await axios.get(`${BASE_URL}/post/all/pinned?pagination=${pagination}&page=${page}`)
dispatch(setRequestStatus(false))
if(res.status === 200){
dispatch(setRequestStatus(true))
console.log('fetching all pinned posts ', res.data.pinnedPost)
const res = await axios.get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un-necessary changes

`${BASE_URL}/post/all/pinned?pagination=${pagination}&page=${page}`
);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
console.log("fetching all pinned posts ", res.data.pinnedPost);
dispatch({
type: GET_ALL_PINNED_POSTS,
payload: res.data.pinnedPost
})
payload: res.data.pinnedPost,
});
}
} catch(error) {
dispatch(errorHandler(error))
} catch (error) {
dispatch(errorHandler(error));
}
}
};

// UPVOTE POST
export const upVotePost = (postId) => async (dispatch) => {
export const upVotePost = (postId, type) => async (dispatch) => {
try {
const res = await axios.patch(`${BASE_URL}/post/upvote/${postId}`)
if(res.status === 200) {
console.log('successfully upvoted post ', res.data)
const res = await axios.patch(`${BASE_URL}/post/upvote/${postId}`, type);
if (res.status === 200) {
console.log("successfully upvoted post ", res.data);
dispatch(getAllPosts());
}
} catch (error) {
dispatch(errorHandler(error))
dispatch(errorHandler(error));
}
}
};

// GET POST BY ID
// GET POST BY ID
export const getPostById = (postId) => async (dispatch) => {
try {
console.log('postId from action ', postId)
console.log("postId from action ", postId);
const res = await axios.get(`${BASE_URL}/post/${postId}`);
if (res.status === 200) {
dispatch({
type: GET_SINGLE_POST,
payload: res.data.post
})
payload: res.data.post,
});
}
} catch (error) {
dispatch(errorHandler(error))
dispatch(errorHandler(error));
}
}
};

// UPDATE POST
// UPDATE POST
export const updatePost = (postId, updatedInfo) => async (dispatch) => {
try {
console.log('updatedPostInfo ', updatedInfo)
const res = await axios.patch(`${BASE_URL}/post/${postId}`, updatedInfo)
console.log("updatedPostInfo ", updatedInfo);
const res = await axios.patch(`${BASE_URL}/post/${postId}`, updatedInfo);
if (res.status === 200) {
dispatch(getPostById(postId))
dispatch(getPostById(postId));
}
} catch (error) {
dispatch(errorHandler(error))
dispatch(errorHandler(error));
}
}
};

// DELETE POST
// DELETE POST
export const deletePost = (postId) => async (dispatch) => {
try {
const res = await axios.delete(`${BASE_URL}/post/${postId}`)
if(res.status === 200) {
dispatch(getAllPosts())
const res = await axios.delete(`${BASE_URL}/post/${postId}`);
if (res.status === 200) {
dispatch(getAllPosts());
}
} catch (error) {
dispatch(errorHandler(error));
}
};

// REMOVE REACTION
export const removeReaction = (postId, type) => async (dispatch) => {
try {
const res = await axios.patch(`${BASE_URL}/post/removereaction/${postId}`, type);
if (res.status === 200) {
dispatch(getAllPosts());
}
} catch (error) {
dispatch(errorHandler(error))
dispatch(errorHandler(error));
}
}
};
Binary file added src/images/DonutReaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/Happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/Heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/Like.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading