-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent UI updates when there is an unresolved recording in progress (#…
- Loading branch information
Showing
5 changed files
with
119 additions
and
22 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
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
39 changes: 39 additions & 0 deletions
39
src/angular-app/languageforge/lexicon/editor/recording-state.service.ts
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,39 @@ | ||
import * as angular from 'angular'; | ||
|
||
export class RecordingStateService { | ||
static $inject: string[] = ['$q']; | ||
|
||
private hasUnresolvedRecording = false; | ||
private uploads$: angular.IPromise<unknown>[] = []; | ||
|
||
constructor(private readonly $q: angular.IQService) { | ||
} | ||
|
||
startRecording(): boolean { | ||
if (this.hasUnresolvedRecording) { | ||
return false; | ||
} else { | ||
this.hasUnresolvedRecording = true; | ||
return true; | ||
} | ||
} | ||
|
||
resolveRecording(): void { | ||
this.hasUnresolvedRecording = false; | ||
} | ||
|
||
startUploading(upload: angular.IPromise<unknown>): void { | ||
this.uploads$.push(upload); | ||
upload.finally(() => | ||
this.uploads$ = this.uploads$.filter(_upload => _upload !== upload) | ||
); | ||
} | ||
|
||
uploading$(): angular.IPromise<unknown> { | ||
return this.$q.all(this.uploads$); | ||
} | ||
|
||
hasUnsavedChanges(): boolean { | ||
return this.hasUnresolvedRecording || this.uploads$.length > 0; | ||
} | ||
} |