Commit 8871491e authored by Ben Hayward's avatar Ben Hayward

Updated to account for session switching

1 merge request!628[Sprint/QuietQuail](fix): Avatar changing forms now change avatar without refresh of components
Pipeline #94148616 running with stages
......@@ -3,7 +3,7 @@
* @desc Singleton service used to store the current user avatar as a BehaviorSubject.
*/
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Subscription } from 'rxjs';
import { Session } from '../../services/session';
import { MindsUser } from '../../interfaces/entities';
......@@ -14,9 +14,17 @@ export class UserAvatarService {
private minds = window.Minds;
private user: MindsUser;
public src$: BehaviorSubject<string>;
public loggedIn$: Subscription;
constructor(public session: Session) {
this.init();
// Subscribe to loggedIn$ and on login, update src$.
this.loggedIn$ = this.session.loggedinEmitter.subscribe(is => {
if (is) {
this.src$.next(this.getSrc());
}
});
}
/**
......@@ -24,8 +32,13 @@ export class UserAvatarService {
*/
public init(): void {
this.user = this.session.getLoggedInUser();
this.src$ = new BehaviorSubject(
`${this.minds.cdn_url}icon/${this.user.guid}/large/${this.user.icontime}`
);
this.src$ = new BehaviorSubject(this.getSrc());
}
/**
* Gets the Src string using the global minds object and the held user object.
*/
public getSrc(): string {
return `${this.minds.cdn_url}icon/${this.user.guid}/large/${this.user.icontime}`;
}
}
Please register or to comment