2121 'mt-10': true,
2222 'z-50': true,
2323 'rounded-md': true}" >
24- <div v-bind:class =" {
24+ <div
25+ v-bind:class =" {
2526 'word-break': true,
2627 'border-b': true,
27- 'font-bold': notification.is_seen,}"
28+ 'font-bold': ! notification.is_seen,}"
2829 v-for =" notification in notifications" :key =" notification.id" >
2930 <router-link
3031 v-bind:to =" notification.link_to"
3334 <h1 class =" ml-4" >{{notification.content}}</h1 >
3435 </router-link >
3536 </div >
37+ <h1 v-if =" !notifications.length" class =" py-4 flex items-center" >No notifications</h1 >
3638 </div >
3739 </div >
3840</template >
@@ -46,22 +48,24 @@ import match from '../../assets/linkBlack.png';
4648
4749/* eslint-disable object-curly-newline */
4850/* eslint-disable consistent-return */
51+ /* eslint-disable max-len */
4952
5053export default {
5154 data : () => ({
5255 notify: true ,
53- notifications: [
54- { content: ' Samantha liked you' , is_seen: false , type: ' like' , id: 1 , link_to: ' google.com' },
55- { content: ' Bae liked you' , id: 2 , is_seen: false , type: ' dislike' , link_to: ' google.com' },
56- { content: ' Samantha liked you' , id: 3 , is_seen: false , type: ' message' , link_to: ' google.com' },
57- { content: ' Bae liked you' , id: 4 , is_seen: false , type: ' match' , link_to: ' google.com' },
58- { content: ' Samantha liked you' , id: 5 , is_seen: true , type: ' view' , link_to: ' google.com' },
59- { content: ' Bae liked you' , id: 6 , is_seen: true , type: ' like' , link_to: ' google.com' },
60- { content: ' Samantha liked you' , id: 7 , is_seen: true , type: ' like' , link_to: ' google.com' },
61- { content: ' Bae liked you' , id: 8 , is_seen: true , type: ' like' , link_to: ' google.com' },
62- { content: ' Samantha liked you' , id: 9 , is_seen: true , type: ' like' , link_to: ' google.com' },
63- { content: ' Bae liked youBae liked youBae liked youBae liked youBae liked youBae liked you' , id: 10 , is_seen: true , type: ' like' , link_to: ' google.com' },
64- ],
56+ // notifications: [
57+ // { content: 'Samantha liked you', is_seen: false, type: 'like', id: 1, link_to: 'google.com' },
58+ // { content: 'Bae liked you', id: 2, is_seen: false, type: 'dislike', link_to: 'google.com' },
59+ // { content: 'Samantha liked you', id: 3, is_seen: false, type: 'message', link_to: 'google.com' },
60+ // { content: 'Bae liked you', id: 4, is_seen: false, type: 'match', link_to: 'google.com' },
61+ // { content: 'Samantha liked you', id: 5, is_seen: true, type: 'view', link_to: 'google.com' },
62+ // { content: 'Bae liked you', id: 6, is_seen: true, type: 'like', link_to: 'google.com' },
63+ // { content: 'Samantha liked you', id: 7, is_seen: true, type: 'like', link_to: 'google.com' },
64+ // { content: 'Bae liked you', id: 8, is_seen: true, type: 'like', link_to: 'google.com' },
65+ // { content: 'Samantha liked you', id: 9, is_seen: true, type: 'like', link_to: 'google.com' },
66+ // { content: 'Bae liked youBae liked youBae liked youBae liked youBae liked youBae liked you', id: 10, is_seen: true, type: 'like', link_to: 'google.com' },
67+ // ],
68+ notifications: [],
6569 showNotifications: false ,
6670 }),
6771 methods: {
@@ -91,6 +95,32 @@ export default {
9195 return message;
9296 }
9397 },
98+ async fetchNotifications () {
99+ const notificationsRequest = await this .$http .get (' /notifications' );
100+ this .notifications = notificationsRequest .data .notifications ;
101+ },
102+ async newNotificationCheck () {
103+ const notificationsRequest = await this .$http .get (' /notifications/unread' );
104+ const { notifications } = notificationsRequest .data ;
105+ this .notify = notifications .length ;
106+ },
107+ async fetchNewNotifications () {
108+ const notificationsRequest = await this .$http .get (' /notifications/unread' );
109+ const { notifications } = notificationsRequest .data ;
110+ const count = notifications .length ;
111+ if (! count) {
112+ return ;
113+ }
114+ for (let i = 0 ; i < count; i += 1 ) {
115+ this .notifications .unshift (notifications[i]);
116+ }
117+ this .notify = true ;
118+ },
119+ },
120+ async beforeMount () {
121+ await this .fetchNotifications ();
122+ await this .newNotificationCheck ();
123+ await this .fetchNewNotifications ();
94124 },
95125};
96126 </script >
0 commit comments