Skip to content

Commit 3dc0a95

Browse files
authored
feat: better notification type icons (#748)
1 parent 1e1adde commit 3dc0a95

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/components/NotificationRow.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export const NotificationRow: React.FC<IProps> = ({
4949
};
5050

5151
const reason = formatReason(notification.reason);
52-
const NotificationIcon = getNotificationTypeIcon(notification.subject.type);
52+
const NotificationIcon = getNotificationTypeIcon(
53+
notification.subject.type,
54+
notification.subject.state,
55+
);
5356
const iconColor = getNotificationTypeIconColor(notification.subject.state);
5457
const realIconColor = settings
5558
? (settings.colors && iconColor) || ''

src/utils/github-api.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,30 @@ describe('./utils/github-api.ts', () => {
2727
expect(getNotificationTypeIcon('Issue').displayName).toBe(
2828
'IssueOpenedIcon',
2929
);
30+
expect(getNotificationTypeIcon('Issue', 'draft').displayName).toBe(
31+
'IssueDraftIcon',
32+
);
33+
expect(getNotificationTypeIcon('Issue', 'closed').displayName).toBe(
34+
'IssueClosedIcon',
35+
);
36+
expect(getNotificationTypeIcon('Issue', 'completed').displayName).toBe(
37+
'IssueClosedIcon',
38+
);
39+
expect(getNotificationTypeIcon('Issue', 'reopened').displayName).toBe(
40+
'IssueReopenedIcon',
41+
);
3042
expect(getNotificationTypeIcon('PullRequest').displayName).toBe(
3143
'GitPullRequestIcon',
3244
);
45+
expect(getNotificationTypeIcon('PullRequest', 'draft').displayName).toBe(
46+
'GitPullRequestDraftIcon',
47+
);
48+
expect(getNotificationTypeIcon('PullRequest', 'closed').displayName).toBe(
49+
'GitPullRequestClosedIcon',
50+
);
51+
expect(getNotificationTypeIcon('PullRequest', 'merged').displayName).toBe(
52+
'GitMergeIcon',
53+
);
3354
expect(getNotificationTypeIcon('Release').displayName).toBe('TagIcon');
3455
expect(
3556
getNotificationTypeIcon('RepositoryVulnerabilityAlert').displayName,

src/utils/github-api.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import {
22
AlertIcon,
33
CommentDiscussionIcon,
44
GitCommitIcon,
5+
GitMergeIcon,
6+
GitPullRequestClosedIcon,
7+
GitPullRequestDraftIcon,
58
GitPullRequestIcon,
9+
IssueClosedIcon,
10+
IssueDraftIcon,
611
IssueOpenedIcon,
12+
IssueReopenedIcon,
713
MailIcon,
814
OcticonProps,
915
QuestionIcon,
@@ -66,6 +72,7 @@ export function formatReason(reason: Reason): {
6672

6773
export function getNotificationTypeIcon(
6874
type: SubjectType,
75+
state?: StateType,
6976
): React.FC<OcticonProps> {
7077
switch (type) {
7178
case 'CheckSuite':
@@ -75,9 +82,28 @@ export function getNotificationTypeIcon(
7582
case 'Discussion':
7683
return CommentDiscussionIcon;
7784
case 'Issue':
78-
return IssueOpenedIcon;
85+
switch (state) {
86+
case 'draft':
87+
return IssueDraftIcon;
88+
case 'closed':
89+
case 'completed':
90+
return IssueClosedIcon;
91+
case 'reopened':
92+
return IssueReopenedIcon;
93+
default:
94+
return IssueOpenedIcon;
95+
}
7996
case 'PullRequest':
80-
return GitPullRequestIcon;
97+
switch (state) {
98+
case 'draft':
99+
return GitPullRequestDraftIcon;
100+
case 'closed':
101+
return GitPullRequestClosedIcon;
102+
case 'merged':
103+
return GitMergeIcon;
104+
default:
105+
return GitPullRequestIcon;
106+
}
81107
case 'Release':
82108
return TagIcon;
83109
case 'RepositoryInvitation':

0 commit comments

Comments
 (0)