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

(feat) Notification bell doesn't show notifications #993

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion zubhub_frontend/zubhub/src/components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function PageWrapper(props) {
<div className={classes.navActionStyle}>
<SearchOutlined onClick={toggleSearchBar} className={classes.addOn894} />

<NotificationButton />
<NotificationButton {...props}/>
<Hidden smDown>
{props.auth.username && (
<Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
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 (
<ClickAwayListener onClickAway={() => setDropdownOpen(false)}>
<div>
<div
onClick={() => setDropdownOpen(!dropdownOpen)}
ref={buttonRef}
className={clsx(classes.notification, commonClasses.iconBox)}
style={{ cursor: 'pointer' }}
style={{ position: 'relative', cursor: 'pointer' }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you help move this to notificationButtonStyles.js?

>
<Notifications style={{ color: colors.primary, fontSize: 20 }} />
{
unreadNotifications?.length > 0 && (
<span className={classes.spanNumber}>
{unreadNotifications.length > 9 ? '9+' : unreadNotifications?.length}
</span>
)
}
<Notifications style={{ color: colors.primary, fontSize: 24 }} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

this too. move to notification style file

</div>
<NotificationPanel
open={dropdownOpen}
Expand Down
Loading