+ console.log(query);
+ const theblog = document.querySelector(".card--wrapper");
+ query.forEach(element => {
+ const queryElement= document.createElement("div");
+ queryElement.innerHTML = `
+
+
+
${element.content}
+
+
${element.author} / ${element.email}
- `;
+
+
+
+ `;
+ theblog.appendChild(queryElement);
+ });
+ // console.log(theblog);
+
})
.catch((error) => console.error("Error fetching blog details:", error));
diff --git a/js/script.js b/js/script.js
index 25b35ab..718f903 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,161 +1,179 @@
-const openMenu=document.querySelector('.openmenu');
-const menu=document.querySelector('.menu');
-const Fname=document.querySelector('#Fname');
-const contact=document.querySelector('.contact');
-const Email=document.querySelector('.Email');
-const textarea=document.querySelector('#textarea');
-const blogs=document.querySelector('.blogs');
-const nameError=document.querySelector('#nameError');
-const messageError=document.querySelector('#messageError');
-const contactus=document.querySelector('#contactus');
-const login=document.querySelector('#login');
-const logName=document.querySelector("#logName");
-const logNameErrors=document.querySelector("#logNameErrors");
-const logpassword=document.querySelector("#logpassword");
-const logpasswordErrors=document.querySelector("#logpasswordErrors");
-const blogcontainer=document.querySelector('.blog-container');
-
-
-
-
-openMenu.addEventListener('click',()=>{
- menu.classList.toggle('show')
-})
-
-
-contactus.addEventListener('submit',(e)=>{
- e.preventDefault();
- if(Fname.value.trim()===""){
-
- nameError.innerHTML='please enter the name!';
- }
-
- else if(Fname.value.length<3){
-
- nameError.innerHTML="name should have 3 character and over";
- }
- else{
- nameError.innerHTML="";
- }
-
- if(textarea.value.trim()===""){
- messageError.innerHTML='please enter the message!';
- }else if (textarea.value.length < 10) {
- messageError.innerHTML = "your message should be atleast 10 characters";
- } else {
- messageError.innerHTML = "";
- alert("sent")
- window.location.href = "./index.html";
- }
-
-
-
+const openMenu = document.querySelector(".openmenu");
+const menu = document.querySelector(".menu");
+const Fname = document.querySelector("#Fname");
+const contact = document.querySelector(".contact");
+const Email = document.querySelector(".Email");
+const textarea = document.querySelector("#textarea");
+const blogs = document.querySelector(".blogs");
+const nameError = document.querySelector("#nameError");
+const messageError = document.querySelector("#messageError");
+const contactus = document.querySelector("#contactus");
+const login = document.querySelector("#login");
+const logName = document.querySelector("#logName");
+const logNameErrors = document.querySelector("#logNameErrors");
+const logpassword = document.querySelector("#logpassword");
+const logpasswordErrors = document.querySelector("#logpasswordErrors");
+const blogcontainer = document.querySelector(".blog-container");
+
+openMenu.addEventListener("click", () => {
+ menu.classList.toggle("show");
});
-Fname.value==='';
-textarea.value==='';
+contactus.addEventListener("submit", (e) => {
+ e.preventDefault();
+
+ var Qname = Fname.value.trim();
+ var Qtext = textarea.value.trim();
+ var Qemail = Email.value.trim();
+
+ if (Qname === "") {
+ nameError.innerHTML = "please enter the name!";
+ } else if (Fname.value.length < 3) {
+ nameError.innerHTML = "name should have 3 character and over";
+ } else {
+ nameError.innerHTML = "";
+ }
+ if (Qemail === "") {
+ messageError.innerHTML = "please enter the name!";
+ } else {
+ messageError.innerHTML = "";
+ }
+
+ if (Qtext === "") {
+ messageError.innerHTML = "please enter the message!";
+ } else if (textarea.value.length < 10) {
+ messageError.innerHTML = "your message should be atleast 10 characters";
+ } else {
+ messageError.innerHTML = "";
+ alert("sent");
+ window.location.href = "./index.html";
+ }
+
+ var Qname = Fname.value.trim();
+ var Qtext = textarea.value.trim();
+ var Qemail = Email.value.trim();
+
+ const data = {
+ author: Qname,
+ email: Qemail,
+ content: Qtext,
+ };
+ console.log(data);
+ function createQueries(data) {
+ // const link = "https://rwemaremy-my-brand-back-end.onrender.com";
+ fetch(`https://rwemaremy-my-brand-back-end.onrender.com/api/queries`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ })
+ .then((response) => {
+ if (response.ok) {
+ console.log("Query created successfully");
+ } else {
+ console.error("creating a query failed");
+ }
+ })
+ .catch((error) => {
+ console.error("Error:", error);
+ });
+ }
+ createQueries(data);
-function validate(){
-if(Fname.value===""){
-nameError.innerHTML='please enter the name!';
-}
-if (textarea.value ==="") {
-
- return false;
-}
-else{
- alert("your message is sent!!!")
- true;
-}
-}
+});
-function emailvalid(){
- var form=document.getElementById("form");
- var email=document.getElementById("emails").value;
- var text=document.getElementById("errors");
-
-var pattern=/^[^ ]+@[^ ]+\.[a-z]{1,3}$/;
-if(email.match(pattern))
-{
-form.classList.add("valid");
-form.classList.remove("invalid");
-text.innerHTML="";
-text.style.color="#00ff00";
+Fname.value === "";
+textarea.value === "";
+
+function validate() {
+ if (Fname.value === "") {
+ nameError.innerHTML = "please enter the name!";
+ }
+ if (textarea.value === "") {
+ return false;
+ } else {
+ alert("your message is sent!!!");
+ true;
+ }
}
-else{
- form.classList.remove("valid");
- form.classList.add("invalid");
- text.innerHTML="Please enter a valid email";
-text.style.color="#ff0000";
-}
+function emailvalid() {
+ var form = document.getElementById("form");
+ var email = document.getElementById("emails").value;
+ var text = document.getElementById("errors");
+
+ var pattern = /^[^ ]+@[^ ]+\.[a-z]{1,3}$/;
+ if (email.match(pattern)) {
+ form.classList.add("valid");
+ form.classList.remove("invalid");
+ text.innerHTML = "";
+ text.style.color = "#00ff00";
+ } else {
+ form.classList.remove("valid");
+ form.classList.add("invalid");
+ text.innerHTML = "Please enter a valid email";
+ text.style.color = "#ff0000";
+ }
}
-function fnamevalid(){
- var form=document.getElementById("form");
- var email=document.getElementById("Fname").value;
- var text=document.getElementById("nameError");
-
-var pattern = /^[a-z]{3,}$/;
-if(email.match(pattern))
-{
-form.classList.add("valid");
-form.classList.remove("invalid");
-text.innerHTML="";
-text.style.color="#00ff00";
+function fnamevalid() {
+ var form = document.getElementById("form");
+ var email = document.getElementById("Fname").value;
+ var text = document.getElementById("nameError");
+
+ var pattern = /^[a-z]{3,}$/;
+ if (email.match(pattern)) {
+ form.classList.add("valid");
+ form.classList.remove("invalid");
+ text.innerHTML = "";
+ text.style.color = "#00ff00";
+ } else {
+ form.classList.remove("valid");
+ form.classList.add("invalid");
+ text.innerHTML = "ooops fix your name";
+ text.style.color = "#ff0000";
+ }
}
-else{
- form.classList.remove("valid");
- form.classList.add("invalid");
- text.innerHTML="ooops fix your name";
-text.style.color="#ff0000";
+function messagevalid() {
+ var form = document.getElementById("form");
+ var email = document.getElementById("textarea").value;
+ var text = document.getElementById("messageError");
+
+ var pattern = /^[a-zA-Z\s\S]{10,}$/;
+ if (email.match(pattern)) {
+ form.classList.add("valid");
+ form.classList.remove("invalid");
+ text.innerHTML = "";
+ text.style.color = "#00ff00";
+ } else {
+ form.classList.remove("valid");
+ form.classList.add("invalid");
+ text.innerHTML = "your text it has to be over 10 chacters";
+ text.style.color = "#ff0000";
+ }
}
-}
-
-
-function messagevalid(){
- var form=document.getElementById("form");
- var email=document.getElementById("textarea").value;
- var text=document.getElementById("messageError");
+ //slider------------------------------------------
+ var hoovered = false;
-var pattern = /^[a-zA-Z\s\S]{10,}$/;
-if(email.match(pattern))
-{
-form.classList.add("valid");
-form.classList.remove("invalid");
-text.innerHTML="";
-text.style.color="#00ff00";
-}
-else{
-
- form.classList.remove("valid");
- form.classList.add("invalid");
- text.innerHTML="your text it has to be over 10 chacters";
-text.style.color="#ff0000";
-}
-}
-//slider------------------------------------------
-var hoovered=false;
-
-const scroll=()=>{
- if (blogs.scrollLeft + blogs.clientWidth >= blogs.scrollWidth) {
+ const scroll = () => {
+ if (blogs.scrollLeft + blogs.clientWidth >= blogs.scrollWidth) {
blogs.scrollLeft = 0;
}
-if(!hoovered){
- blogs.scrollLeft+=100;
-}else{
- blogs.scrollLeft-=100;
-}
-}
-setInterval(scroll,70);
+ if (!hoovered) {
+ blogs.scrollLeft += 100;
+ } else {
+ blogs.scrollLeft -= 100;
+ }
+ };
+ setInterval(scroll, 70);
// blogcontainer.addEventListener("mouseenter", ()=>{
-
+
// hoovered=true;
// });
// blogcontainer.addEventListener("mouseenter", ()=>{
// hoovered=false;
// });
-
diff --git a/js/single-blog.js b/js/single-blog.js
index 3434e9f..4cf235b 100644
--- a/js/single-blog.js
+++ b/js/single-blog.js
@@ -1,7 +1,10 @@
const currentUrl = new URL(window.location.href);
+const Names = document.querySelector(".name");
+const email = document.querySelector(".email");
+const content = document.querySelector(".message");
const searchParams = new URLSearchParams(currentUrl.search);
const blogId = searchParams.get("id");
-console.log(blogId);
+
const allblog = "https://rwemaremy-my-brand-back-end.onrender.com";
const theblog = document.querySelector(".wrapper");
@@ -15,23 +18,53 @@ fetch(allblog + `/api/blogs/${blogId}`)
${give.content}
-
-
${give.likes}
+
+
${give.likes}
-
-
`;
+ const allblog = "https://rwemaremy-my-brand-back-end.onrender.com";
+ theblog.addEventListener("click", function (event) {
+ const target = event.target;
+ if (target.classList.contains("likes-btn")) {
+ const blogId = searchParams.get("id");
+ fetch(
+ `https://rwemaremy-my-brand-back-end.onrender.com/api/blogs/${blogId}/likes`,
+ {
+ method: "POST",
+ }
+ );
+ const singleDisplay = document.getElementById("single-display");
+ let count = 0;
+ if (singleDisplay) {
+ singleDisplay.textContent = theblog.blog.likes.toString();
+ count++;
+ location.reload();
+ localStorage.setItem("count", `${count}`);
+ }
+ }
+ });
+
+ theblog.addEventListener("click", function (event) {
+ const target = event.target;
+ if (target.classList.contains("comment")) {
+ // window.location.href = "#comment-box";
+ console.log("clicked");
+ }
+ });
// Fetch comments
- fetch(allblog + `/api/blogs/${blogId}/comments`)
+ const id = searchParams.get("id");
+ fetch(allblog + `/api/blogs/${id}/comments`)
.then((res) => res.json())
.then((comments) => {
const commentBox = document.getElementById("comment-box");
@@ -42,18 +75,48 @@ fetch(allblog + `/api/blogs/${blogId}`)
-
`;
commentBox.appendChild(commentElement);
});
})
.catch((error) => console.error("Error fetching comments:", error));
+
+ const data = {
+ name: Names,
+ email: email,
+ content: content,
+ };
+
+ function postComment(blogId, data) {
+ // Assuming you're using fetch for API calls
+ fetch(
+ `https://rwemaremy-my-brand-back-end.onrender.com/api/blogs/${blogId}/comments`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ }
+ )
+ .then((response) => {
+ if (response.ok) {
+ // Comment created successfully
+ console.log("Comment created successfully");
+ } else {
+ // Failed to create comment
+ console.error("Failed to create comment");
+ }
+ })
+ .catch((error) => {
+ console.error("Error:", error);
+ });
+ }
+
+ // Replace '123' with the actual ID of the blog post
})
- .catch((error) => console.error("Error fetching blog:", error));
+ .catch((error) => console.error("Error fetching blog:", error));
diff --git a/queries.html b/queries.html
index 3e710ad..d10a0fd 100644
--- a/queries.html
+++ b/queries.html
@@ -91,11 +91,11 @@
QUERRIES
-
+
-
+