Skip to content

Commit

Permalink
fix:like system bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SySagar committed Sep 22, 2023
1 parent 69259cb commit bbe6223
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/app/blog/ShowBlog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
Avatar,
Button,
CircularProgress,
Divider,
IconButton,
Stack,
Expand Down Expand Up @@ -152,11 +153,14 @@ export default function ShowBlog() {
localStorage.getItem("user") as string
) as unknown as LikeBlogTypes;
const userId = user._id;
console.log("userId", userId);
await APIMethods.blog
.likeBlog({ userId, blogId })
.then(async (res) => {
.then(async (res:any) => {
console.log(res);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if(res.data.status == 400) {
window.location.href = "/auth/login";
}
const data = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
userId: JSON.parse(localStorage.getItem("user") as string)._id as string,
Expand All @@ -183,6 +187,7 @@ export default function ShowBlog() {
})
.catch((e) => {
console.log(e);
navigate("/auth/login");
});
}

Expand Down Expand Up @@ -231,6 +236,12 @@ export default function ShowBlog() {
padding={5}
>
<UserProfile authorId={authorid} isOpen={isSidebarOpen} onClose={() => setIsSidebarOpen(false)} />

{
isLoading? <Stack minHeight={'100vh'}>
<CircularProgress />
</Stack>:

<Stack
width={"900px"}
justifyContent={"center"}
Expand Down Expand Up @@ -336,6 +347,7 @@ export default function ShowBlog() {
}}
/>
</Stack>
}
</Stack>
);
}
9 changes: 6 additions & 3 deletions src/app/notifications/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ export default function Notification() {
}, [notifications]);

return (
<Stack minWidth={350} minHeight={400} >
<Stack minWidth={350} height={400} >
<Typography variant='body1' borderBottom={'3px solid #bfbfbf'} fontWeight={600} paddingLeft={2} paddingY={2} position={'sticky'} top={0} zIndex={2} sx={{background:'#fff'}}>
All Notifications
</Typography>
{


notifications.length!=0 ?(

notifications.slice().reverse().map((singleItem,idx) => {
return (
<Stack key={idx} className='inNots' width={350} padding={2} paddingY={3} borderBottom={1} borderColor={'grey'}>
<Typography>
<Stack key={idx} className='inNots' width={350} padding={2} paddingY={3} borderBottom={'1px solid #d9d9d9'} >
<Typography variant='body2'>
{singleItem}
</Typography>
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/axios/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const APIMethods = {
deleteBlog: async (id: string) => {return await AuthorizedAPIInstance.delete(`/blog/${id}`)},
getUserBlogs: async (email:any) => {return await APIInstance.post("/blog/getUserBlogs",email)},
getUserBlogsByUserId: async (authorId:any) => {return await APIInstance.post("/blog/getUserBlogsByUserId",authorId)},
likeBlog: async (data: {userId:string,blogId:string}) => {await AuthorizedAPIInstance.post(`/blog/${data.blogId}`, data)},
likeBlog: async (data: {userId:string,blogId:string}) => {return await AuthorizedAPIInstance.post(`/blog/${data.blogId}`, data)},
commentOnBlog: async (data: {userId:string,blogId:string,comment:string}) => {await AuthorizedAPIInstance.post(`/blog/comment/${data.blogId}`, data)},
getComments: async (data: {blogId:string}) => {return await APIInstance.get(`/blog/comments/${data.blogId}`)},
addComment: async (data: {blogId:string,comment:string,authorId:string}) => {return await AuthorizedAPIInstance.post(`/blog/comment/${data.blogId}`, data)},
Expand Down

0 comments on commit bbe6223

Please sign in to comment.