From 1f9e50a641acc5f3a35dd168e2d1a9d0a702d45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sen=C3=A9cal?= Date: Thu, 24 Mar 2022 16:21:00 -0400 Subject: [PATCH] #51 - Added UI/Logic to View Notifications --- .../layout/NotificationsMenuItem.tsx | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/components/layout/NotificationsMenuItem.tsx diff --git a/src/components/layout/NotificationsMenuItem.tsx b/src/components/layout/NotificationsMenuItem.tsx new file mode 100644 index 00000000..5d639a68 --- /dev/null +++ b/src/components/layout/NotificationsMenuItem.tsx @@ -0,0 +1,86 @@ +// eslint-disable-next-line max-len +import { Dialog, DialogContent, DialogTitle, Badge, List, ListItem, ListItemIcon, ListItemText, Typography, useMediaQuery, useTheme } from '@mui/material'; +import React, { useEffect, useState } from 'react'; +import NotificationsNoneOutlinedIcon from '@mui/icons-material/NotificationsNoneOutlined'; +import { doc, onSnapshot } from 'firebase/firestore'; +import { UserContext } from '../../context/UserContext'; +import { firestore } from '../../config/firebase_config'; + +interface UserNotification { + title: string; + message: string; + date: Date; + read: boolean; +} + +function NotificationsMenuItem() { + const [open, setOpen] = React.useState(false); + const theme = useTheme(); + const fullScreen = useMediaQuery(theme.breakpoints.down('md')); + + const handleClickOpen = () => { + setOpen(true); + }; + + const handleClose = () => { + setOpen(false); + }; + const { state, update } = React.useContext(UserContext); + const [notifications, setNotifications] = useState([]); + + useEffect(() => { + onSnapshot(doc(firestore, 'users', `${state.id}`), (docu) => { + const data = docu.data(); + if (data && data.notifications) { + setNotifications(data.notifications); + } + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( + <> + + + + + + + + + + + + + + {notifications?.length === 0 && ( + + + + )} + + {notifications?.map((notification) => ( + + + + ))} + + + + + + + ); +} + +export default NotificationsMenuItem;