Show timer edits immediately upon saving
This commit is contained in:
parent
a5b40f710d
commit
b3777d57ec
4 changed files with 28 additions and 5 deletions
|
@ -94,7 +94,7 @@ export class ActiveTimer extends LitElement {
|
|||
}
|
||||
|
||||
updated() {
|
||||
if (!this.timerState || this.timerState.timer.id !== this.timer.id) {
|
||||
if (!this.timerState || this.timerState.timer !== this.timer) {
|
||||
this.timerState = new TimerState(this.timer, () => this.requestUpdate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { LitElement, css, html } from 'lit';
|
|||
import { property, customElement, query } from 'lit/decorators.js';
|
||||
import { durationString, IntervalTimer, parseDuration } from '../timer';
|
||||
import { TimerService } from '../timer-service';
|
||||
import { TimerSavedEvent } from '../timer-saved-event';
|
||||
|
||||
@customElement('timer-form-dialog')
|
||||
export class TimerFormDialog extends LitElement {
|
||||
|
@ -119,6 +120,7 @@ export class TimerFormDialog extends LitElement {
|
|||
this.saving = false;
|
||||
// TODO: Clear form
|
||||
this.toggleVisibility();
|
||||
document.dispatchEvent(new TimerSavedEvent(id))
|
||||
}
|
||||
|
||||
private async delete() {
|
||||
|
|
|
@ -36,11 +36,18 @@ export class AppHome extends LitElement {
|
|||
timerServiceSingleton()
|
||||
.then(async timerService => {
|
||||
this.timerService = timerService;
|
||||
this.timers = await timerService.getAll();
|
||||
if (!this.selectedTimer) {
|
||||
this.selectedTimer = this.timers[0]?.id;
|
||||
}
|
||||
this.loadTimers()
|
||||
});
|
||||
document.addEventListener('timersaved', () => {
|
||||
this.loadTimers()
|
||||
})
|
||||
}
|
||||
|
||||
private async loadTimers() {
|
||||
this.timers = await this.timerService?.getAll() || [];
|
||||
if (!this.selectedTimer) {
|
||||
this.selectedTimer = this.timers[0]?.id;
|
||||
}
|
||||
}
|
||||
|
||||
private async closeEditor() {
|
||||
|
|
14
src/script/timer-saved-event.ts
Normal file
14
src/script/timer-saved-event.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export class TimerSavedEvent extends Event {
|
||||
timerId?: number;
|
||||
|
||||
constructor(timerId?: string) {
|
||||
super(
|
||||
'timersaved',
|
||||
{
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}
|
||||
);
|
||||
this.timerId = timerId ? Number.parseInt(timerId) : undefined;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue