Skip to content

Commit

Permalink
some
Browse files Browse the repository at this point in the history
  • Loading branch information
RWEMAREMY committed Mar 11, 2024
1 parent 358e379 commit cbd3af1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ <h2 class="main--title">Dashboard</h2>
</div>

<script src="./js/connect.js"></script>
<script src="./js/dashboard_restriction.js"></script>

</body>

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ <h1>I'm ready to Talk.....</h1>

</div>

</div>
</div><br>
<footer>Made with ❤️ by M.Rwema Remy</footer>


Expand Down
12 changes: 12 additions & 0 deletions js/dashboard_restriction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function checkAuthentication() {
const token = localStorage.getItem("token");
if (!token) {
// Redirect to login page if token is not present
window.location.href = "/log-in.html";
}
}

// Call checkAuthentication when the dashboard page loads
window.addEventListener("DOMContentLoaded", () => {
checkAuthentication();
});
53 changes: 50 additions & 3 deletions js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ fetch(`https://rwemaremy-my-brand-back-end.onrender.com/api/queries`)
.then((query) => {
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 class="queries1" key=${element._id} >
<div> <p> ${element.content}</p> <br>
<div> <h3>${element.author} / ${element.email}</h3> </div>
<span class="delete-btn" id="delete" ><i class="fa-solid fa-trash"
<span class="delete-btn" id="delete" key=${element._id}><i class="fa-solid fa-trash"
style="color: #d11515;"></i></span>
</div>
Expand All @@ -30,9 +32,54 @@ fetch(`https://rwemaremy-my-brand-back-end.onrender.com/api/queries`)
theblog.appendChild(queryElement);
});

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

blogger.forEach((blg) => {
blg.addEventListener("click", (e) => {
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."
);
}
});

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

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

function checkAuthentication() {
const token = localStorage.getItem("token");
Expand Down

0 comments on commit cbd3af1

Please sign in to comment.