Skip to content

Commit 115170e

Browse files
authored
fix: notification read state when using delayNotificationState settings (#2314)
* fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> * Update useNotifications.ts * fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> * fix: notification read state for delayNotificationState Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 969e5da commit 115170e

File tree

8 files changed

+1236
-48
lines changed

8 files changed

+1236
-48
lines changed

src/renderer/components/notifications/NotificationRow.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => {
8484
expect(tree).toMatchSnapshot();
8585
});
8686

87+
it('should render itself & its children - notification is read', async () => {
88+
jest
89+
.spyOn(global.Date, 'now')
90+
.mockImplementation(() => new Date('2024').valueOf());
91+
92+
const props = {
93+
notification: {
94+
...mockSingleNotification,
95+
unread: false,
96+
},
97+
account: mockGitHubCloudAccount,
98+
};
99+
100+
const tree = render(
101+
<AppContext.Provider value={{ settings: mockSettings }}>
102+
<NotificationRow {...props} />
103+
</AppContext.Provider>,
104+
);
105+
106+
expect(tree).toMatchSnapshot();
107+
});
108+
87109
describe('notification interactions', () => {
88110
it('should open a notification in the browser - click', async () => {
89111
const markNotificationsAsRead = jest.fn();

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import { NotificationHeader } from './NotificationHeader';
1818
interface INotificationRow {
1919
notification: Notification;
2020
isAnimated?: boolean;
21-
isRead?: boolean;
2221
}
2322

2423
export const NotificationRow: FC<INotificationRow> = ({
2524
notification,
2625
isAnimated = false,
27-
isRead = false,
2826
}: INotificationRow) => {
2927
const {
3028
settings,
@@ -33,12 +31,9 @@ export const NotificationRow: FC<INotificationRow> = ({
3331
unsubscribeNotification,
3432
} = useContext(AppContext);
3533
const [animateExit, setAnimateExit] = useState(false);
36-
const [showAsRead, setShowAsRead] = useState(false);
3734

3835
const handleNotification = useCallback(() => {
3936
setAnimateExit(!settings.delayNotificationState);
40-
setShowAsRead(settings.delayNotificationState);
41-
4237
openNotification(notification);
4338

4439
if (settings.markAsDoneOnOpen) {
@@ -55,13 +50,11 @@ export const NotificationRow: FC<INotificationRow> = ({
5550

5651
const actionMarkAsDone = () => {
5752
setAnimateExit(!settings.delayNotificationState);
58-
setShowAsRead(settings.delayNotificationState);
5953
markNotificationsAsDone([notification]);
6054
};
6155

6256
const actionMarkAsRead = () => {
6357
setAnimateExit(!settings.delayNotificationState);
64-
setShowAsRead(settings.delayNotificationState);
6558
markNotificationsAsRead([notification]);
6659
};
6760

@@ -78,6 +71,8 @@ export const NotificationRow: FC<INotificationRow> = ({
7871

7972
const groupByDate = settings.groupBy === GroupBy.DATE;
8073

74+
const isNotificationRead = !notification.unread;
75+
8176
return (
8277
<div
8378
className={cn(
@@ -86,7 +81,7 @@ export const NotificationRow: FC<INotificationRow> = ({
8681
'text-gitify-font border-gitify-notification-border hover:bg-gitify-notification-hover',
8782
(isAnimated || animateExit) &&
8883
'translate-x-full opacity-0 transition duration-350 ease-in-out',
89-
(isRead || showAsRead) && Opacity.READ,
84+
isNotificationRead && Opacity.READ,
9085
)}
9186
id={notification.id}
9287
>

src/renderer/components/notifications/RepositoryNotifications.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () =>
3939
expect(tree).toMatchSnapshot();
4040
});
4141

42+
it('should render itself & its children - all notifications are read', () => {
43+
for (const n of props.repoNotifications) {
44+
n.unread = false;
45+
}
46+
47+
const tree = render(
48+
<AppContext.Provider value={{}}>
49+
<RepositoryNotifications {...props} />
50+
</AppContext.Provider>,
51+
);
52+
53+
expect(tree).toMatchSnapshot();
54+
});
55+
4256
it('should open the browser when clicking on the repo name', async () => {
4357
const openExternalLinkMock = jest
4458
.spyOn(comms, 'openExternalLink')

src/renderer/components/notifications/RepositoryNotifications.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,29 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
2727
const { settings, markNotificationsAsRead, markNotificationsAsDone } =
2828
useContext(AppContext);
2929
const [animateExit, setAnimateExit] = useState(false);
30-
const [showAsRead, setShowAsRead] = useState(false);
3130
const [showRepositoryNotifications, setShowRepositoryNotifications] =
3231
useState(true);
3332

3433
const avatarUrl = repoNotifications[0].repository.owner.avatar_url;
3534

3635
const actionMarkAsDone = () => {
3736
setAnimateExit(!settings.delayNotificationState);
38-
setShowAsRead(settings.delayNotificationState);
3937
markNotificationsAsDone(repoNotifications);
4038
};
4139

4240
const actionMarkAsRead = () => {
4341
setAnimateExit(!settings.delayNotificationState);
44-
setShowAsRead(settings.delayNotificationState);
4542
markNotificationsAsRead(repoNotifications);
4643
};
4744

4845
const actionToggleRepositoryNotifications = () => {
4946
setShowRepositoryNotifications(!showRepositoryNotifications);
5047
};
5148

49+
const areAllRepoNotificationsRead = repoNotifications.every(
50+
(notification) => !notification.unread,
51+
);
52+
5253
const Chevron = getChevronDetails(
5354
true,
5455
showRepositoryNotifications,
@@ -63,7 +64,7 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
6364
'bg-gitify-repository',
6465
animateExit &&
6566
'translate-x-full opacity-0 transition duration-350 ease-in-out',
66-
showAsRead && Opacity.READ,
67+
areAllRepoNotificationsRead && Opacity.READ,
6768
)}
6869
direction="horizontal"
6970
onClick={actionToggleRepositoryNotifications}
@@ -122,7 +123,6 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
122123
repoNotifications.map((notification) => (
123124
<NotificationRow
124125
isAnimated={animateExit}
125-
isRead={showAsRead}
126126
key={notification.id}
127127
notification={notification}
128128
/>

0 commit comments

Comments
 (0)