Skip to content

Commit 587eb50

Browse files
committed
fix: notification read state for delayNotificationState
Signed-off-by: Adam Setch <[email protected]>
1 parent 969e5da commit 587eb50

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

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.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
/>

src/renderer/hooks/useNotifications.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ import {
2323
} from '../utils/notifications/notifications';
2424
import { removeNotifications } from '../utils/notifications/remove';
2525

26+
// Apply optimistic local updates for read state when delayNotificationState is enabled
27+
function applyLocalOptimisticRead(
28+
state: GitifyState,
29+
targetNotifications: Notification[],
30+
) {
31+
if (state.settings.delayNotificationState) {
32+
for (const n of targetNotifications) {
33+
n.unread = false;
34+
}
35+
}
36+
}
37+
2638
interface NotificationsState {
2739
notifications: AccountNotifications[];
2840
removeAccountNotifications: (account: Account) => Promise<void>;
@@ -125,6 +137,8 @@ export const useNotifications = (): NotificationsState => {
125137
notifications,
126138
);
127139

140+
applyLocalOptimisticRead(state, readNotifications);
141+
128142
setNotifications(updatedNotifications);
129143
setTrayIconColor(updatedNotifications);
130144
} catch (err) {
@@ -163,6 +177,8 @@ export const useNotifications = (): NotificationsState => {
163177
notifications,
164178
);
165179

180+
applyLocalOptimisticRead(state, doneNotifications);
181+
166182
setNotifications(updatedNotifications);
167183
setTrayIconColor(updatedNotifications);
168184
} catch (err) {

0 commit comments

Comments
 (0)