-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Execute the send() operations without waiting for it, to give user much better UX.
- Loading branch information
Showing
9 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ export interface RecordEntry<T> { | |
record: Record; | ||
id: string; | ||
data: T; | ||
loading?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { UtilityService } from './utility.service'; | ||
|
||
describe('UtilityService', () => { | ||
let service: UtilityService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(UtilityService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { inject, Injectable } from '@angular/core'; | ||
import { AppService } from './app.service'; | ||
import { MatSnackBar } from '@angular/material/snack-bar'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class UtilityService { | ||
snackBar = inject(MatSnackBar); | ||
|
||
constructor() {} | ||
|
||
// executeAsyncWithoutWaiting(action: () => Promise<any>) { | ||
// action(); | ||
// } | ||
|
||
async executeAsyncWithToast(action: Promise<any>, successMessage?: string, errorMessage?: string) { | ||
try { | ||
await action; | ||
|
||
if (successMessage) { | ||
this.openSnackBar(successMessage); | ||
} | ||
} catch (error) { | ||
if (errorMessage) { | ||
this.openSnackBar(errorMessage); | ||
} else { | ||
this.openSnackBar(`Error: ${error}.`); | ||
} | ||
} | ||
} | ||
|
||
openSnackBar(message: string) { | ||
this.snackBar.open(message, undefined, { duration: 2000 }); | ||
} | ||
} |