Fehlerbehebung & Start Vector Search
This commit is contained in:
@@ -1,32 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
|
||||
export interface Message {
|
||||
severity: 'success' | 'danger' | 'warning';
|
||||
text: string;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MessageService {
|
||||
private modalVisibleSubject = new BehaviorSubject<boolean>(false);
|
||||
private messageSubject = new BehaviorSubject<string>('');
|
||||
private resolvePromise!: (value: boolean) => void;
|
||||
private messagesSubject = new BehaviorSubject<Message[]>([]);
|
||||
messages$: Observable<Message[]> = this.messagesSubject.asObservable();
|
||||
|
||||
modalVisible$: Observable<boolean> = this.modalVisibleSubject.asObservable();
|
||||
message$: Observable<string> = this.messageSubject.asObservable();
|
||||
addMessage(message: Message): void {
|
||||
const currentMessages = this.messagesSubject.value;
|
||||
this.messagesSubject.next([...currentMessages, message]);
|
||||
|
||||
showMessage(message: string): Promise<boolean> {
|
||||
this.messageSubject.next(message);
|
||||
this.modalVisibleSubject.next(true);
|
||||
return new Promise<boolean>(resolve => {
|
||||
this.resolvePromise = resolve;
|
||||
});
|
||||
if (message.duration > 0) {
|
||||
setTimeout(() => this.removeMessage(message), message.duration);
|
||||
}
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
this.modalVisibleSubject.next(false);
|
||||
this.resolvePromise(true);
|
||||
}
|
||||
|
||||
reject(): void {
|
||||
this.modalVisibleSubject.next(false);
|
||||
this.resolvePromise(false);
|
||||
removeMessage(messageToRemove: Message): void {
|
||||
const currentMessages = this.messagesSubject.value;
|
||||
this.messagesSubject.next(currentMessages.filter(msg => msg !== messageToRemove));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user