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

Create NotificationBell.jsx #505

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
45 changes: 45 additions & 0 deletions src/components/NotificationBell.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// src/components/NotificationBell.jsx
import React, { useState } from 'react';
import './NotificationBell.css'; // Optional: for styling
const NotificationBell = () => {
const [notifications, setNotifications] = useState([
{ id: 1, text: 'New comment on your post' },
{ id: 2, text: 'New follower' },
]);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const handleBellClick = () => {
setIsDropdownOpen(!isDropdownOpen);
};
const handleNotificationClick = (id) => {
// Handle notification click (e.g., mark as read, navigate to detail page)
console.log(`Notification ${id} clicked`);
};
return (
<div className="notification-bell">
<button className="bell-icon" onClick={handleBellClick}>
<span className="bell">&#128276;</span> {/* Bell icon */}
{notifications.length > 0 && (
<span className="notification-count">{notifications.length}</span>
)}
</button>
{isDropdownOpen && (
<div className="dropdown-menu">
{notifications.length === 0 ? (
<div className="no-notifications">No notifications</div>
) : (
notifications.map((notification) => (
<div
key={notification.id}
className="notification-item"
onClick={() => handleNotificationClick(notification.id)}
>
{notification.text}
</div>
))
)}
</div>
)}
</div>
);
};
export default NotificationBell;
Loading