Skip to content

Commit 2058114

Browse files
authored
Merge pull request #2531 from ORCID/lmendoza/jun-4-2025-multiple-fixes
Lmendoza/jun 4 2025 multiple fixes
2 parents 4654593 + 6a106e1 commit 2058114

6 files changed

Lines changed: 71 additions & 22 deletions

File tree

src/app/core/inbox/inbox.service.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient, HttpHeaders } from '@angular/common/http'
22
import { Injectable } from '@angular/core'
3-
import { Observable, ReplaySubject } from 'rxjs'
3+
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs'
44
import { catchError, map, switchMap, tap, retry } from 'rxjs/operators'
55
import { AMOUNT_OF_RETRIEVE_NOTIFICATIONS_PER_CALL } from 'src/app/constants'
66
import { ERROR_REPORT } from 'src/app/errors'
@@ -22,6 +22,10 @@ export class InboxService {
2222
private currentlyIncludingArchive: boolean
2323
private currentLevel = 0
2424
private headers: HttpHeaders
25+
private _unreadCountSubject = new BehaviorSubject<number | null>(null)
26+
public readonly unreadCount$: Observable<number | null> =
27+
this._unreadCountSubject.asObservable()
28+
2529
private inboxSubject = new ReplaySubject<
2630
(
2731
| InboxNotificationAmended
@@ -218,13 +222,39 @@ export class InboxService {
218222
)
219223
}
220224

221-
retrieveUnreadCount(): any {
222-
return this._http.get(
223-
runtimeEnvironment.BASE_URL + 'inbox/unreadCount.json'
224-
)
225+
private _fetchAndUpdateUnreadCount(): Observable<number> {
226+
return this._http
227+
.get<number>(runtimeEnvironment.BASE_URL + 'inbox/unreadCount.json', {
228+
headers: this.headers,
229+
})
230+
.pipe(
231+
retry(3),
232+
tap((count: number) => {
233+
this._unreadCountSubject.next(count)
234+
}),
235+
catchError((error) =>
236+
this._errorHandler.handleError(error, ERROR_REPORT.STANDARD_VERBOSE)
237+
)
238+
)
225239
}
226240

227-
totalNumber() {
241+
/**
242+
243+
* Calling retrieveUnreadCount() will:
244+
* 1) Kick off a fresh HTTP GET to inbox/unreadCount.json
245+
* 2) Push that result into _unreadCountSubject
246+
* 3) Return the “hot” Observable from _unreadCountSubject, so that ANY future changes are pass through
247+
*/
248+
retrieveUnreadCount(): Observable<number | null> {
249+
this._fetchAndUpdateUnreadCount().subscribe()
250+
return this.unreadCount$
251+
}
252+
253+
/**
254+
* Returns Observable<TotalNotificationCount>
255+
* and triggers a fresh fetch of unreadCount.json so that unreadCount$ subscribers are updated.
256+
*/
257+
totalNumber(): Observable<TotalNotificationCount> {
228258
return this._http
229259
.get<TotalNotificationCount>(
230260
runtimeEnvironment.BASE_URL + `inbox/totalCount.json`,
@@ -238,6 +268,10 @@ export class InboxService {
238268
value.archived = value.all - value.nonArchived
239269
return value
240270
}),
271+
// As a side‐effect, refresh the unread count whenever totalNumber() is called:
272+
tap(() => {
273+
this._fetchAndUpdateUnreadCount().subscribe()
274+
}),
241275
catchError((error) => this._errorHandler.handleError(error))
242276
)
243277
}

src/app/layout/user-menu/user-menu.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
inboxUnread > 0 ? notificationTooltipActive : notificationTooltip
4040
"
4141
[attr.aria-label]="
42-
inboxUnread > 0 ? notificationTooltipActive : notificationTooltip
42+
inboxUnread > 0 ? notificationi18nActive : notificationi18n
4343
"
4444
>
4545
<mat-icon
@@ -77,7 +77,13 @@
7777
</div>
7878
</button>
7979
<button mat-menu-item (click)="goto('inbox', 'fromMenuButton')" id="cy-inbox">
80-
<mat-icon *ngIf="inboxUnread === 0">inbox</mat-icon>
80+
<mat-icon *ngIf="inboxUnread === 0"
81+
><img
82+
class="bell-icon"
83+
*ngIf="inboxUnread === 0"
84+
src="./assets/vectors/notification-button.svg"
85+
alt=""
86+
/></mat-icon>
8187
<mat-icon *ngIf="inboxUnread > 0"
8288
><img src="./assets/vectors/notification-button-active.svg"
8389
/></mat-icon>

src/app/layout/user-menu/user-menu.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ span.name-text-container {
8484
padding: 0;
8585
margin: 0 16px;
8686
}
87+
88+
.bell-icon {
89+
margin-inline-start: 3px;
90+
margin-inline-end: 14px;
91+
}

src/app/layout/user-menu/user-menu.component.scss-theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
.main-button {
1111
border-bottom: 1px map-get($foreground, divider) solid;
1212
}
13+
.mat-icon {
14+
color: map-get($background, ui-background-darkest);
15+
}
1316
}
1417

1518
@include user-menu-theme($orcid-app-theme);

src/app/layout/user-menu/user-menu.component.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class UserMenuComponent implements OnInit {
2828
labelUserMenu = $localize`:@@layout.ariaLabelUserMenu:User menu`
2929
notificationTooltipActive = $localize`:@@layout.notificationTooltip:You have unread notifications`
3030
notificationTooltip = $localize`:@@layout.notificationTooltipInactive:Notifications inbox`
31+
notificationi18n = $localize`:@@layout.notifications:Open notification inbox`
32+
notificationi18nActive = $localize`:@@layout.notificationsActive:You have unread notifications. Open notification inbox`
3133
isAccountDelegate: boolean
3234
inboxUnread = 0
3335
userJourney!: 'orcid_with_notifications' | 'orcid_without_notifications'
@@ -58,21 +60,18 @@ export class UserMenuComponent implements OnInit {
5860
}
5961

6062
ngOnInit() {
61-
this._inboxService
62-
.retrieveUnreadCount()
63-
.pipe(first())
64-
.subscribe((inboxUnread) => {
65-
;(this.userJourney =
66-
inboxUnread > 0
67-
? 'orcid_with_notifications'
68-
: 'orcid_without_notifications'),
69-
this.observabilityEventService.startJourney(
70-
this.userJourney,
63+
this._inboxService.retrieveUnreadCount().subscribe((inboxUnread) => {
64+
;(this.userJourney =
65+
inboxUnread > 0
66+
? 'orcid_with_notifications'
67+
: 'orcid_without_notifications'),
68+
this.observabilityEventService.startJourney(
69+
this.userJourney,
7170

72-
{ inboxUnread }
73-
)
74-
this.inboxUnread = inboxUnread
75-
})
71+
{ inboxUnread }
72+
)
73+
this.inboxUnread = inboxUnread
74+
})
7675
}
7776

7877
goto(url, from?: string) {

src/locale/properties/layout/layout.en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ layout.ariaLabelConnectingResearchers=Connecting research and researchers
116116
layout.ariaLabelSearchRegistry=Search the ORCID registry...
117117
layout.notificationTooltip=You have unread notifications
118118
layout.notificationTooltipInactive=Notifications inbox
119+
layout.notifications=Open notification inbox
120+
layout.notificationsActive=You have unread notifications. Open notification inbox

0 commit comments

Comments
 (0)