Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions frontend/src/components/RestTimer.dock.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import RestTimer, { applyRestLeft } from './RestTimer.jsx'
import RestTimer, { adjustRestSheet, applyRestLeft } from './RestTimer.jsx'
import { useUI } from '../store/useUI.js'
import { useStore } from '../store/useStore.js'

Expand Down Expand Up @@ -42,7 +42,7 @@ const sheetHost = () => {
return { el, r }
}

// v1.3.11: one docked row; the clock is a button that opens the wheel at the time left.
// v1.3.11: one docked row; the clock is a button (it opens the rest full screen, RestTimer.full.test.jsx).
describe('the docked rest bar', () => {
it('is one row: the clock with its label, then −15, +15, pause and Skip', () => {
act(() => useUI.getState().startRest(90, 0))
Expand All @@ -52,7 +52,7 @@ describe('the docked rest bar', () => {
expect(bar.querySelector('.tclock .lbl').textContent).toBe('Rest')
expect([...bar.querySelectorAll('.acts > button')].map(b => b.getAttribute('aria-label') || (b.querySelector('.on') || b).textContent.trim()))
.toEqual(['15s', '15s', 'Pause', 'Skip'])
expect(bar.querySelector('.tclock').getAttribute('aria-label')).toBe('1:30. Change the time left')
expect(bar.querySelector('.tclock').getAttribute('aria-label')).toBe('1:30. Expand')
})

// QA 10-05: Ready used to drop the pause button and reflow the row, so the spot +15 had been
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('the docked rest bar', () => {
act(() => useUI.getState().startRest(90, 3))
mount()
act(() => vi.advanceTimersByTime(10_000))
act(() => host.querySelector('#timer .tclock').click())
act(() => adjustRestSheet())
const { el, r } = sheetHost()
expect(el.querySelector('h3').textContent).toBe('Time left')
expect(el.querySelector('.dw-read').textContent).toBe('1:20')
Expand All @@ -137,7 +137,7 @@ describe('the docked rest bar', () => {
// still counting: the seconds that passed while the wheel was open are not given back
act(() => useUI.getState().startRest(60, 0))
mount()
act(() => host.querySelector('#timer .tclock').click())
act(() => adjustRestSheet())
act(() => vi.advanceTimersByTime(10_000))
let { el, r } = sheetHost()
act(() => { [...el.querySelectorAll('button')].find(b => b.textContent === 'Done').click() })
Expand All @@ -146,7 +146,7 @@ describe('the docked rest bar', () => {

// ran out meanwhile: no fresh rest nobody asked for
act(() => useUI.getState().startRest(5, 2))
act(() => host.querySelector('#timer .tclock').click())
act(() => adjustRestSheet())
act(() => vi.advanceTimersByTime(5000))
expect(useUI.getState().timer.ready).toBe(true);
({ el, r } = sheetHost())
Expand All @@ -156,7 +156,7 @@ describe('the docked rest bar', () => {

// a switch-sides pause that ended does not turn into a plain rest
act(() => useUI.getState().startRest(5, 1, { kind: 'switch' }))
act(() => host.querySelector('#timer .tclock').click())
act(() => adjustRestSheet())
act(() => vi.advanceTimersByTime(5000))
expect(useUI.getState().timer).toBeNull();
({ el, r } = sheetHost())
Expand Down
116 changes: 116 additions & 0 deletions frontend/src/components/RestTimer.full.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// @vitest-environment happy-dom
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import RestTimer from './RestTimer.jsx'
import { useUI } from '../store/useUI.js'
import { useStore } from '../store/useStore.js'

globalThis.IS_REACT_ACT_ENVIRONMENT = true

vi.mock('../lib/sound.js', () => ({ beep: vi.fn(), chime: vi.fn(), vibrate: vi.fn(), alertBuzz: vi.fn() }))

let host, root, sheetEl, sheetRoot, originalS

beforeEach(() => {
vi.useFakeTimers()
originalS = useStore.getState().S
useStore.setState({ S: { ...originalS, sound: false } })
useUI.setState({ timer: null, work: null, timerFlashId: 0, sheets: [] })
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
sheetEl = document.createElement('div')
document.body.appendChild(sheetEl)
sheetRoot = createRoot(sheetEl)
})

afterEach(() => {
act(() => { root.render(null); sheetRoot.render(null) })
useUI.getState().stopRest()
useUI.getState().stopWork()
useUI.setState({ sheets: [] })
useStore.setState({ S: originalS })
host.remove(); sheetEl.remove()
vi.useRealTimers()
})

// The open sheets, rendered the way Modals.jsx renders them, so a sheet that closes itself leaves.
function Sheets() {
const sheets = useUI(s => s.sheets)
return sheets.map(s => <div key={s.id} data-kind={s.kind}>{s.render(() => useUI.getState().closeSheet(s.id))}</div>)
}
const mount = () => act(() => { root.render(<RestTimer />); sheetRoot.render(<Sheets />) })
const full = () => sheetEl.querySelector('.restfull')
const tapClock = () => act(() => host.querySelector('#timer .tclock').click())

describe('the rest, full screen', () => {
it('opens from the bar\'s clock as a viewer, and counts down with the bar', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
tapClock()
expect(useUI.getState().sheets.map(s => s.kind)).toEqual(['viewer'])
expect(full().querySelector('.restfull-clock .t').textContent).toBe('1:30')
expect(full().querySelector('.restfull-clock').getAttribute('aria-label')).toBe('1:30. Change the time left')
act(() => vi.advanceTimersByTime(10_000))
expect(full().querySelector('.restfull-clock .t').textContent).toBe('1:20')
expect(host.querySelector('#timer .t').textContent).toBe('1:20')
})

it('its buttons work the rest: −15, pause, +15', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
tapClock()
const btn = sel => full().querySelector(sel)
act(() => btn('.adj').click())
expect(useUI.getState().timer.left).toBe(75)
act(() => btn('.pause').click())
expect(useUI.getState().timer.paused).toBe(true)
expect(full().classList.contains('paused')).toBe(true)
act(() => btn('.pause').click())
expect(useUI.getState().timer.paused).toBeFalsy()
act(() => full().querySelectorAll('.adj')[1].click())
expect(useUI.getState().timer.left).toBe(90)
})

it('the big clock opens the wheel on top of it', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
tapClock()
act(() => full().querySelector('.restfull-clock').click())
expect(useUI.getState().sheets.map(s => s.kind)).toEqual(['viewer', 'sheet'])
expect(sheetEl.querySelector('[data-kind="sheet"] h3').textContent).toBe('Time left')
})

it('Skip ends the rest and closes the view', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
tapClock()
act(() => full().querySelector('.restfull-skip .btn').click())
expect(useUI.getState().timer).toBeNull()
expect(useUI.getState().sheets).toEqual([])
expect(full()).toBeNull()
})

it('stays open at Ready, with Dismiss and no pause', () => {
act(() => useUI.getState().startRest(2, 0))
mount()
tapClock()
act(() => vi.advanceTimersByTime(2000))
expect(useUI.getState().timer.ready).toBe(true)
expect(full().classList.contains('ready')).toBe(true)
expect(full().querySelector('.restfull-clock .t').textContent).toBe('Ready')
expect(full().querySelector('.pause')).toBeNull()
expect(full().querySelector('.restfull-skip .btn').textContent).toBe('Dismiss')
})

it('Minimize goes back to the bar, the rest still running', () => {
act(() => useUI.getState().startRest(90, 0))
mount()
tapClock()
act(() => full().querySelector('.restfull-bar .iconbtn').click())
expect(useUI.getState().sheets).toEqual([])
expect(useUI.getState().timer.left).toBe(90)
expect(host.querySelector('#timer.rest')).not.toBeNull()
})
})
57 changes: 54 additions & 3 deletions frontend/src/components/RestTimer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SeasonDeco } from './Seasonal.jsx'

const clock = sec => Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '0')

// The clock is a button: a tap opens the wheel at the time that is left, for a rest that wants
// The full-screen clock is a button (the bar's own clock opens full screen, openRestFull below):
// a tap opens the wheel at the time that is left, for a rest that wants
// to be a round 2:00 rather than eight taps of +15. 0:00 ends the rest, like Skip. What is left
// is read again at Done, since the rest kept counting while the wheel was open. Done on a wheel
// nobody turned changes nothing: the rest keeps the seconds it counted down meanwhile, and one
Expand Down Expand Up @@ -37,6 +38,56 @@ export function applyRestLeft(v, opened) {
if (v !== now.left) ui.addRest(v - now.left)
}

// The rest, full screen: the bar's clock opens it, for a rest read from across the room or with
// the phone propped on a bench. A viewer sheet (Modals.jsx), so Android back closes it like any
// sheet. The big clock is where the wheel moved to, the same buttons sit under it, and it closes
// itself once there is no rest left to show (Skip, 0:00 on the wheel, a timed set starting).
export function openRestFull() {
if (!useUI.getState().timer) return
useUI.getState().openSheet(close => <RestTimerFull close={close} />, { kind: 'viewer' })
}

const RING = 2 * Math.PI * 46

function RestTimerFull({ close }) {
const timer = useUI(s => s.timer)
const work = useUI(s => s.work)
const { addRest, skipRest, pauseRest, resumeRest } = useUI.getState()
const gone = !timer || !!work
useEffect(() => { if (gone) close() }, [gone])
if (gone) return null
const pct = Math.max(0, Math.min(1, (timer.left ?? timer.total) / timer.total))
const label = timer.kind === 'switch' ? t('Switch sides') : timer.paused ? t('Paused') : t('Rest')
return (
<div className={'restfull' + (timer.paused ? ' paused' : '') + (timer.ready ? ' ready' : '')}>
<div className="restfull-bar">
<button type="button" className="iconbtn" aria-label={t('Minimize')} onClick={close}><Icon name="chevronDown" /></button>
</div>
<div className="restfull-stage">
<button type="button" className="restfull-clock" onClick={adjustRestSheet}
aria-label={(timer.ready ? t('Ready') : clock(timer.left)) + '. ' + t('Change the time left')}>
<svg viewBox="0 0 100 100" aria-hidden="true">
<circle className="track" cx="50" cy="50" r="46" />
<circle className="prog" cx="50" cy="50" r="46" strokeDasharray={RING} strokeDashoffset={RING * (1 - pct)} />
</svg>
<span className="t" role={timer.ready ? 'status' : undefined}>{timer.ready ? t('Ready') : clock(timer.left)}</span>
<span className="lbl">{label}</span>
</button>
</div>
<div className="restfull-acts">
<Button className="adj" icon="minus" onClick={() => addRest(-15)}>15s</Button>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{!timer.ready && <Button className="pause" icon={timer.paused ? 'play' : 'pause'}
aria-label={t(timer.paused ? 'Resume' : 'Pause')} aria-pressed={!!timer.paused}
onClick={timer.paused ? resumeRest : pauseRest} />}
<Button className="adj" icon="plus" disabled={!timer.ready && timer.left >= REST_MAX} onClick={() => addRest(15)}>15s</Button>
</div>
<div className="restfull-skip">
<Button variant="primary" onClick={() => skipRest()}>{t(timer.ready ? 'Dismiss' : 'Skip')}</Button>
</div>
</div>
)
}

// One bar, two meanings: the rest countdown between sets, and the work countdown during a
// timed set (issue #16). They are mutually exclusive by construction — startWork() stops any
// running rest — so the bar can never have to show both, and a work set gets its own colour
Expand Down Expand Up @@ -164,8 +215,8 @@ export default function RestTimer() {
<div id="timer" data-tour="rest" className={'rest' + (timer.paused ? ' paused' : '') + (timer.kind === 'switch' ? ' switch' : '') + (timer.ready ? ' ready' : '') + (autoNext ? ' auto' : '')}>
<div className="bar" aria-hidden="true"><i style={{ transform: `scaleX(${pct / 100})` }} /></div>
<SeasonDeco spot="rest-timer" workout />
<button type="button" className="tclock" onClick={adjustRestSheet}
aria-label={(timer.ready ? t('Ready') : clock(timer.left)) + '. ' + t('Change the time left')}>
<button type="button" className="tclock" onClick={openRestFull}
aria-label={(timer.ready ? t('Ready') : clock(timer.left)) + '. ' + t('Expand')}>
<span className="t" role={timer.ready ? 'status' : undefined} data-alt={timer.ready ? '0:00' : t('Ready')}>{timer.ready ? t('Ready') : clock(timer.left)}</span>
<span className="lbl">{label}<Icon name="chevronDown" /></span>
</button>
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,33 @@ body.no-tabbar #timer.countin{box-shadow:inset 0 var(--hair) 0 var(--acc),0 -10p
#timer.countin .t{font-size:34px}
}

/* The rest, full screen (RestTimer.jsx openRestFull): a viewer sheet, so it covers the page and
the bar. The clock sits in a ring that empties as the rest runs out, sized off the shorter side
so it fits a phone held either way; the buttons are big, for a thumb between sets. */
.restfull{
position:absolute;inset:0;background:var(--bg);color:var(--label);display:flex;flex-direction:column;
padding:var(--sat) 16px calc(16px + var(--sab));animation:pop-fade .2s var(--ease);
}
.restfull-bar{display:flex;justify-content:flex-start;padding:6px 0;flex:none}
.restfull-stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center}
.restfull-clock{
position:relative;width:min(78vw,52vh,420px);aspect-ratio:1;border-radius:50%;
display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;color:inherit;
}
.restfull-clock svg{position:absolute;inset:0;width:100%;height:100%;transform:rotate(-90deg)}
.restfull-clock circle{fill:none;stroke-width:4}
.restfull-clock .track{stroke:var(--surface-3)}
.restfull-clock .prog{stroke:var(--acc);stroke-linecap:round;transition:stroke-dashoffset 1s linear}
.restfull-clock .t{position:relative;font-size:min(20vw,13vh,104px);font-weight:600;line-height:1;letter-spacing:-.03em;font-variant-numeric:tabular-nums;white-space:nowrap}
.restfull-clock .lbl{position:relative;font-size:17px;color:var(--label-2)}
.restfull.ready .t{color:var(--acc-ink);font-size:min(14vw,9vh,72px)}
.restfull.paused .t,.restfull.paused .prog{opacity:.5}
.restfull-acts{display:flex;justify-content:center;gap:12px;flex:none;padding-bottom:12px}
.restfull-acts .btn{min-height:56px;min-width:72px;padding-inline:18px}
.restfull-skip{display:flex;flex:none}
.restfull-skip .btn{flex:1;min-height:56px}
@media (min-width:600px){.restfull-skip{justify-content:center}.restfull-skip .btn{flex:0 1 360px}}

/* ---------------------------------------------------------------- modal -- */
#modal-root{position:fixed;inset:0;z-index:100;display:none}
#modal-root.open{display:block}
Expand Down
Loading