mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
34 lines
955 B
TypeScript
34 lines
955 B
TypeScript
import { Component, Input } from '@angular/core'
|
|
import { ModalController } from '@ionic/angular'
|
|
import { defer, isObservable, Observable, of } from 'rxjs'
|
|
import { catchError, ignoreElements, share } from 'rxjs/operators'
|
|
|
|
import { getErrorMessage } from '../../services/error-toast.service'
|
|
|
|
@Component({
|
|
selector: 'markdown',
|
|
templateUrl: './markdown.component.html',
|
|
styleUrls: ['./markdown.component.scss'],
|
|
})
|
|
export class MarkdownComponent {
|
|
@Input() content?: string | Observable<string>
|
|
@Input() title = ''
|
|
|
|
private readonly data$ = defer(() =>
|
|
isObservable(this.content) ? this.content : of(this.content),
|
|
).pipe(share())
|
|
|
|
readonly error$ = this.data$.pipe(
|
|
ignoreElements(),
|
|
catchError(e => of(getErrorMessage(e))),
|
|
)
|
|
|
|
readonly content$ = this.data$.pipe(catchError(() => of([])))
|
|
|
|
constructor(private readonly modalCtrl: ModalController) {}
|
|
|
|
async dismiss() {
|
|
return this.modalCtrl.dismiss(true)
|
|
}
|
|
}
|