Skip to content

Commit

Permalink
Email
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSharma72 committed Oct 11, 2024
1 parent 09bbf11 commit fe17381
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 70 deletions.
4 changes: 2 additions & 2 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const app = express();

const emailRouter = require("./router/EmailRoute.js");
const authRouter = require('./router/authRoute.js');
const databaseconnect = require('./config/databaseConfig.js');
const cookieParser = require('cookie-parser');
Expand All @@ -16,7 +16,7 @@ app.use(cors({ origin: [process.env.CLIENT_URL], credentials: true })); //Third-

// Auth router
app.use('/auth', authRouter);

app.use("/email", emailRouter);
app.use('/', (req, res) => {
res.status(200).json({ data: 'JWTauth server ;)' });
});
Expand Down
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"email-validator": "^2.0.4",
"nodemailer": "^6.9.15",
"express": "^4.21.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.0",
Expand Down
8 changes: 8 additions & 0 deletions backend/router/EmailRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require("express");
const emailRouter = express.Router();

const { SendEmailController } = require("../controller/EmailController");

emailRouter.post("/SendEmail", SendEmailController);

module.exports = emailRouter;
165 changes: 97 additions & 68 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,125 @@ var menuList = document.getElementById("menuList");
menuList.style.maxHeight = "0px";

function toggleMenu() {
if (menuList.style.maxHeight == "0px") {
menuList.style.maxHeight = "160px";
} else {
menuList.style.maxHeight = "0px";
}
}
window.onscroll = function() {
updateProgressBar();
};


function updateProgressBar() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scrollPercent = (scrollTop / scrollHeight) * 100;

document.getElementById("progressBar").style.width = scrollPercent + "%";
if (menuList.style.maxHeight == "0px") {
menuList.style.maxHeight = "160px";
} else {
menuList.style.maxHeight = "0px";
}

document.addEventListener('DOMContentLoaded', () => {
console.log("Website loaded successfully!");
}
window.onscroll = function () {
updateProgressBar();
};

function updateProgressBar() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
var scrollPercent = (scrollTop / scrollHeight) * 100;

document.getElementById("progressBar").style.width = scrollPercent + "%";
}

document.addEventListener("DOMContentLoaded", () => {
console.log("Website loaded successfully!");
});

// Show or hide the scroll-top button based on scroll position
window.addEventListener('scroll', function() {
const scrollTopButton = document.querySelector('.scroll-top');
if (window.pageYOffset > 300) {
scrollTopButton.style.display = 'block';
} else {
scrollTopButton.style.display = 'none';
}
window.addEventListener("scroll", function () {
const scrollTopButton = document.querySelector(".scroll-top");
if (window.pageYOffset > 300) {
scrollTopButton.style.display = "block";
} else {
scrollTopButton.style.display = "none";
}
});

// Smooth scroll to top when the button is clicked
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
window.scrollTo({
top: 0,
behavior: "smooth",
});
}

function toggleTheme() {
const body = document.body;
const themeToggle = document.getElementById('theme-toggle');
body.classList.toggle('dark-mode', themeToggle.checked);
const body = document.body;
const themeToggle = document.getElementById("theme-toggle");
body.classList.toggle("dark-mode", themeToggle.checked);

// Save the user's preference in localStorage
if (themeToggle.checked) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
// Save the user's preference in localStorage
if (themeToggle.checked) {
localStorage.setItem("theme", "dark");
} else {
localStorage.setItem("theme", "light");
}
}

// Load theme from localStorage on page load
window.onload = () => {
const savedTheme = localStorage.getItem('theme');
const themeToggle = document.getElementById('theme-toggle');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
themeToggle.checked = true;
}
const savedTheme = localStorage.getItem("theme");
const themeToggle = document.getElementById("theme-toggle");
if (savedTheme === "dark") {
document.body.classList.add("dark-mode");
themeToggle.checked = true;
}
};

//function to remove sidebar upon clicking close button
function toggleSidebar() {
var sidebar = document.getElementById("SideBar");
var sidebarContent = document.getElementById("sidebar-content");
if (sidebar) {
// Remove the sidebar element and its content
sidebar.remove();
sidebarContent.remove();
var sidebar = document.getElementById("SideBar");
var sidebarContent = document.getElementById("sidebar-content");
if (sidebar) {
// Remove the sidebar element and its content
sidebar.remove();
sidebarContent.remove();
} else {
console.error("Sidebar element not found");
}
}

function performSearch() {
let searchTerm = document.getElementById("search-input").value.toLowerCase();
console.log(searchTerm);
let cards = document.querySelectorAll(".row");

cards.forEach(function (card) {
let cardHeading = card
.querySelector(".card-heading")
.innerText.toLowerCase();

// Check if the search term is in the card heading or description
if (cardHeading.includes(searchTerm)) {
card.style.display = "block"; // Show the card
} else {
console.error("Sidebar element not found");
card.style.display = "none"; // Hide the card
}
};
});
}

function performSearch(){
let searchTerm = document.getElementById('search-input').value.toLowerCase();
console.log(searchTerm);
let cards = document.querySelectorAll('.row');

cards.forEach(function (card) {
let cardHeading = card.querySelector('.card-heading').innerText.toLowerCase();

// Check if the search term is in the card heading or description
if (cardHeading.includes(searchTerm)) {
card.style.display = "block"; // Show the card
} else {
card.style.display = "none"; // Hide the card
}
async function SendEmail(e) {
e.preventDefault();
const Name = document.getElementById("name").value;
const Email = document.getElementById("email").value;
const Message = document.getElementById("message").value;

try {
const response = await fetch("http://localhost:5000/email/SendEmail", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ Name, Email, Message }),
});

if (response.ok) {
alert("Email sent successfully!");
} else {
alert("Error sending email");
}
} catch (error) {
console.error("Error:", error);
alert("An error occurred while sending the email.");
}
}

0 comments on commit fe17381

Please sign in to comment.