Skip to content

Commit b9b8a99

Browse files
authored
feat: account notifications toggle via chevron (#1218)
* feat: account notifications toggle via chevron * feat: account notifications toggle via chevron
1 parent 0a4f5ca commit b9b8a99

File tree

3 files changed

+350
-53
lines changed

3 files changed

+350
-53
lines changed

src/components/AccountNotifications.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ describe('components/AccountNotifications.tsx', () => {
4949
expect(openAccountProfileMock).toHaveBeenCalledTimes(1);
5050
expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount);
5151
});
52+
53+
it('should toggle account notifications visibility', async () => {
54+
const props = {
55+
account: mockGitHubCloudAccount,
56+
notifications: mockGitHubNotifications,
57+
showAccountHostname: true,
58+
};
59+
60+
await act(async () => {
61+
render(<AccountNotifications {...props} />);
62+
});
63+
64+
fireEvent.click(screen.getByTitle('Hide account notifications'));
65+
66+
const tree = render(<AccountNotifications {...props} />);
67+
expect(tree).toMatchSnapshot();
68+
});
5269
});

src/components/AccountNotifications.tsx

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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';
27
import type { Account } from '../types';
38
import type { Notification } from '../typesGitHub';
49
import { 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

Comments
 (0)