@@ -4,8 +4,9 @@ import useLocalToken from 'hooks/useLocalToken';
44import { useEffect , useState } from 'react' ;
55import { Link } from 'react-router-dom' ;
66import styled from '@emotion/styled' ;
7- import { useUserContext } from 'contexts/UserContext' ;
87import theme from 'styles/theme' ;
8+ import displayedAt from 'utils/functions/displayedAt' ;
9+ import { setNotificationSeen } from 'utils/apis/postApi' ;
910
1011const NotificationsWrapper = styled . div `
1112 background-color: ${ theme . color . backgroundLight } ;
@@ -17,7 +18,6 @@ const NotificationsWrapper = styled.div`
1718const NotificationPage = ( ) => {
1819 const [ token ] = useLocalToken ( ) ;
1920 const [ notifications , setNotifications ] = useState ( [ ] ) ;
20- const { currentUser } = useUserContext ( ) ;
2121 useEffect ( ( ) => {
2222 const initNotifications = async ( ) => {
2323 const fetchedNotifications = await getNotifications ( token ) ;
@@ -44,23 +44,19 @@ const NotificationPage = () => {
4444 ) ;
4545 } ;
4646 initNotifications ( ) ;
47+ return ( ) => {
48+ const readNotifications = async ( ) => {
49+ setNotificationSeen ( token ) ;
50+ } ;
51+ readNotifications ( ) ;
52+ } ;
4753 } , [ ] ) ;
4854 return (
4955 < >
5056 < PageWrapper title = "알림" header prev >
5157 < NotificationsWrapper >
5258 { notifications . map (
53- ( {
54- notificationId,
55- postId,
56- fullName,
57- message,
58- userId,
59- authorId,
60- isSeen,
61- img,
62- createdAt,
63- } ) =>
59+ ( { notificationId, postId, fullName, message, authorId, isSeen, img, createdAt } ) =>
6460 message &&
6561 ( postId ? (
6662 < Link to = { `/post/detail/${ postId } ` } key = { notificationId } >
@@ -71,7 +67,9 @@ const NotificationPage = () => {
7167 message = { message }
7268 img = { img }
7369 createdAt = { createdAt }
74- > </ NotificationCard >
70+ >
71+ < span > { displayedAt ( createdAt ) } </ span >
72+ </ NotificationCard >
7573 </ Link >
7674 ) : (
7775 < Link to = { `/user/${ authorId } ` } key = { notificationId } >
@@ -82,7 +80,9 @@ const NotificationPage = () => {
8280 message = { message }
8381 img = { img }
8482 createdAt = { createdAt }
85- > </ NotificationCard >
83+ >
84+ < span > { displayedAt ( createdAt ) } </ span >
85+ </ NotificationCard >
8686 </ Link >
8787 ) ) ,
8888 ) }
0 commit comments