Skip to content

Commit dcbd6cd

Browse files
authored
fix missing permanent snackbars (#12)
* fix missing permanent snackbars * rearrange timeout and button args, make timeout defaults more sensible * convert mat snack bar -> snackbar service, update extant snackbar service calls
1 parent da9a643 commit dcbd6cd

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

src/@seed/api/organization/organization.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class OrganizationService {
7575
this._userService.getCurrentUser().subscribe()
7676
}),
7777
map(() => {
78-
this._snackBar.success('Organization Settings Updated', 'OK', true, 3000)
78+
this._snackBar.success('Organization Settings Updated')
7979
this.getById(org.id).subscribe((o) => {
8080
return of(o)
8181
})

src/app/core/snackbar/snackbar.service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { MatSnackBar } from '@angular/material/snack-bar'
55
export class SnackbarService {
66
private _snackBar = inject(MatSnackBar)
77

8-
alert(message: string, button = 'OK', timeout = false, timeoutLength = 3000) {
8+
alert(message: string, timeout = false, button = 'OK', timeoutLength = 3000) {
99
this._displaySnackBar(message, button, 'alert', timeout, timeoutLength)
1010
}
1111

12-
warning(message: string, button = 'OK', timeout = false, timeoutLength = 3000) {
12+
warning(message: string, timeout = true, button = 'OK', timeoutLength = 3000) {
1313
this._displaySnackBar(message, button, 'warning', timeout, timeoutLength)
1414
}
1515

16-
success(message: string, button = 'OK', timeout = false, timeoutLength = 3000) {
16+
success(message: string, timeout = true, button = 'OK', timeoutLength = 3000) {
1717
this._displaySnackBar(message, button, 'success', timeout, timeoutLength)
1818
}
1919

20-
info(message: string, button = 'OK', timeout = false, timeoutLength = 3000) {
20+
info(message: string, timeout = true, button = 'OK', timeoutLength = 3000) {
2121
this._displaySnackBar(message, button, 'info', timeout, timeoutLength)
2222
}
2323

@@ -26,6 +26,10 @@ export class SnackbarService {
2626
this._snackBar.open(message, button,
2727
{ panelClass: `soft-${css_class}-snackbar`, duration: timeoutLength, horizontalPosition: 'center', verticalPosition: 'top' },
2828
)
29+
} else {
30+
this._snackBar.open(message, button,
31+
{ panelClass: `soft-${css_class}-snackbar`, horizontalPosition: 'center', verticalPosition: 'top' },
32+
)
2933
}
3034
}
3135
}

src/app/modules/organizations/cycles/modal/delete-modal.component.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/materia
88
import { MatFormFieldModule } from '@angular/material/form-field'
99
import { MatInputModule } from '@angular/material/input'
1010
import { MatProgressBarModule } from '@angular/material/progress-bar'
11-
import { MatSnackBar } from '@angular/material/snack-bar'
1211
import { catchError, throwError } from 'rxjs'
1312
import type { Cycle } from '@seed/api/cycle'
1413
import { CycleService } from '@seed/api/cycle/cycle.service'
1514
import { AlertComponent } from '@seed/components'
1615
import { UploaderService } from '@seed/services/uploader/uploader.service'
1716
import type { ProgressBarObj } from '@seed/services/uploader/uploader.types'
17+
import { SnackbarService } from 'app/core/snackbar/snackbar.service'
1818

1919
@Component({
2020
selector: 'seed-cycles-delete-modal',
@@ -35,7 +35,7 @@ import type { ProgressBarObj } from '@seed/services/uploader/uploader.types'
3535
export class DeleteModalComponent {
3636
private _cycleService = inject(CycleService)
3737
private _uploaderService = inject(UploaderService)
38-
private _snackBar = inject(MatSnackBar)
38+
private _snackBar = inject(SnackbarService)
3939
private _dialogRef = inject(MatDialogRef<DeleteModalComponent>)
4040
errorMessage: string
4141
inProgress = false
@@ -90,19 +90,11 @@ export class DeleteModalComponent {
9090
}
9191

9292
close(message: string) {
93-
this.openSnackBar(`Deleted Cycle ${this.data.cycle.name}`)
93+
this._snackBar.success(`Deleted Cycle ${this.data.cycle.name}`)
9494
this._dialogRef.close(message)
9595
}
9696

9797
dismiss() {
9898
this._dialogRef.close()
9999
}
100-
101-
openSnackBar(message: string) {
102-
this._snackBar.open(message, null, {
103-
verticalPosition: 'top',
104-
duration: 2000,
105-
panelClass: 'soft-success-snackbar',
106-
})
107-
}
108100
}

src/app/modules/organizations/cycles/modal/form-modal.component.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { MatDatepickerModule } from '@angular/material/datepicker'
88
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'
99
import { MatFormFieldModule } from '@angular/material/form-field'
1010
import { MatInputModule } from '@angular/material/input'
11-
import { MatSnackBar } from '@angular/material/snack-bar'
1211
import type { Cycle, CycleResponse } from '@seed/api/cycle'
1312
import { CycleService } from '@seed/api/cycle/cycle.service'
1413
import { SEEDValidators } from '@seed/validators'
14+
import { SnackbarService } from 'app/core/snackbar/snackbar.service'
1515

1616
// configure the datepicker to display 01/01/2000 instead of January 1, 2000
1717
export const MY_DATE_FORMATS = {
@@ -44,7 +44,7 @@ export const MY_DATE_FORMATS = {
4444
})
4545
export class FormModalComponent implements OnInit {
4646
private _cycleService = inject(CycleService)
47-
private _snackBar = inject(MatSnackBar)
47+
private _snackBar = inject(SnackbarService)
4848
private _datePipe = inject(DatePipe)
4949
private _dialogRef = inject(MatDialogRef<FormModalComponent>)
5050

@@ -83,7 +83,7 @@ export class FormModalComponent implements OnInit {
8383
close(response: CycleResponse) {
8484
const message = this.create ? `Created Cycle ${response.cycles.name}` : `Updated Cycle ${response.cycles.name}`
8585
if (response.status === 'success') {
86-
this.openSnackBar(message)
86+
this._snackBar.success(message)
8787
}
8888
this._dialogRef.close(response)
8989
}
@@ -92,14 +92,6 @@ export class FormModalComponent implements OnInit {
9292
this._dialogRef.close('dismiss')
9393
}
9494

95-
openSnackBar(message: string) {
96-
this._snackBar.open(message, null, {
97-
verticalPosition: 'top',
98-
duration: 2000,
99-
panelClass: 'soft-success-snackbar',
100-
})
101-
}
102-
10395
private _formatDates() {
10496
this.form.value.start = this._datePipe.transform(this.form.value.start, 'yyyy-MM-dd')
10597
this.form.value.end = this._datePipe.transform(this.form.value.end, 'yyyy-MM-dd')

src/app/modules/organizations/settings/options/options.component.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Subject, takeUntil } from 'rxjs'
1010
import { type Organization, OrganizationService } from '@seed/api/organization'
1111
import { type Alert, AlertComponent } from '@seed/components'
1212
import { SharedImports } from '@seed/directives'
13-
import { SnackbarService } from 'app/core/snackbar/snackbar.service'
1413

1514
@Component({
1615
selector: 'seed-organizations-settings-options',
@@ -30,7 +29,6 @@ import { SnackbarService } from 'app/core/snackbar/snackbar.service'
3029
export class OptionsComponent implements OnInit, OnDestroy {
3130
private _organizationService = inject(OrganizationService)
3231
private readonly _unsubscribeAll$ = new Subject<void>()
33-
private _snackBar = inject(SnackbarService)
3432
organization: Organization
3533
alert: Alert
3634
fields: string[] = ['name', 'geocoding_enabled', 'comstock_enabled', 'public_feed_enabled']

0 commit comments

Comments
 (0)