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' ;
27import type { Account } from '../types' ;
38import type { Notification } from '../typesGitHub' ;
49import { openAccountProfile } from '../utils/links' ;
@@ -26,7 +31,25 @@ export const AccountNotifications = (props: IProps) => {
2631 ) ,
2732 ) ;
2833
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' ;
3053
3154 return (
3255 < >
@@ -43,23 +66,30 @@ export const AccountNotifications = (props: IProps) => {
4366 </ button >
4467 </ div >
4568 < div >
46- < Chevron size = { 20 } />
69+ < button
70+ type = "button"
71+ title = { toggleNotificationsLabel }
72+ onClick = { toggleNotifications }
73+ >
74+ < ChevronIcon size = { 20 } />
75+ </ button >
4776 </ div >
4877 </ div >
4978 ) }
5079
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 ;
5383
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+ } ) }
6393 </ >
6494 ) ;
6595} ;
0 commit comments