feat: notification component
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
export interface INotification {
|
||||
message: string;
|
||||
isError: boolean;
|
||||
time: number;
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Subject } from "rxjs";
|
||||
import { INotification } from "./notification.dto";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class NotificationService {
|
||||
readonly notification$ = new Subject<INotification>();
|
||||
|
||||
private sendNotification(message: INotification) {
|
||||
this.notification$.next(message);
|
||||
}
|
||||
|
||||
info(message: string, title: string = "", time = 3000) {
|
||||
this.sendNotification({
|
||||
message,
|
||||
isError: false,
|
||||
time: time,
|
||||
name: title,
|
||||
});
|
||||
}
|
||||
|
||||
error(message: string, title: string = "", time = 3000) {
|
||||
this.sendNotification({
|
||||
message,
|
||||
isError: true,
|
||||
time: time,
|
||||
name: title,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,16 @@ export class RulibAuthService implements OnDestroy {
|
||||
private api_url = "https://api.lib.social";
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
setToken(token: string) {
|
||||
this.checkToken(token)
|
||||
setToken(token: string): Observable<boolean> {
|
||||
return this.checkToken(token)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((data) => {
|
||||
if (!data) return;
|
||||
localStorage.setItem("token", token);
|
||||
});
|
||||
.pipe(
|
||||
map((data) => {
|
||||
if (!data) return false;
|
||||
localStorage.setItem("token", token);
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getToken(): string {
|
||||
|
||||
Reference in New Issue
Block a user