search blog update
This commit is contained in:
parent
df179be1fa
commit
49794dfb7b
@ -83,7 +83,8 @@ const Blogs = () => {
|
|||||||
}).then((value) => {
|
}).then((value) => {
|
||||||
if (value === true) {
|
if (value === true) {
|
||||||
axios
|
axios
|
||||||
.delete(`/api/v1/blog/deleteblog/${id}`, { // Correct the API endpoint
|
.delete(`/api/v1/blog/deleteblog/${id}`, {
|
||||||
|
// Correct the API endpoint
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
@ -110,24 +111,23 @@ const Blogs = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (query !== "") {
|
if (query !== "") {
|
||||||
let searchedResult = [];
|
const lowerCaseQuery = query.toLowerCase(); // Convert query to lowercase
|
||||||
searchedResult = BlogsData.filter((item) =>
|
|
||||||
item.title.toString().includes(query)
|
const searchedResult = BlogsData.filter((item) =>
|
||||||
|
item.title.toString().toLowerCase().includes(lowerCaseQuery)
|
||||||
);
|
);
|
||||||
|
|
||||||
setShowData(searchedResult);
|
setShowData(searchedResult);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
getBlogsData();
|
getBlogsData();
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}, [query]);
|
}, [query]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
<div className="page-content">
|
<div className="page-content">
|
||||||
@ -323,7 +323,10 @@ const Blogs = () => {
|
|||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
<Link to={`/blog/view/${blog._id}`}>
|
<Link to={`/blog/view/${blog._id}`}>
|
||||||
<button
|
<button
|
||||||
style={{ color: "white", marginRight: "1rem" }}
|
style={{
|
||||||
|
color: "white",
|
||||||
|
marginRight: "1rem",
|
||||||
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
className="
|
className="
|
||||||
btn btn-primary btn-sm
|
btn btn-primary btn-sm
|
||||||
@ -338,7 +341,10 @@ const Blogs = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
<Link to={`/blog/edit/${blog._id}`}>
|
<Link to={`/blog/edit/${blog._id}`}>
|
||||||
<button
|
<button
|
||||||
style={{ color: "white", marginRight: "1rem" }}
|
style={{
|
||||||
|
color: "white",
|
||||||
|
marginRight: "1rem",
|
||||||
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
className="
|
className="
|
||||||
btn btn-info btn-sm
|
btn btn-info btn-sm
|
||||||
@ -381,10 +387,7 @@ const Blogs = () => {
|
|||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
{Math.min(
|
{Math.min(currentPage * itemPerPage, BlogsData.length)}{" "}
|
||||||
currentPage * itemPerPage,
|
|
||||||
BlogsData.length
|
|
||||||
)}{" "}
|
|
||||||
of {BlogsData.length} entries
|
of {BlogsData.length} entries
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -58,55 +58,6 @@ const CreateBlog = () => {
|
|||||||
setimage(null);
|
setimage(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// const handleSubmit = () => {
|
|
||||||
// setLoading(true);
|
|
||||||
|
|
||||||
// const contentState = blogContent.getCurrentContent();
|
|
||||||
// const htmlData = stateToHTML(contentState);
|
|
||||||
// // console.log(title, typeof htmlData, image, tag);
|
|
||||||
|
|
||||||
// const formData = new FormData();
|
|
||||||
// formData.append("title", title);
|
|
||||||
// formData.append("blog_content", htmlData);
|
|
||||||
|
|
||||||
// formData.append("image", image);
|
|
||||||
// formData.append("tags", tag);
|
|
||||||
// // for (let entry of formData.entries()) {
|
|
||||||
// // console.log(entry);
|
|
||||||
// // }
|
|
||||||
// axios
|
|
||||||
// .post(`/api/v1/blog/create`, formData, {
|
|
||||||
// headers: {
|
|
||||||
// Authorization: `Bearer ${token}`,
|
|
||||||
// "Content-Type": "multipart/form-data",
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// .then((res) => {
|
|
||||||
// swal({
|
|
||||||
// title: "Added",
|
|
||||||
// text: "Blog added successfully!",
|
|
||||||
// icon: "success",
|
|
||||||
// button: "ok",
|
|
||||||
// });
|
|
||||||
// setLoading(false);
|
|
||||||
// navigate("/blogs");
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err);
|
|
||||||
// setLoading(false);
|
|
||||||
// const message = err.response?.data?.message
|
|
||||||
// ? err.response?.data?.message
|
|
||||||
// : "Something went wrong!";
|
|
||||||
// swal({
|
|
||||||
// title: "Warning",
|
|
||||||
// text: message,
|
|
||||||
// icon: "error",
|
|
||||||
// button: "Retry",
|
|
||||||
// dangerMode: true,
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
// Check if any of the required fields are empty
|
// Check if any of the required fields are empty
|
||||||
if (!title || !image || !tag || !blogContent) {
|
if (!title || !image || !tag || !blogContent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user