aboutsummaryrefslogtreecommitdiff
path: root/src/view/timer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/timer.ts')
-rw-r--r--src/view/timer.ts34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/view/timer.ts b/src/view/timer.ts
index ddcea71..061f5d4 100644
--- a/src/view/timer.ts
+++ b/src/view/timer.ts
@@ -7,6 +7,8 @@ import h from 'h'
let interval: number | undefined = undefined
+const endDuration: number = 4
+
export function clearInterval() {
if (interval !== undefined) {
window.clearInterval(interval)
@@ -27,21 +29,22 @@ export function view(config: Config.Config, showPage: (route: Router.Route) => v
// Elements
const section = h('section', { className: timerClass(state.step) })
const stepElt = document.createTextNode(State.prettyPrintStep(state.step))
- const stepCountElt = document.createTextNode(stepCount(state))
+ const stepInfoElt = document.createTextNode(state.info)
const arcPathElt = h('path', { class: 'g-Timer__ArcProgress' })
const updateDom = () => {
- const angle = elapsed / duration * 360
+ const angle = Math.min(359.999, elapsed / duration * 360)
arcPathElt.setAttribute("d", Arc.describe(0, 0, 90, 0, angle))
section.className = timerClass(state.step)
stepElt.textContent = State.prettyPrintStep(state.step)
- stepCountElt.textContent = stepCount(state)
+ stepInfoElt.textContent = state.info
Audio.playFromStep(config, state)
}
const quit = () => {
const formRoute = { kind: Router.Kind.Form, config }
history.pushState({}, '', Router.toString(formRoute))
+ clearInterval()
showPage(formRoute)
}
@@ -49,7 +52,7 @@ export function view(config: Config.Config, showPage: (route: Router.Route) => v
if (isPlaying) {
elapsed = elapsed + 1
state = State.getAt(config, elapsed)
- elapsed > duration
+ elapsed >= duration + endDuration
? quit()
: updateDom()
}
@@ -62,6 +65,9 @@ export function view(config: Config.Config, showPage: (route: Router.Route) => v
}
interval = window.setInterval(update, 1000)
+ // Play initial audio
+ Audio.playFromStep(config, state)
+
section.append(
h('div',
{ className: 'g-Timer__Dial' },
@@ -78,7 +84,7 @@ export function view(config: Config.Config, showPage: (route: Router.Route) => v
arcPathElt
),
h('div', { className: 'g-Timer__Step' }, stepElt),
- h('div', {}, stepCountElt)
+ h('div', {}, stepInfoElt)
),
h('div',
{ className: 'g-Timer__Buttons' },
@@ -128,6 +134,10 @@ function arcPaths(config: Config.Config): Element[] {
)
}
+ if (config.warmup > 0) {
+ paths.push(arc('WarmUp', config.warmup))
+ }
+
for (let tabata = 0; tabata < config.tabatas; tabata++) {
paths.push(arc('Prepare', config.prepare))
for (let cycle = 0; cycle < config.cycles; cycle++) {
@@ -140,19 +150,15 @@ function arcPaths(config: Config.Config): Element[] {
}
function timerClass(step: State.Step): string {
- if (step === State.Step.Work) {
+ if (step === State.Step.WarmUp) {
+ return 'g-Layout__Page g-Timer g-Timer--WarmUp'
+ } else if (step === State.Step.Work) {
return 'g-Layout__Page g-Timer g-Timer--Work'
} else if (step === State.Step.Rest) {
return 'g-Layout__Page g-Timer g-Timer--Rest'
- } else {
+ } else if (step === State.Step.Prepare) {
return 'g-Layout__Page g-Timer g-Timer--Prepare'
- }
-}
-
-function stepCount(state: State.State): string {
- if (state.step === State.Step.Work || state.step === State.Step.Rest) {
- return `#${state.tabata.toString()}.${state.cycle.toString()}`
} else {
- return `#${state.tabata.toString()}`
+ return 'g-Layout__Page g-Timer'
}
}