Skip to content

Commit 986581c

Browse files
committed
feat: stabilize notification order during notification interactions
Signed-off-by: Adam Setch <[email protected]>
1 parent 2b02a9a commit 986581c

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

src/renderer/utils/notifications/group.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { AccountNotifications, SettingsState } from '../../types';
22
import type { Notification } from '../../typesGitHub';
33

4+
/**
5+
* Returns true when settings say to group by repository.
6+
*/
47
export function isGroupByRepository(settings: SettingsState) {
58
return settings.groupBy === 'REPOSITORY';
69
}
@@ -31,8 +34,17 @@ export function groupNotificationsByRepository(
3134
}
3235

3336
/**
34-
* Flatten the Map values into a single array, preserving Map insertion order (first-seen repo order).
37+
* Returns a flattened, ordered Notification[] according to repository-first-seen order
38+
* (when grouped) or the natural account->notification order otherwise.
3539
*/
36-
export function flattenRepoGroups(repoGroups: Map<string, Notification[]>) {
37-
return Array.from(repoGroups.values()).flat();
40+
export function getFlattenedNotificationsByRepo(
41+
accounts: AccountNotifications[],
42+
settings: SettingsState,
43+
): Notification[] {
44+
if (isGroupByRepository(settings)) {
45+
const repoGroups = groupNotificationsByRepository(accounts);
46+
return Array.from(repoGroups.values()).flat();
47+
}
48+
49+
return accounts.flatMap((a) => a.notifications);
3850
}

src/renderer/utils/notifications/notifications.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import {
1212
filterBaseNotifications,
1313
filterDetailedNotifications,
1414
} from './filters/filter';
15-
import {
16-
flattenRepoGroups,
17-
groupNotificationsByRepository,
18-
isGroupByRepository,
19-
} from './group';
15+
import { getFlattenedNotificationsByRepo } from './group';
2016
import { createNotificationHandler } from './handlers';
2117

2218
export function setTrayIconColor(notifications: AccountNotifications[]) {
@@ -154,23 +150,14 @@ export function stabilizeNotificationsOrder(
154150
notifications: AccountNotifications[],
155151
settings: SettingsState,
156152
) {
157-
if (isGroupByRepository(settings)) {
158-
const repoGroups = groupNotificationsByRepository(notifications);
159-
const flattened = flattenRepoGroups(repoGroups);
160-
161-
let orderIndex = 0;
162-
163-
for (const n of flattened) {
164-
n.order = orderIndex++;
165-
}
166-
} else {
167-
// Non-repository grouping: assign sequential order across all notifications
168-
let orderIndex = 0;
169-
170-
for (const accountNotifications of notifications) {
171-
for (const notification of accountNotifications.notifications) {
172-
notification.order = orderIndex++;
173-
}
174-
}
153+
const flattenedNotifications = getFlattenedNotificationsByRepo(
154+
notifications,
155+
settings,
156+
);
157+
158+
let orderIndex = 0;
159+
160+
for (const n of flattenedNotifications) {
161+
n.order = orderIndex++;
175162
}
176163
}

0 commit comments

Comments
 (0)