Feature: compact toasts (#4545)

This commit is contained in:
shamoon
2023-11-13 13:17:44 -08:00
committed by GitHub
parent ab9e561317
commit 0f3f4ed0e7
9 changed files with 127 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
import { Component, OnDestroy, OnInit } from '@angular/core'
import { Subscription } from 'rxjs'
import { Subscription, interval, take } from 'rxjs'
import { Toast, ToastService } from 'src/app/services/toast.service'
import { Clipboard } from '@angular/cdk/clipboard'
@@ -20,6 +20,8 @@ export class ToastsComponent implements OnInit, OnDestroy {
public copied: boolean = false
public seconds: number = 0
ngOnDestroy(): void {
this.subscription?.unsubscribe()
}
@@ -37,6 +39,20 @@ export class ToastsComponent implements OnInit, OnDestroy {
})
}
onShow(toast: Toast) {
const refreshInterval = 150
const delay = toast.delay - 500 // for fade animation
interval(refreshInterval)
.pipe(take(delay / refreshInterval))
.subscribe((count) => {
toast.delayRemaining = Math.max(
0,
delay - refreshInterval * (count + 1)
)
})
}
public isDetailedError(error: any): boolean {
return (
typeof error === 'object' &&