1
- import { ChevronDownIcon , ChevronLeftIcon } from '@primer/octicons-react' ;
1
+ import {
2
+ ChevronDownIcon ,
3
+ ChevronLeftIcon ,
4
+ ChevronUpIcon ,
5
+ } from '@primer/octicons-react' ;
6
+ import { useState } from 'react' ;
2
7
import type { Account } from '../types' ;
3
8
import type { Notification } from '../typesGitHub' ;
4
9
import { openAccountProfile } from '../utils/links' ;
@@ -26,7 +31,25 @@ export const AccountNotifications = (props: IProps) => {
26
31
) ,
27
32
) ;
28
33
29
- const Chevron = notifications . length > 0 ? ChevronDownIcon : ChevronLeftIcon ;
34
+ const [ showNotifications , setShowNotifications ] = useState ( true ) ;
35
+
36
+ const toggleNotifications = ( ) => {
37
+ setShowNotifications ( ! showNotifications ) ;
38
+ } ;
39
+
40
+ const ChevronIcon =
41
+ notifications . length === 0
42
+ ? ChevronLeftIcon
43
+ : showNotifications
44
+ ? ChevronDownIcon
45
+ : ChevronUpIcon ;
46
+
47
+ const toggleNotificationsLabel =
48
+ notifications . length === 0
49
+ ? 'No notifications for account'
50
+ : showNotifications
51
+ ? 'Hide account notifications'
52
+ : 'Show account notifications' ;
30
53
31
54
return (
32
55
< >
@@ -43,23 +66,30 @@ export const AccountNotifications = (props: IProps) => {
43
66
</ button >
44
67
</ div >
45
68
< div >
46
- < Chevron size = { 20 } />
69
+ < button
70
+ type = "button"
71
+ title = { toggleNotificationsLabel }
72
+ onClick = { toggleNotifications }
73
+ >
74
+ < ChevronIcon size = { 20 } />
75
+ </ button >
47
76
</ div >
48
77
</ div >
49
78
) }
50
79
51
- { Object . values ( groupedNotifications ) . map ( ( repoNotifications ) => {
52
- const repoSlug = repoNotifications [ 0 ] . repository . full_name ;
80
+ { showNotifications &&
81
+ Object . values ( groupedNotifications ) . map ( ( repoNotifications ) => {
82
+ const repoSlug = repoNotifications [ 0 ] . repository . full_name ;
53
83
54
- return (
55
- < RepositoryNotifications
56
- key = { repoSlug }
57
- account = { account }
58
- repoName = { repoSlug }
59
- repoNotifications = { repoNotifications }
60
- />
61
- ) ;
62
- } ) }
84
+ return (
85
+ < RepositoryNotifications
86
+ key = { repoSlug }
87
+ account = { account }
88
+ repoName = { repoSlug }
89
+ repoNotifications = { repoNotifications }
90
+ />
91
+ ) ;
92
+ } ) }
63
93
</ >
64
94
) ;
65
95
} ;
0 commit comments