File tree Expand file tree Collapse file tree 2 files changed +25
-26
lines changed
src/renderer/utils/notifications Expand file tree Collapse file tree 2 files changed +25
-26
lines changed Original file line number Diff line number Diff line change 11import type { AccountNotifications , SettingsState } from '../../types' ;
22import type { Notification } from '../../typesGitHub' ;
33
4+ /**
5+ * Returns true when settings say to group by repository.
6+ */
47export 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}
Original file line number Diff line number Diff 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' ;
2016import { createNotificationHandler } from './handlers' ;
2117
2218export 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}
You can’t perform that action at this time.
0 commit comments