Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
RWEMAREMY committed Mar 8, 2024
1 parent 9d49d3f commit 6c04b0f
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 222 deletions.
21 changes: 10 additions & 11 deletions css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,19 @@ body {
display: flex;
font-weight: bolder;
}
.messagestitle{
.messagestitle {
color: hwb(0 13% 87%);
font-size: 15px;

margin-top: 10px;

border-radius: 10px;
height: 10px;
max-width: fit-content;
justify-content: center;
align-items: center;

font-weight: bolder;

}
.blogbtn {
display: flex;
Expand Down Expand Up @@ -368,13 +367,12 @@ button:hover {
height: 60%;
border-radius: 20px;
margin-top: 0;

}
.adminImgLikes{
.adminImgLikes {
width: 100%;
height: 35%;
border-radius: 20px;
margin-top: 0;
margin-top: 0;
}

/* .blog-wrapper img {
Expand Down Expand Up @@ -433,14 +431,15 @@ button:hover {
margin-left: -3%;
}
.queries1 {
background-color: rgba(207, 205, 204, 0.868);
background-color: rgba(236, 146, 101, 0.868);
width: 100%;
display: flex;
position: relative;
justify-content: center;
align-items: center;
margin-top: 20px;
padding: 10px 10px;
margin-top: 10px;
margin-bottom: 10px;
padding: 20px 100px;
border-radius: 10px;
margin-left: -3%;
}
Expand Down
1 change: 1 addition & 0 deletions js/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async function createBlog() {
body: formData,
});
if (!response.ok) {
window.location.href = "log-in.html";
throw new Error(response.statusText);
}
const data = await response.json();
Expand Down
98 changes: 56 additions & 42 deletions js/blogedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ fetch(url + "/api/blogs")
let result = addThreeDotsAfterLength(string, length);

function addThreeDotsAfterLength(string, length) {
return string.length > length ? string.slice(0, length) + "..." : string;
return string.length > length
? string.slice(0, length) + "..."
: string;
}

blogshtml += `
Expand All @@ -23,64 +25,76 @@ fetch(url + "/api/blogs")
<br>
<div class="blog-heart"><img class="adminImgLikes" src="./assets/heart.png">${blog.likes}</div>
</div>
<span class="delete-btn" id="delete"><i class="fa-solid fa-trash" style="color: #d11515;"></i></span>
<span class="update-blog" id="update" ><i class="fa-solid fa-arrows-rotate" style="color: black;"></i></span>
<span class="delete-btn" id="delete" key=${blog._id} ><i class="fa-solid fa-trash" style="color: #d11515;"></i></span>
<span class="update-blog" id="update" key=${blog._id}><i class="fa-solid fa-arrows-rotate" style="color: black;"></i></span>
</div>`;
});

container.innerHTML = blogshtml;

const blogger = document.querySelectorAll(".blog-container");
const blogger = document.querySelectorAll(".delete-btn");

blogger.forEach((blg) => {
blg.addEventListener("click", (e) => {
const clickedContainer = e.target.closest(".blog-container");
const clickedContainer = e.target.closest(".delete-btn");
if (clickedContainer) {
const id = clickedContainer.getAttribute("key");
deleteBlog(id);
// Use the id as needed
} else {
console.error("No blog container found in the clicked element chain.");
console.error(
"No blog container found in the clicked element chain."
);
}
});


const deleteButtons = document.querySelectorAll('.delete-btn');
deleteButtons.forEach(button => {
button.addEventListener('click', (e) => {
const blogId = button.getAttribute('key');



const deleteButtons = document.querySelectorAll(".delete-btn");
deleteButtons.forEach((button) => {
button.addEventListener("click", (e) => {
const blogId = button.getAttribute("key");
});
});
});
});
const token=localStorage.getItem("token");
const token = localStorage.getItem("token");

const deleteBlog = (blogId) => {
const url = "https://rwemaremy-my-brand-back-end.onrender.com";
fetch(url + `/api/blogs/${blogId}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${localStorage.getItem(token)}`,
},
}).then(response => {
if (response.ok) {
console.log("Blog deleted successfully");
} else {
console.error("Error deleting blog:", response.statusText);
}
}).catch(error => {
console.error("Error:", error);
});
};
const deleteBlog = (blogId) => {
const url = "https://rwemaremy-my-brand-back-end.onrender.com";
fetch(url + `/api/blogs/${blogId}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${localStorage.getItem(token)}`,
},
})
.then((response) => {
if (response.ok) {
console.log("Blog deleted successfully");
location.reload();
} else {
console.error("Error deleting blog:", response.statusText);
}
})
.catch((error) => {
console.error("Error:", error);
});
};

const editblog = document.querySelectorAll(".update-blog");
editblog.forEach((editbutton) => {
editbutton.addEventListener("click", (e) => {
const update = e.target.closest(".update-blog");
if (update) {
const id = update.getAttribute("key");
updateblog(id);
// Use the id as needed
}else{
console.error(
"No blog container found in the clicked element chain."
);
}
}

// Redirect to update page with id
);
});

const editblog = document.querySelectorAll(".update-blog");
editblog.forEach((editbutton) => {
editbutton.addEventListener("click", (e) => {
const id = e.target.getAttribute("key");
console.log(id);
// Redirect to update page with id
window.location.href = `./update.html?id=${id}`;
});
});
});
2 changes: 1 addition & 1 deletion js/blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ blogger.forEach((blg) => {
window.location.href = `./single-blog.html?id=${id}`;
});
});
console.log(blog);
// console.log(blog);
});
});

Expand Down
33 changes: 21 additions & 12 deletions js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ const currentUrl = new URL(window.location.href);
const searchParams = new URLSearchParams(currentUrl.search);
const blogId = searchParams.get("id");

const allblog = "https://rwemaremy-my-brand-back-end.onrender.com";
const url = "https://rwemaremy-my-brand-back-end.onrender.com";


const theblog = document.querySelector(".queries1");

// Fetch blog details
fetch(allblog + `/api/queries`)
fetch(url + `/api/queries`)
.then((res) => res.json())
.then((query) => {
theblog.innerHTML = `
<div class="cards">
<div class="queries1">
<h3>${query.author}</h3>
<h3>${query.email}</h3>
<p>${query.content}</p>
<h3>${query.date}</h3>
</div>
console.log(query);
const theblog = document.querySelector(".card--wrapper");
query.forEach(element => {
const queryElement= document.createElement("div");
queryElement.innerHTML = `
<div class="cards">
<div class="queries1">
<div> <p> ${element.content}</p> <br>
<div> <h3>${element.author} / ${element.email}</h3> </div>
</div>
`;
</div>
`;
theblog.appendChild(queryElement);
});
// console.log(theblog);

})
.catch((error) => console.error("Error fetching blog details:", error));
Loading

0 comments on commit 6c04b0f

Please sign in to comment.