refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
export enum Severity {
|
||||
INFO = 'INFO',
|
||||
WARN = 'WARN',
|
||||
ERROR = 'ERROR'
|
||||
}
|
||||
|
||||
export interface LogNotification {
|
||||
timestamp?: string;
|
||||
message: string;
|
||||
severity?: Severity;
|
||||
}
|
||||
|
||||
export function parseLogNotification(messageBody: string): LogNotification {
|
||||
const raw = JSON.parse(messageBody);
|
||||
return {
|
||||
timestamp: raw.timestamp ? new Date(raw.timestamp).toLocaleTimeString() : undefined,
|
||||
message: raw.message,
|
||||
severity: raw.severity ? Severity[raw.severity as keyof typeof Severity] : undefined
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {LogNotification} from './model/log-notification.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class NotificationEventService {
|
||||
private latestNotificationSubject = new BehaviorSubject<LogNotification | null>(null);
|
||||
|
||||
latestNotification$: Observable<LogNotification> = this.latestNotificationSubject.asObservable().pipe(
|
||||
filter((event): event is LogNotification => event !== null)
|
||||
);
|
||||
|
||||
private notificationHighlightSubject = new BehaviorSubject<boolean>(false);
|
||||
notificationHighlight$ = this.notificationHighlightSubject.asObservable();
|
||||
|
||||
private highlightTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
handleNewNotification(notification: LogNotification): void {
|
||||
this.latestNotificationSubject.next(notification);
|
||||
this.notificationHighlightSubject.next(true);
|
||||
|
||||
if (this.highlightTimeout) {
|
||||
clearTimeout(this.highlightTimeout);
|
||||
}
|
||||
|
||||
this.highlightTimeout = setTimeout(() => {
|
||||
this.notificationHighlightSubject.next(false);
|
||||
}, 7500);
|
||||
|
||||
setTimeout(() => {
|
||||
if (!this.notificationHighlightSubject.value) {
|
||||
this.latestNotificationSubject.next(null);
|
||||
}
|
||||
}, 20000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { RxStompService } from './rx-stomp.service';
|
||||
import { createRxStompConfig } from './rx-stomp.config';
|
||||
import {AuthService} from '../service/auth.service';
|
||||
|
||||
export function rxStompServiceFactory(authService: AuthService) {
|
||||
const rxStomp = new RxStompService(authService);
|
||||
const stompConfig = createRxStompConfig(authService);
|
||||
rxStomp.configure(stompConfig);
|
||||
return rxStomp;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {RxStompConfig} from '@stomp/rx-stomp';
|
||||
import {AuthService} from '../service/auth.service';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
|
||||
export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||
return {
|
||||
brokerURL: API_CONFIG.BROKER_URL,
|
||||
heartbeatIncoming: 0,
|
||||
heartbeatOutgoing: 20000,
|
||||
reconnectDelay: 10000,
|
||||
beforeConnect: (stomp) => {
|
||||
const token = authService.getInternalAccessToken();
|
||||
if (token) {
|
||||
stomp.stompClient.connectHeaders = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
debug: (msg: string): void => {
|
||||
// console.log(new Date(), msg);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {RxStomp, RxStompConfig} from '@stomp/rx-stomp';
|
||||
import { AuthService } from '../service/auth.service';
|
||||
import { createRxStompConfig } from './rx-stomp.config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RxStompService extends RxStomp {
|
||||
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
const stompConfig = createRxStompConfig(this.authService);
|
||||
this.configure(stompConfig);
|
||||
}
|
||||
|
||||
public updateConfig(config: RxStompConfig) {
|
||||
this.configure(config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user