Skip to content

Commit 674a65d

Browse files
authored
feat(accounts): add avatar, account-level quick links and account refresh support (#1438)
* feat(account): add avatar and account-level quick links Signed-off-by: Adam Setch <[email protected]> * feat(account): add avatar and account-level quick links Signed-off-by: Adam Setch <[email protected]> * feat(account): add avatar and account-level quick links Signed-off-by: Adam Setch <[email protected]> * feat(account): add avatar and account-level quick links Signed-off-by: Adam Setch <[email protected]> * feat(account): add avatar and account-level quick links Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into feature/account-avatar Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into feature/account-avatar Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent e7b843b commit 674a65d

16 files changed

+1184
-348
lines changed

src/__mocks__/state-mocks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type GitifyUser,
66
GroupBy,
77
type Hostname,
8+
type Link,
89
OpenPreference,
910
type SettingsState,
1011
Theme,
@@ -24,6 +25,7 @@ export const mockGitifyUser: GitifyUser = {
2425
login: 'octocat',
2526
name: 'Mona Lisa Octocat',
2627
id: 123456789,
28+
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
2729
};
2830

2931
export const mockPersonalAccessTokenAccount: Account = {

src/components/AccountNotifications.test.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,62 @@ describe('components/AccountNotifications.tsx', () => {
114114
expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount);
115115
});
116116

117+
it('should open my issues when clicked', async () => {
118+
const openMyIssuesMock = jest
119+
.spyOn(links, 'openGitHubIssues')
120+
.mockImplementation();
121+
122+
const props = {
123+
account: mockGitHubCloudAccount,
124+
notifications: [],
125+
showAccountHostname: true,
126+
error: null,
127+
};
128+
129+
await act(async () => {
130+
render(
131+
<AppContext.Provider value={{ settings: mockSettings }}>
132+
<AccountNotifications {...props} />
133+
</AppContext.Provider>,
134+
);
135+
});
136+
137+
fireEvent.click(screen.getByTitle('My Issues'));
138+
139+
expect(openMyIssuesMock).toHaveBeenCalledTimes(1);
140+
expect(openMyIssuesMock).toHaveBeenCalledWith(
141+
mockGitHubCloudAccount.hostname,
142+
);
143+
});
144+
145+
it('should open my pull requests when clicked', async () => {
146+
const openPullRequestsMock = jest
147+
.spyOn(links, 'openGitHubPulls')
148+
.mockImplementation();
149+
150+
const props = {
151+
account: mockGitHubCloudAccount,
152+
notifications: [],
153+
showAccountHostname: true,
154+
error: null,
155+
};
156+
157+
await act(async () => {
158+
render(
159+
<AppContext.Provider value={{ settings: mockSettings }}>
160+
<AccountNotifications {...props} />
161+
</AppContext.Provider>,
162+
);
163+
});
164+
165+
fireEvent.click(screen.getByTitle('My Pull Requests'));
166+
167+
expect(openPullRequestsMock).toHaveBeenCalledTimes(1);
168+
expect(openPullRequestsMock).toHaveBeenCalledWith(
169+
mockGitHubCloudAccount.hostname,
170+
);
171+
});
172+
117173
it('should toggle account notifications visibility', async () => {
118174
const props = {
119175
account: mockGitHubCloudAccount,

src/components/AccountNotifications.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ import {
22
ChevronDownIcon,
33
ChevronLeftIcon,
44
ChevronUpIcon,
5+
FeedPersonIcon,
6+
GitPullRequestIcon,
7+
IssueOpenedIcon,
58
} from '@primer/octicons-react';
69
import { type FC, type MouseEvent, useContext, useMemo, useState } from 'react';
710
import { AppContext } from '../context/App';
811
import { type Account, type GitifyError, Opacity, Size } from '../types';
912
import type { Notification } from '../typesGitHub';
1013
import { cn } from '../utils/cn';
11-
import { openAccountProfile } from '../utils/links';
14+
import {
15+
openAccountProfile,
16+
openGitHubIssues,
17+
openGitHubPulls,
18+
} from '../utils/links';
1219
import { AllRead } from './AllRead';
1320
import { HoverGroup } from './HoverGroup';
1421
import { NotificationRow } from './NotificationRow';
1522
import { Oops } from './Oops';
1623
import { RepositoryNotifications } from './RepositoryNotifications';
1724
import { InteractionButton } from './buttons/InteractionButton';
25+
import { AvatarIcon } from './icons/AvatarIcon';
1826
import { PlatformIcon } from './icons/PlatformIcon';
1927

2028
interface IAccountNotifications {
@@ -85,8 +93,13 @@ export const AccountNotifications: FC<IAccountNotifications> = (
8593
onClick={toggleAccountNotifications}
8694
>
8795
<div className="flex">
88-
<div className="mr-3 flex items-center justify-center">
89-
<PlatformIcon type={account.platform} size={Size.MEDIUM} />
96+
<div className="mr-2 flex items-center justify-center">
97+
<AvatarIcon
98+
title={account.user.login}
99+
url={account.user.avatar}
100+
size={Size.SMALL}
101+
defaultIcon={FeedPersonIcon}
102+
/>
90103
</div>
91104
<button
92105
type="button"
@@ -101,6 +114,19 @@ export const AccountNotifications: FC<IAccountNotifications> = (
101114
</button>
102115
</div>
103116
<HoverGroup>
117+
<PlatformIcon type={account.platform} size={Size.SMALL} />
118+
<InteractionButton
119+
title="My Issues"
120+
icon={IssueOpenedIcon}
121+
size={Size.SMALL}
122+
onClick={() => openGitHubIssues(account.hostname)}
123+
/>
124+
<InteractionButton
125+
title="My Pull Requests"
126+
icon={GitPullRequestIcon}
127+
size={Size.SMALL}
128+
onClick={() => openGitHubPulls(account.hostname)}
129+
/>
104130
<InteractionButton
105131
title={toggleAccountNotificationsLabel}
106132
icon={ChevronIcon}

src/components/RepositoryNotifications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
5555
>
5656
<div
5757
className={cn(
58-
'flex flex-1 gap-4 items-center truncate text-sm font-medium',
58+
'flex flex-1 gap-3 items-center truncate text-sm font-medium',
5959
animateExit &&
6060
'translate-x-full opacity-0 transition duration-[350ms] ease-in-out',
6161
showAsRead ? Opacity.READ : Opacity.MEDIUM,

0 commit comments

Comments
 (0)