Feature/refactor snack bars (#4273)

* Refactor snack bars
This commit is contained in:
Thomas Kaul 2025-02-02 14:48:07 +01:00 committed by GitHub
parent 14cb0c98ce
commit 9ab21508a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 18 deletions

View File

@ -14,6 +14,7 @@ import {
} from '@angular/core'; } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import ms from 'ms';
@Component({ @Component({
selector: 'gf-access-table', selector: 'gf-access-table',
@ -64,7 +65,7 @@ export class AccessTableComponent implements OnChanges {
'✅ ' + $localize`Link has been copied to the clipboard`, '✅ ' + $localize`Link has been copied to the clipboard`,
undefined, undefined,
{ {
duration: 3000 duration: ms('3 seconds')
} }
); );
} }

View File

@ -12,11 +12,7 @@ import {
Component, Component,
OnDestroy OnDestroy
} from '@angular/core'; } from '@angular/core';
import { import { MatSnackBar } from '@angular/material/snack-bar';
MatSnackBar,
MatSnackBarRef,
TextOnlySnackBar
} from '@angular/material/snack-bar';
import ms, { StringValue } from 'ms'; import ms, { StringValue } from 'ms';
import { StripeService } from 'ngx-stripe'; import { StripeService } from 'ngx-stripe';
import { EMPTY, Subject } from 'rxjs'; import { EMPTY, Subject } from 'rxjs';
@ -41,7 +37,6 @@ export class UserAccountMembershipComponent implements OnDestroy {
public price: number; public price: number;
public priceId: string; public priceId: string;
public routerLinkPricing = ['/' + $localize`:snake-case:pricing`]; public routerLinkPricing = ['/' + $localize`:snake-case:pricing`];
public snackBarRef: MatSnackBarRef<TextOnlySnackBar>;
public trySubscriptionMail = public trySubscriptionMail =
'mailto:hi@ghostfol.io?Subject=Ghostfolio Premium Trial&body=Hello%0D%0DI am interested in Ghostfolio Premium. Can you please send me a coupon code to try it for some time?%0D%0DKind regards'; 'mailto:hi@ghostfol.io?Subject=Ghostfolio Premium Trial&body=Hello%0D%0DI am interested in Ghostfolio Premium. Can you please send me a coupon code to try it for some time?%0D%0DKind regards';
public user: User; public user: User;
@ -186,22 +181,22 @@ export class UserAccountMembershipComponent implements OnDestroy {
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
) )
.subscribe(() => { .subscribe(() => {
this.snackBarRef = this.snackBar.open( const snackBarRef = this.snackBar.open(
'✅ ' + $localize`Coupon code has been redeemed`, '✅ ' + $localize`Coupon code has been redeemed`,
$localize`Reload`, $localize`Reload`,
{ {
duration: 3000 duration: ms('3 seconds')
} }
); );
this.snackBarRef snackBarRef
.afterDismissed() .afterDismissed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {
window.location.reload(); window.location.reload();
}); });
this.snackBarRef snackBarRef
.onAction() .onAction()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {

View File

@ -25,6 +25,7 @@ import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { format, parseISO } from 'date-fns'; import { format, parseISO } from 'date-fns';
import { uniq } from 'lodash'; import { uniq } from 'lodash';
import ms from 'ms';
import { EMPTY, Subject, throwError } from 'rxjs'; import { EMPTY, Subject, throwError } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators'; import { catchError, takeUntil } from 'rxjs/operators';
@ -301,7 +302,9 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
this.snackBar.open( this.snackBar.open(
$localize`Oops! There was an error setting up biometric authentication.`, $localize`Oops! There was an error setting up biometric authentication.`,
undefined, undefined,
{ duration: 3000 } {
duration: ms('3 seconds')
}
); );
return throwError(() => { return throwError(() => {

View File

@ -19,6 +19,7 @@ import {
} from '@angular/material/snack-bar'; } from '@angular/material/snack-bar';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { StatusCodes } from 'http-status-codes'; import { StatusCodes } from 'http-status-codes';
import ms from 'ms';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators'; import { catchError, tap } from 'rxjs/operators';
@ -54,13 +55,17 @@ export class HttpResponseInterceptor implements HttpInterceptor {
' ' + ' ' +
$localize`Please try again later.`, $localize`Please try again later.`,
undefined, undefined,
{ duration: 6000 } {
duration: ms('6 seconds')
}
); );
} else if (!error.url.includes('/auth')) { } else if (!error.url.includes('/auth')) {
this.snackBarRef = this.snackBar.open( this.snackBarRef = this.snackBar.open(
$localize`This action is not allowed.`, $localize`This action is not allowed.`,
undefined, undefined,
{ duration: 6000 } {
duration: ms('6 seconds')
}
); );
} }
@ -79,7 +84,9 @@ export class HttpResponseInterceptor implements HttpInterceptor {
' ' + ' ' +
$localize`Please try again later.`, $localize`Please try again later.`,
$localize`Okay`, $localize`Okay`,
{ duration: 6000 } {
duration: ms('6 seconds')
}
); );
this.snackBarRef.afterDismissed().subscribe(() => { this.snackBarRef.afterDismissed().subscribe(() => {

View File

@ -23,6 +23,7 @@ import { MatStepper } from '@angular/material/stepper';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { AssetClass } from '@prisma/client'; import { AssetClass } from '@prisma/client';
import { isArray, sortBy } from 'lodash'; import { isArray, sortBy } from 'lodash';
import ms from 'ms';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, takeUntil } from 'rxjs'; import { Subject, takeUntil } from 'rxjs';
@ -133,7 +134,7 @@ export class ImportActivitiesDialog implements OnDestroy {
'✅ ' + $localize`Import has been completed`, '✅ ' + $localize`Import has been completed`,
undefined, undefined,
{ {
duration: 3000 duration: ms('3 seconds')
} }
); );
} catch (error) { } catch (error) {
@ -142,7 +143,9 @@ export class ImportActivitiesDialog implements OnDestroy {
' ' + ' ' +
$localize`Please try again later.`, $localize`Please try again later.`,
$localize`Okay`, $localize`Okay`,
{ duration: 3000 } {
duration: ms('3 seconds')
}
); );
} finally { } finally {
this.dialogRef.close(); this.dialogRef.close();

View File

@ -261,7 +261,9 @@ export class GfHistoricalMarketDataEditorComponent
this.snackBar.open( this.snackBar.open(
$localize`Oops! Could not parse historical data.`, $localize`Oops! Could not parse historical data.`,
undefined, undefined,
{ duration: ms('3 seconds') } {
duration: ms('3 seconds')
}
); );
} }
} }