-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathRepositoryNotifications.tsx
More file actions
138 lines (124 loc) · 4.31 KB
/
RepositoryNotifications.tsx
File metadata and controls
138 lines (124 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { type FC, type MouseEvent, useContext, useState } from 'react';
import { CheckIcon, ReadIcon } from '@primer/octicons-react';
import { Box, Button, Stack } from '@primer/react';
import { AppContext } from '../../context/App';
import { Opacity, Size } from '../../types';
import type { Notification } from '../../typesGitHub';
import { cn } from '../../utils/cn';
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
import { getChevronDetails } from '../../utils/helpers';
import { openRepository } from '../../utils/links';
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';
import { HoverButton } from '../primitives/HoverButton';
import { HoverGroup } from '../primitives/HoverGroup';
import { NotificationRow } from './NotificationRow';
interface IRepositoryNotifications {
repoNotifications: Notification[];
repoName: string;
}
export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
repoName,
repoNotifications,
}) => {
const { settings, markNotificationsAsRead, markNotificationsAsDone } =
useContext(AppContext);
const [animateExit, setAnimateExit] = useState(false);
const [showAsRead, setShowAsRead] = useState(false);
const [showRepositoryNotifications, setShowRepositoryNotifications] =
useState(true);
const avatarUrl = repoNotifications[0].repository.owner.avatar_url;
const actionMarkAsDone = () => {
setAnimateExit(!settings.delayNotificationState);
setShowAsRead(settings.delayNotificationState);
markNotificationsAsDone(repoNotifications);
};
const actionMarkAsRead = () => {
setAnimateExit(!settings.delayNotificationState);
setShowAsRead(settings.delayNotificationState);
markNotificationsAsRead(repoNotifications);
};
const actionToggleRepositoryNotifications = () => {
setShowRepositoryNotifications(!showRepositoryNotifications);
};
const Chevron = getChevronDetails(
true,
showRepositoryNotifications,
'repository',
);
return (
<>
<Box
className={cn(
'group pr-1 py-0.5',
'bg-gitify-repository',
animateExit &&
'translate-x-full opacity-0 transition duration-350 ease-in-out',
showAsRead && Opacity.READ,
)}
onClick={actionToggleRepositoryNotifications}
>
<Stack
direction="horizontal"
align="center"
gap="condensed"
className="relative"
>
<Button
title="Open repository"
variant="invisible"
alignContent="center"
count={repoNotifications.length}
onClick={(event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
event.stopPropagation();
openRepository(repoNotifications[0].repository);
}}
data-testid="open-repository"
>
<AvatarWithFallback
src={avatarUrl}
alt={repoName}
name={repoName}
size={Size.LARGE}
userType={repoNotifications[0].repository.owner.type}
/>
</Button>
{!animateExit && (
<HoverGroup bgColor="group-hover:bg-gitify-repository">
<HoverButton
label="Mark repository as done"
icon={CheckIcon}
enabled={isMarkAsDoneFeatureSupported(
repoNotifications[0].account,
)}
testid="repository-mark-as-done"
action={actionMarkAsDone}
/>
<HoverButton
label="Mark repository as read"
icon={ReadIcon}
testid="repository-mark-as-read"
action={actionMarkAsRead}
/>
<HoverButton
label={Chevron.label}
icon={Chevron.icon}
testid="repository-toggle"
action={actionToggleRepositoryNotifications}
/>
</HoverGroup>
)}
</Stack>
</Box>
{showRepositoryNotifications &&
repoNotifications.map((notification) => (
<NotificationRow
key={notification.id}
notification={notification}
isAnimated={animateExit}
isRead={showAsRead}
/>
))}
</>
);
};