-
Notifications
You must be signed in to change notification settings - Fork 219
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
Post Reactions #556
Changes from all commits
b534b91
2e6152a
ec5f5c5
d6a2b8b
eac6a39
446a765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.