Refactor save! saving... saved! truth table to single string :D

This commit is contained in:
Kristóf Tóth 2018-02-09 14:59:10 +01:00
parent d0a35b53d3
commit 13e60e5d98
2 changed files with 13 additions and 19 deletions

View File

@ -3,12 +3,13 @@
class="btn btn-secondary"
[class.active]="filename === file"
[class.disabled]="filename === file"
(click)="selectCode(file); requestCode()">
(click)="selectCode(file); requestCode()"
[disabled]="filename === file">
{{file}}
</button>
</div>
<div (textChanged)="saved = false"
<div (textChanged)="saveButtonState = 'DIRTY'"
ace-editor
[(text)]="code"
[(mode)]="language"
@ -18,17 +19,12 @@
</div>
<button (click)="sendCode()"
[disabled]="saving === true"
[disabled]="saveButtonState === 'SAVING'"
type="submit"
class="btn btn-secondary"
[class.btn-success]="saved === true"
[class.btn-warning]="saving === true"
[class.disabled]="saving === true"
><span *ngIf="saved === false && saving === false">Save</span>
<span *ngIf="saved === true && saving === false">Saved!</span>
<span *ngIf="saved === false && saving === true">Saving...</span></button>
<span *ngIf="saved === true">Saved</span>
<span *ngIf="saving === true">Saving</span>
<span *ngIf="saved === false">Not Saved</span>
<span *ngIf="saving === false">Not Saving</span>
[class.btn-success]="saveButtonState === 'SAVED'"
[class.btn-warning]="saveButtonState === 'SAVING'"
[class.disabled]="saveButtonState === 'SAVING'"
><span *ngIf="saveButtonState === 'DIRTY'">Save!</span>
<span *ngIf="saveButtonState === 'SAVED'">Saved!</span>
<span *ngIf="saveButtonState === 'SAVING'">Saving...</span></button>

View File

@ -20,8 +20,7 @@ export class WebideComponent implements OnInit {
language = 'javascript';
theme = 'monokai';
files: string[];
saved = false;
saving = false;
saveButtonState = 'DIRTY';
constructor(private webSocketService: WebSocketService) { }
@ -31,7 +30,7 @@ export class WebideComponent implements OnInit {
this.code = event.data.content;
this.language = event.data.language;
this.files = event.data.files;
if (event.data.command === 'write') { this.saved = true; this.saving = false; }
if (event.data.command === 'write') { this.saveButtonState = 'SAVED'; }
});
this.requestCode();
}
@ -41,8 +40,7 @@ export class WebideComponent implements OnInit {
'command': 'write',
'content': this.code
});
this.saving = true;
this.saved = false;
this.saveButtonState = 'SAVING';
}
requestCode() {