diff --git a/zubhub_frontend/zubhub/src/assets/js/styles/components/notification_button/notificationButtonStyles.js b/zubhub_frontend/zubhub/src/assets/js/styles/components/notification_button/notificationButtonStyles.js
index 6513696bb..4bfa90ded 100644
--- a/zubhub_frontend/zubhub/src/assets/js/styles/components/notification_button/notificationButtonStyles.js
+++ b/zubhub_frontend/zubhub/src/assets/js/styles/components/notification_button/notificationButtonStyles.js
@@ -7,6 +7,19 @@ const styles = theme => ({
notification: {
backgroundColor: colors["primary-01"],
},
+ spanNumber: {
+ textAlign: 'center',
+ position: 'absolute',
+ width: '15px',
+ height: '15px',
+ top: '3px',
+ left: '16px',
+ borderRadius: '999px',
+ fontSize: '10px',
+ fontWeight: '600',
+ backgroundColor: '#F4DB57',
+ color: '#000000'
+ }
});
export default styles;
diff --git a/zubhub_frontend/zubhub/src/components/Navbar/Navbar.jsx b/zubhub_frontend/zubhub/src/components/Navbar/Navbar.jsx
index f4b3d1b7a..65f95fc35 100644
--- a/zubhub_frontend/zubhub/src/components/Navbar/Navbar.jsx
+++ b/zubhub_frontend/zubhub/src/components/Navbar/Navbar.jsx
@@ -336,7 +336,7 @@ function PageWrapper(props) {
-
+
{props.auth.username && (
diff --git a/zubhub_frontend/zubhub/src/components/notification_button/NotificationButton.jsx b/zubhub_frontend/zubhub/src/components/notification_button/NotificationButton.jsx
index e6fee9a13..f6428a3b2 100644
--- a/zubhub_frontend/zubhub/src/components/notification_button/NotificationButton.jsx
+++ b/zubhub_frontend/zubhub/src/components/notification_button/NotificationButton.jsx
@@ -1,22 +1,45 @@
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
-import React, { useRef, useState } from 'react';
+import React, { useRef, useState, useEffect, useMemo } from 'react';
import styles from '../../assets/js/styles/components/notification_button/notificationButtonStyles';
import commonStyles from '../../assets/js/styles/index';
import NotificationPanel from '../notification_panel/NotificationPanel';
import { makeStyles } from '@material-ui/core/styles';
import { Notifications } from '@material-ui/icons';
+import API from '../../api/api'
import clsx from 'clsx';
import { colors } from '../../assets/js/colors';
import HamburgerMenu from '../hamburger_menu/HamburgerMenu';
const useStyles = makeStyles(styles);
-const NotificationButton = ({ className, notif }) => {
+const notificationSort = (a, b) => {
+ return new Date(b.date) - new Date(a.date);
+};
+
+const NotificationButton = ({ className, notif, auth }) => {
const classes = useStyles();
const commonClasses = makeStyles(commonStyles)();
const [dropdownOpen, setDropdownOpen] = useState(false);
+ const [notifications, setNotifications] = useState([]);
const buttonRef = useRef();
+ const unreadNotifications = useMemo(
+ () =>
+ Object.values(notifications)
+ .sort(notificationSort)
+ .filter(notification => !notification.viewed),
+ [notifications],
+ );
+
+ useEffect(() => {
+ async function fetchData() {
+ const api = new API();
+ const notifications = await api.getNotifications(1, auth.token);
+ setNotifications(notifications.results)
+ }
+ fetchData()
+ }, [auth.token])
+
return (
setDropdownOpen(false)}>
@@ -24,9 +47,16 @@ const NotificationButton = ({ className, notif }) => {
onClick={() => setDropdownOpen(!dropdownOpen)}
ref={buttonRef}
className={clsx(classes.notification, commonClasses.iconBox)}
- style={{ cursor: 'pointer' }}
+ style={{ position: 'relative', cursor: 'pointer' }}
>
-
+ {
+ unreadNotifications?.length > 0 && (
+
+ {unreadNotifications.length > 9 ? '9+' : unreadNotifications?.length}
+
+ )
+ }
+