Opzet businesslogica opzetten focus-stats

This commit is contained in:
2024-11-26 20:56:43 +01:00
parent a168fa31c0
commit 7c457ba8c7
5 changed files with 143 additions and 80 deletions

View File

@@ -2,6 +2,7 @@ import {Component, OnDestroy, OnInit, Renderer2} from "@angular/core";
import {IonBreadcrumb, IonBreadcrumbs, IonButton, IonContent, IonIcon, IonProgressBar} from "@ionic/angular/standalone";
import {TushaPageComponent} from "../../../tusha/tusha-page/tusha-page.component";
import {FocusState} from "./focus-state";
import {FocusService} from "./focus.service";
@Component({
templateUrl: 'focus.component.html',
@@ -16,6 +17,7 @@ export class FocusPage implements OnInit, OnDestroy {
private interval: number | undefined;
private timerStarted: number | null = null;
state: FocusState = FocusState.STOPPED;
private focusRuns = 0;
private endOfTimerChime: HTMLAudioElement;
@@ -23,7 +25,7 @@ export class FocusPage implements OnInit, OnDestroy {
dashOffset = 0;
constructor(private renderer: Renderer2) {
constructor(private renderer: Renderer2, private focusService: FocusService) {
this.endOfTimerChime = new Audio('../../../assets/race-start-beeps-125125.mp3');
}
@@ -62,6 +64,7 @@ export class FocusPage implements OnInit, OnDestroy {
console.error('Error playing audio:', error);
});
clearInterval(this.interval);
this.timerStarted = null;
}
this.renderer.setStyle(
@@ -87,10 +90,24 @@ export class FocusPage implements OnInit, OnDestroy {
}
startWhereWeAre() {
this.startTimer(25);
switch (this.state) {
case FocusState.FOCUS:
this.focusRuns++;
if (this.focusRuns > 3) {
this.focusRuns = 0;
this.recharge();
} else {
this.reload();
}
break;
default:
this.focus();
break;
}
}
stopTimer() {
this.focusRuns = 0;
this.state = FocusState.STOPPED;
this.startTimer(0);
}
@@ -101,11 +118,17 @@ export class FocusPage implements OnInit, OnDestroy {
}
reload() {
if (!!this.timerStarted) {
this.focusRuns = 0;
}
this.state = FocusState.SHORT_BREAK;
this.startTimer(0.5);
this.startTimer(5);
}
recharge() {
if (!!this.timerStarted) {
this.focusRuns = 0;
}
this.state = FocusState.LONG_BREAK;
this.startTimer(15);
}