@@ -40,26 +40,13 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
40
40
notifications,
41
41
} = useContext ( AppContext ) ;
42
42
43
- const setNotificationAsOpaque = ( ) => {
44
- if ( notification . unread ) {
45
- const notificationRow = document . getElementById ( notification . id ) ;
46
- notificationRow . className += Constants . READ_CLASS_NAME ;
47
- }
48
- notification . unread = false ;
49
- } ;
50
-
51
43
const openNotification = useCallback ( ( ) => {
52
44
openInBrowser ( notification , accounts ) ;
53
45
54
46
if ( settings . markAsDoneOnOpen ) {
55
47
markNotificationDone ( notification . id , hostname ) ;
56
48
}
57
-
58
- if ( ! settings . showReadNotifications ) {
59
- removeNotificationFromState ( notification . id , hostname ) ;
60
- } else {
61
- setNotificationAsOpaque ( ) ;
62
- }
49
+ handleNotificationState ( ) ;
63
50
} , [ notifications , notification , accounts , settings ] ) ; // notifications required here to prevent weird state issues
64
51
65
52
const unsubscribe = ( event : MouseEvent < HTMLElement > ) => {
@@ -68,32 +55,17 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
68
55
69
56
unsubscribeNotification ( notification . id , hostname ) ;
70
57
markNotificationRead ( notification . id , hostname ) ;
71
-
72
- if ( ! settings . showReadNotifications ) {
73
- removeNotificationFromState ( notification . id , hostname ) ;
74
- } else {
75
- setNotificationAsOpaque ( ) ;
76
- }
58
+ handleNotificationState ( ) ;
77
59
} ;
78
60
79
61
const markAsRead = ( ) => {
80
62
markNotificationRead ( notification . id , hostname ) ;
81
-
82
- if ( ! settings . showReadNotifications ) {
83
- removeNotificationFromState ( notification . id , hostname ) ;
84
- } else {
85
- setNotificationAsOpaque ( ) ;
86
- }
63
+ handleNotificationState ( ) ;
87
64
} ;
88
65
89
66
const markAsDone = ( ) => {
90
67
markNotificationDone ( notification . id , hostname ) ;
91
-
92
- if ( ! settings . showReadNotifications ) {
93
- removeNotificationFromState ( notification . id , hostname ) ;
94
- } else {
95
- setNotificationAsOpaque ( ) ;
96
- }
68
+ handleNotificationState ( ) ;
97
69
} ;
98
70
99
71
const openUserProfile = (
@@ -105,6 +77,20 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
105
77
openExternalLink ( notification . subject . user . html_url ) ;
106
78
} ;
107
79
80
+ const handleNotificationState = useCallback ( ( ) => {
81
+ if ( ! settings . showAllNotifications ) {
82
+ removeNotificationFromState ( notification . id , hostname ) ;
83
+ }
84
+
85
+ if ( notification . unread ) {
86
+ const notificationRow = document . getElementById ( notification . id ) ;
87
+ notificationRow . className += Constants . READ_CLASS_NAME ;
88
+ }
89
+
90
+ // TODO FIXME - this is not updating the notification count
91
+ notification . unread = false ;
92
+ } , [ notification , notifications ] ) ;
93
+
108
94
const reason = formatReason ( notification . reason ) ;
109
95
const NotificationIcon = getNotificationTypeIcon ( notification . subject ) ;
110
96
const iconColor = getNotificationTypeIconColor ( notification . subject ) ;
0 commit comments