Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime Notification option on home page #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ul id="navbar">
<li title="Login"><a href="choose-file.html">Login</a></li>
<li title="Register" style="border-bottom: 2px solid white;border-radius: 9px;"><a href="./signup.html">Register</a></li>
<li title="notifications"><a href="notification.html"> Notifications</a></li>
<li title="Contact Us"><a href="./contact-us.html">Contact Us</a></li>
<li title="Our Services"><a href="#services">Services</a></li>
<li title="About Us"><a href="#about_show">About</a></li>
Expand Down Expand Up @@ -99,7 +100,7 @@ <h2>About Us</h2>
</div>
<div class="buttons">
<button id="prev">
<</button>
</button>
<button id="next">></button>
</div>
<ul class="dots">
Expand Down Expand Up @@ -458,7 +459,7 @@ <h4 id="custom-follow-heading">Follow Us</h4>
<button id="scrollToTop" title="Go to top" style="display: none;">
<i class="fa-solid fa-arrow-up"></i>
</button>

<script src="notification.js"></script>
<script src="script/script.js"></script>
<script src="script/slider.js"></script>
</body>
Expand Down
18 changes: 18 additions & 0 deletions public/notification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Real-Time Notifications</title>
<link rel="stylesheet" href="notify.css"> <!-- Link to CSS file -->
</head>
<body>
<div class="notification-container">
<h2>Notifications</h2>
<div id="notifications"></div>
<button id="clear-notifications">Clear Notifications</button>
</div>

<script src="notify.js"></script> <!-- Link to JavaScript file -->
</body>
</html>
55 changes: 55 additions & 0 deletions public/notify.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
body {
font-family: Arial, sans-serif;
background-color: #d4edda; /* Light green background color */
margin: 0;
padding: 20px;
}

.notification-container {
max-width: 600px;
margin: auto;
background: #fff; /* White background for notification box */
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
}

h2 {
text-align: center;
}

.notification {
padding: 10px;
border-bottom: 1px solid #e0e0e0;
position: relative;
}

.notification:last-child {
border-bottom: none;
}

.notification p {
margin: 0;
}

.notification-time {
font-size: 0.8em;
color: #999;
position: absolute;
right: 10px;
top: 10px;
}

button {
margin-top: 20px;
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}
32 changes: 32 additions & 0 deletions public/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// script.js

// Sample notification data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes made is possibly good but the notification data(message) are fetched from the node server, we will add this functionality, just remove the sample notification data we will change the logic of displayNotification function from the API endpoint. But yah if you want to change this logic to fetch the the notifications from our node server you can work on it

const notifications = [
{ message: "New research paper on AI published.", time: new Date().toLocaleTimeString() },
{ message: "New comment on your research article.", time: new Date().toLocaleTimeString() },
{ message: "Your research submission has been reviewed.", time: new Date().toLocaleTimeString() }
];

// Function to display notifications
function displayNotification(notification) {
const notificationsContainer = document.getElementById('notifications');
const notificationDiv = document.createElement('div');
notificationDiv.classList.add('notification');
notificationDiv.innerHTML = `
<p>${notification.message}</p>
<span class="notification-time">${notification.time}</span>
`;
notificationsContainer.prepend(notificationDiv); // Add new notifications to the top
}

// Simulate receiving notifications every 5 seconds
setInterval(() => {
const randomIndex = Math.floor(Math.random() * notifications.length);
displayNotification(notifications[randomIndex]);
}, 5000);

// Clear notifications
document.getElementById('clear-notifications').addEventListener('click', () => {
const notificationsContainer = document.getElementById('notifications');
notificationsContainer.innerHTML = ''; // Clear all notifications
});