@@ -5,13 +5,7 @@ import {
55 MarkGithubIcon ,
66 ReadIcon ,
77} from '@primer/octicons-react' ;
8- import {
9- type FC ,
10- type MouseEvent ,
11- useCallback ,
12- useContext ,
13- useState ,
14- } from 'react' ;
8+ import { type FC , type MouseEvent , useContext , useState } from 'react' ;
159import { AppContext } from '../context/App' ;
1610import { Opacity , Size } from '../types' ;
1711import type { Notification } from '../typesGitHub' ;
@@ -31,22 +25,15 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
3125 repoName,
3226 repoNotifications,
3327} ) => {
34- const { markRepoNotificationsRead, markRepoNotificationsDone } =
28+ const { settings , markRepoNotificationsRead, markRepoNotificationsDone } =
3529 useContext ( AppContext ) ;
36-
37- const markRepoAsRead = useCallback ( ( ) => {
38- markRepoNotificationsRead ( repoNotifications [ 0 ] ) ;
39- } , [ repoNotifications , markRepoNotificationsRead ] ) ;
40-
41- const markRepoAsDone = useCallback ( ( ) => {
42- markRepoNotificationsDone ( repoNotifications [ 0 ] ) ;
43- } , [ repoNotifications , markRepoNotificationsDone ] ) ;
44-
45- const avatarUrl = repoNotifications [ 0 ] . repository . owner . avatar_url ;
46-
30+ const [ animateExit , setAnimateExit ] = useState ( false ) ;
31+ const [ showAsRead , setShowAsRead ] = useState ( false ) ;
4732 const [ showRepositoryNotifications , setShowRepositoryNotifications ] =
4833 useState ( true ) ;
4934
35+ const avatarUrl = repoNotifications [ 0 ] . repository . owner . avatar_url ;
36+
5037 const toggleRepositoryNotifications = ( ) => {
5138 setShowRepositoryNotifications ( ! showRepositoryNotifications ) ;
5239 } ;
@@ -68,7 +55,9 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
6855 < div
6956 className = { cn (
7057 'flex flex-1 gap-4 items-center truncate text-sm font-medium' ,
71- Opacity . MEDIUM ,
58+ animateExit &&
59+ 'translate-x-full opacity-0 transition duration-[350ms] ease-in-out' ,
60+ showAsRead ? Opacity . READ : Opacity . MEDIUM ,
7261 ) }
7362 >
7463 < AvatarIcon
@@ -94,13 +83,25 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
9483 title = "Mark Repository as Done"
9584 icon = { CheckIcon }
9685 size = { Size . MEDIUM }
97- onClick = { markRepoAsDone }
86+ onClick = { ( event : MouseEvent < HTMLElement > ) => {
87+ // Don't trigger onClick of parent element.
88+ event . stopPropagation ( ) ;
89+ setAnimateExit ( ! settings . delayNotificationState ) ;
90+ setShowAsRead ( settings . delayNotificationState ) ;
91+ markRepoNotificationsDone ( repoNotifications [ 0 ] ) ;
92+ } }
9893 />
9994 < InteractionButton
10095 title = "Mark Repository as Read"
10196 icon = { ReadIcon }
10297 size = { Size . SMALL }
103- onClick = { markRepoAsRead }
98+ onClick = { ( event : MouseEvent < HTMLElement > ) => {
99+ // Don't trigger onClick of parent element.
100+ event . stopPropagation ( ) ;
101+ setAnimateExit ( ! settings . delayNotificationState ) ;
102+ setShowAsRead ( settings . delayNotificationState ) ;
103+ markRepoNotificationsRead ( repoNotifications [ 0 ] ) ;
104+ } }
104105 />
105106 < InteractionButton
106107 title = { toggleRepositoryNotificationsLabel }
@@ -113,7 +114,11 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
113114
114115 { showRepositoryNotifications &&
115116 repoNotifications . map ( ( notification ) => (
116- < NotificationRow key = { notification . id } notification = { notification } />
117+ < NotificationRow
118+ key = { notification . id }
119+ notification = { notification }
120+ isRead = { showAsRead }
121+ />
117122 ) ) }
118123 </ >
119124 ) ;
0 commit comments