Upload 5.12

This commit is contained in:
Andrew Trieu
2023-06-21 09:57:08 +03:00
parent 8c37a7308b
commit bb55cbad5b
11 changed files with 463 additions and 168 deletions

View File

@@ -1,30 +1,30 @@
import { useState } from "react";
import blogService from "../services/blogs";
import Togglable from "./Togglable";
import { useState } from 'react'
import blogService from '../services/blogs'
import Togglable from './Togglable'
const Blog = ({ blog, setNotification, removeBlog }) => {
const blogStyle = {
paddingTop: 10,
paddingLeft: 2,
border: "solid",
border: 'solid',
borderWidth: 1,
marginBottom: 5,
};
}
const [likes, setLikes] = useState(blog.likes);
const [likes, setLikes] = useState(blog.likes)
const handleLike = (blog) => {
blog.likes = blog.likes + 1;
blog.likes = blog.likes + 1
blogService
.update(blog.id, blog)
.then((returnedBlog) => {
setLikes(returnedBlog.likes);
setNotification(`You liked ${blog.title}`, "success");
setLikes(returnedBlog.likes)
setNotification(`You liked ${blog.title}`, 'success')
})
.catch((error) => {
setNotification(`Like failed. Error: ${error}`, "error");
});
};
setNotification(`Like failed. Error: ${error}`, 'error')
})
}
return (
<div style={blogStyle}>
@@ -43,7 +43,7 @@ const Blog = ({ blog, setNotification, removeBlog }) => {
</Togglable>
</div>
</div>
);
};
)
}
export default Blog;
export default Blog