Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

frontend+api: pin a coach session to a day

Boris Kurktchievbd2ec5e1d0b0
diff --git a/api/queue.js b/api/queue.js
index f01fe30d9..374372f4a 100644
--- a/api/queue.js
+++ b/api/queue.js
@@ -1,16 +1,28 @@
// Floating coach week — the "what's next" rule for web-push reminders. Hand-copied (not
-// imported) from frontend/src/lib/queue.js / lib/history.js: the same DONE RULE on both sides,
-// kept as a tiny standalone module here (rather than inline in server.js) so it can be
-// unit-tested without booting the whole server. `S.queue` is written by a planner — any API
-// client that PUTs state with a queue (a coaching agent, a script) — never by the app itself.
+// imported) from frontend/src/lib/queue.js / lib/history.js: the same rules on both sides, kept
+// as a tiny standalone module here (rather than inline in server.js) so it can be unit-tested
+// without booting the whole server. `S.queue` is written by a planner — any API client that PUTs
+// state with a queue (a coaching agent, a script) — never by the app itself. Three rules live here:
//
-// DONE RULE: a queue session counts as done once a finished workout on its routine exists,
-// started at/after the queue was applied (`S.queue.since`) — or a "past workout" logged with an
-// early clock but DATED inside the week (on or after `startsOn`) whose merged name (`'A + B'`)
-// names the routine under its current title. The date bound keeps a past week's workout, which
-// a planner's reused ids and names can make look identical, from counting. Only finished
-// workouts (`S.workouts`) count; an in-progress session never does. Missed sets are the
-// planner's business, not the queue's.
+// DONE RULE (shared with the frontend, and the rule a planner has to mirror): a queue session
+// counts as done once a finished workout on its routine exists, started at/after the queue was
+// applied (`S.queue.since`) — or a "past workout" logged with an early clock but DATED inside the
+// week (on or after `startsOn`) whose merged name (`'A + B'`) names the routine under its current
+// title. The date bound keeps a past week's workout, which a planner's reused ids and names can
+// make look identical, from counting. Only finished workouts (`S.workouts`) count; an in-progress
+// session never does. Missed sets are the planner's business, not the queue's.
+//
+// NEXT RULE (shared with the frontend): once `startsOn` is reached, the day's session is the
+// first not-done one in slot order — unless pins say otherwise.
+//
+// PINS (shared with the frontend; a planner need not read them — `dayPlan` is the athlete's): the
+// day sheet can give a session a day by writing the per-date override that already exists,
+// `S.dayPlan[iso] = <queue routine id>`; nothing new is stored. An active pin is a dayPlan entry
+// dated today or later that names a session still to do. On its day the pinned session is the
+// day's session, ahead of the floating order; on every other day from today on the floating rule
+// skips it. A pin on a past day is stale (the session floats again), and a pin on a done session
+// is fulfilled (`pinState === 'done'`) and reads as no override at all. Pins change which session
+// is NEXT, never what counts as DONE, so the tally a planner reads is untouched.
function routineIdsOf(w) {
return Array.isArray(w.routineIds) ? w.routineIds : (w.routineId ? [w.routineId] : []);
}
@@ -22,33 +34,65 @@ function queueDone(S, id, startsOn) {
return (S.workouts || []).some(w => routineIdsOf(w).includes(id)
&& ((w.start ?? 0) >= S.queue.since || (String(w.d || '') >= startsOn && nameParts(w).includes(currentName))));
}
-// The reminder tick only ever asks "what's next right now" — there is no separate "today" to
-// preview a different date against, so `today` in the spec's `next(iso, today)` is just `iso`.
-// That collapses `iso === max(today, startsOn)` to the equivalent, simpler `iso >= startsOn`.
-function queueNext(S, iso) {
+// Tolerant reader, as in the frontend: a missing or malformed queue reads as none. A missing
+// startsOn means active now; a session whose routine was deleted is dropped from the week (the
+// frontend's queue.js does the same — it could never be started or logged).
+function queueOf(S) {
const q = S.queue;
if (!q || typeof q !== 'object' || !Array.isArray(q.ids)) return null;
- // A missing startsOn means active now; a session whose routine was deleted is dropped from the
- // week (the frontend's queue.js does the same — it could never be started or logged).
const startsOn = typeof q.startsOn === 'string' ? q.startsOn : new Date(q.since || 0).toISOString().slice(0, 10);
- if (iso < startsOn) return null;
const ids = q.ids.filter(id => (S.routines || []).some(r => r?.id === id));
- const remaining = ids.filter(id => !queueDone(S, id, startsOn));
- return remaining.length ? remaining[0] : null;
+ return { ids, startsOn };
+}
+// The reminder tick only ever asks "what's next right now" — there is no separate "today" to
+// preview a different date against, so `today` in the spec's `next(iso, today)` is just `iso`.
+// That collapses `iso === max(today, startsOn)` to the equivalent, simpler `iso >= startsOn`, and
+// "pins dated today or later" to "pins dated `iso` or later".
+function queueNext(S, iso) {
+ const q = queueOf(S);
+ if (!q || iso < q.startsOn) return null;
+ const remaining = q.ids.filter(id => !queueDone(S, id, q.startsOn));
+ const pins = Object.entries(S.dayPlan || {}).filter(([d, id]) => d >= iso && remaining.includes(id));
+ const here = pins.find(([d]) => d === iso);
+ if (here) return here[1];
+ return remaining.find(id => !pins.some(([, id2]) => id2 === id)) ?? null;
+}
+
+// What a per-date override pointing at `id` means for the queue: 'open' — a pin on a session
+// still to do (its day's session, skipped elsewhere); 'done' — a fulfilled pin, to be read as no
+// override; null — not a queue session (no queue, a malformed one, a routine override, 'rest', a
+// deleted routine), so the plain override rules apply.
+export function pinState(S, id) {
+ const q = queueOf(S);
+ if (!q || !id || !q.ids.includes(id)) return null;
+ return queueDone(S, id, q.startsOn) ? 'done' : 'open';
}
// A weekday can hold a routine-id list (combine routines); the reminder only needs the first.
// The `?.` on each routine entry is this copy's own: it reads whatever is on disk, including a
// file written before PUT /api/data dropped null entries.
-// Per-date overrides win outright ('rest' -> null; an explicit routine id -> that id); otherwise
-// a live queue's next session wins over the plain weekday assignment, falling back to the weekday
-// only once the queue is finished, not yet started, or absent.
+// Per-date overrides: 'rest' -> null; a pin on an open queue session -> that session; a pin on a
+// done one is fulfilled and ignored; an explicit routine id -> that id. Otherwise a live queue's
+// next session wins over the plain weekday assignment, falling back to the weekday only once the
+// queue is finished, not yet started, or absent.
export function effectiveRoutineId(S, iso) {
const ov = S.dayPlan?.[iso];
if (ov === 'rest') return null;
- if (ov && S.routines?.some(r => r?.id === ov)) return ov;
+ const pin = pinState(S, ov);
+ if (pin === 'open') return ov;
+ if (!pin && ov && S.routines?.some(r => r?.id === ov)) return ov;
const q = queueNext(S, iso);
if (q) return q;
const wd = new Date(iso + 'T12:00:00').getDay();
- return [].concat(S.week?.[wd] || []).find(id => S.routines?.some(r => r?.id === id)) || null;
+ // The planner's weekday pointers stay hidden on a live queue day even when it has no session for
+ // it (every remaining one pinned to another day): those sessions have their days.
+ const live = queueLiveOn(S, iso);
+ return [].concat(S.week?.[wd] || []).find(id => S.routines?.some(r => r?.id === id) && !(live && S.queue.ids.includes(id))) || null;
+}
+
+// Is `iso` a day the queue speaks for, with sessions still to do? (`today === iso` here, so
+// "the queue's day" is any day from startsOn on.)
+function queueLiveOn(S, iso) {
+ const q = queueOf(S);
+ return !!q && iso >= q.startsOn && q.ids.some(id => !queueDone(S, id, q.startsOn));
}
diff --git a/api/test/queue.test.js b/api/test/queue.test.js
index 853e5fd82..0fcf42bdc 100644
--- a/api/test/queue.test.js
+++ b/api/test/queue.test.js
@@ -2,7 +2,7 @@
// server.js. Pure function, no server needed: the tick only calls this one export.
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { effectiveRoutineId } from '../queue.js';
+import { effectiveRoutineId, pinState } from '../queue.js';
const routines = [
{ id: 'r1', name: 'Push' },
@@ -107,3 +107,103 @@ test('queue: a session whose routine was deleted is dropped; a missing startsOn
const bad = { ...base, week: { 2: 'r3' }, queue: { ids: 'r1' } };
assert.equal(effectiveRoutineId(bad, '2026-09-08'), 'r3'); // Tuesday: a malformed queue reads as none
});
+
+// ---- pins: a per-date override naming a queue session re-dates it (pinState) ----
+// Mirrors the "pins —" block in frontend/src/lib/queue.test.js and the pin cases in
+// lib/history.test.js. Here `today` is always the date asked about (the reminder tick).
+
+const own = { id: 'own', name: 'Core' };
+const W1 = { ids: ['r1', 'r2', 'r3'], since: 1000, startsOn: '2026-09-07', label: 'W1' };
+const P = (over = {}) => ({ ...base, routines: [...routines, own], queue: W1, ...over });
+const done = (id, d = '2026-09-08') => ({ d, start: 2000, routineIds: [id], name: routines.find(r => r.id === id).name });
+const TODAY = '2026-09-09'; // Wednesday
+const FRI = '2026-09-11';
+
+test('pins: a session pinned to another day is skipped by the floating rule, and is that day\'s session when it comes', () => {
+ const S = P({ dayPlan: { [FRI]: 'r1' } });
+ assert.equal(effectiveRoutineId(S, TODAY), 'r2'); // r1 is Friday's, today floats past it
+ assert.equal(effectiveRoutineId(S, FRI), 'r1'); // on its day, ahead of the floating order
+ assert.equal(pinState(S, 'r1'), 'open');
+});
+
+test('pins: a session pinned to the day asked about wins over the floating order', () => {
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [TODAY]: 'r3' } }), TODAY), 'r3');
+ // A pin on a day the weekday model also fills: the pin still answers first (a single id here).
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [TODAY]: 'r3' }, week: { 3: 'own' } }), TODAY), 'r3');
+});
+
+test('pins: a pin on a past day is stale — the session floats again', () => {
+ const S = P({ dayPlan: { '2026-09-08': 'r1' } });
+ assert.equal(effectiveRoutineId(S, TODAY), 'r1'); // Tuesday's pin was never met, r1 is first undone again
+});
+
+test('pins: a fulfilled pin reads as no override, so the day falls through to the next floating session or the weekday', () => {
+ const S = P({ dayPlan: { [FRI]: 'r1' }, workouts: [done('r1')], week: { 5: 'own' } });
+ assert.equal(pinState(S, 'r1'), 'done');
+ assert.equal(effectiveRoutineId(S, FRI), 'r2'); // not r1 (done), not own (queue still live) -> next floating
+ assert.equal(effectiveRoutineId(S, TODAY), 'r2');
+ // Done early on the pinned day itself: today's answer is the next floating session.
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [TODAY]: 'r1' }, workouts: [done('r1')] }), TODAY), 'r2');
+ // Week complete with a fulfilled pin on the day: the weekday plan shows through, not the pinned id.
+ const complete = P({
+ queue: { ...W1, ids: ['r1', 'r2'] },
+ dayPlan: { [FRI]: 'r1' },
+ workouts: [done('r1'), done('r2')],
+ week: { 5: 'own' },
+ });
+ assert.equal(effectiveRoutineId(complete, FRI), 'own');
+ assert.equal(effectiveRoutineId(P({ queue: { ...W1, ids: ['r1'] }, dayPlan: { [FRI]: 'r1' }, workouts: [done('r1')] }), FRI), null);
+});
+
+test('pins: every remaining session pinned to other days — nothing floats, the weekday plan (or nothing) shows through', () => {
+ const pins = { [FRI]: 'r1', '2026-09-12': 'r2', '2026-09-13': 'r3' };
+ assert.equal(effectiveRoutineId(P({ dayPlan: pins }), TODAY), null);
+ assert.equal(effectiveRoutineId(P({ dayPlan: pins, week: { 3: 'own' } }), TODAY), 'own');
+ // Each pinned day still answers with its own session.
+ assert.equal(effectiveRoutineId(P({ dayPlan: pins }), '2026-09-12'), 'r2');
+});
+
+test('pins: \'rest\' still wins over a pin, and a plain routine override is still single-pick', () => {
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [TODAY]: 'rest', [FRI]: 'r1' } }), TODAY), null);
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [TODAY]: 'own' } }), TODAY), 'own');
+});
+
+test('pins: a pin dated before a future startsOn is honoured on its day; once the start day arrives the unmet pin is past, so the session floats', () => {
+ const S = P({ queue: { ...W1, startsOn: '2026-09-14' }, dayPlan: { '2026-09-12': 'r1' } });
+ assert.equal(effectiveRoutineId(S, '2026-09-12'), 'r1');
+ assert.equal(effectiveRoutineId(S, TODAY), null); // before startsOn, the queue has nothing to say
+ // The reminder asks on the day itself (`today === iso`): a 09-12 pin is stale by 09-14, r1 floats.
+ assert.equal(effectiveRoutineId(S, '2026-09-14'), 'r1');
+});
+
+test('pinState: open for a session still to do, done once logged, null for anything else', () => {
+ assert.equal(pinState(P(), 'r2'), 'open');
+ assert.equal(pinState(P({ workouts: [done('r2')] }), 'r2'), 'done');
+ assert.equal(pinState(P(), 'own'), null); // a routine override, not a queue session
+ assert.equal(pinState(P(), 'rest'), null);
+ assert.equal(pinState(P(), undefined), null);
+ assert.equal(pinState(P({ queue: null }), 'r1'), null);
+ assert.equal(pinState(P({ queue: undefined }), 'r1'), null);
+ assert.equal(pinState(P({ queue: { ids: 'r1' } }), 'r1'), null); // malformed queue reads as none
+ // A pinned session whose routine was deleted is not a pin any more; the override falls through.
+ const gone = P({ routines: [routines[1], routines[2], own], dayPlan: { [TODAY]: 'r1' } });
+ assert.equal(pinState(gone, 'r1'), null);
+ assert.equal(effectiveRoutineId(gone, TODAY), 'r2');
+});
+
+test('pins: no queue — a dayPlan entry is the plain override it always was', () => {
+ const S = { ...base, routines: [...routines, own], week: { 3: 'own' }, dayPlan: { [TODAY]: 'r1', [FRI]: 'rest' } };
+ assert.equal(pinState(S, 'r1'), null);
+ assert.equal(effectiveRoutineId(S, TODAY), 'r1');
+ assert.equal(effectiveRoutineId(S, FRI), null);
+ assert.equal(effectiveRoutineId(S, '2026-09-16'), 'own'); // next Wednesday, weekday plan
+});
+
+test('pins: with every remaining session pinned to other days, a coach pointer on the weekday stays hidden', () => {
+ const S = P({ dayPlan: { [FRI]: 'r1', '2026-09-12': 'r2', '2026-09-13': 'r3' }, week: { 3: ['r2', 'own'] } });
+ assert.equal(effectiveRoutineId(S, TODAY), 'own');
+ assert.equal(effectiveRoutineId(P({ dayPlan: { [FRI]: 'r1', '2026-09-12': 'r2', '2026-09-13': 'r3' }, week: { 3: 'r1' } }), TODAY), null);
+ // A complete week hands the weekday back whole, coach pointer included, as before.
+ const complete = P({ workouts: [done('r1'), done('r2'), done('r3')], week: { 3: ['r2', 'own'] } });
+ assert.equal(effectiveRoutineId(complete, TODAY), 'r2');
+});
diff --git a/frontend/src/components/QueueRow.jsx b/frontend/src/components/QueueRow.jsx
index 8af3f654d..53fc30e9f 100644
--- a/frontend/src/components/QueueRow.jsx
+++ b/frontend/src/components/QueueRow.jsx
@@ -8,19 +8,26 @@ import Icon from './Icon.jsx'
// while a planner-written queue runs the week, because its sessions have no weekday: they are done in
// order, on whatever days you train. One chip per session in slot order; the next undone one
// is lit, and any undone chip starts its own routine, in whatever order the day calls for. A
-// done chip is inert: that session is logged. Reads through queueView so the words here and
-// the today row (effectiveRoutineIds → queueNext) can never disagree about which is next.
+// done chip is inert: that session is logged. A session pinned to another day (the day sheet,
+// S.dayPlan) is not lit and wears its day instead of a state word — it still starts on a tap.
+// Reads through queueView so the words here and the today row (effectiveRoutineIds →
+// queueNext) can never disagree about which is next.
export default function QueueRow({ S, today, onStart }) {
const v = queueView(S, today)
if (!v) return null
const word = { done: t('Done'), next: t('Up next'), later: t('Later') }
const next = v.items.find(i => i.state === 'next')
+ // With every remaining session pinned to its own day nothing floats, so there is no 'next'
+ // chip at all; the status line then names the soonest pinned one with its day.
+ const pinned = v.items.filter(i => i.state === 'pinned').sort((a, b) => (a.on < b.on ? -1 : a.on > b.on ? 1 : 0))[0]
// "today" only when the today row really offers it: a 'rest' or routine override for today
// wins over the queue there (effectiveRoutineIds), and this line must not contradict it.
const shownToday = !!next && effectiveRoutineIds(S, today, today).includes(next.id)
const status = v.complete ? t('Week complete, ask the coach')
: v.waiting ? t('Next week starts {0}', fmtDate(v.startsOn, true))
- : shownToday ? t('Next: {0}, today', next.name) : t('Next: {0}', next.name)
+ : shownToday ? t('Next: {0}, today', next.name)
+ : next ? t('Next: {0}', next.name)
+ : t('Next: {0}', pinned.name + ' · ' + fmtDate(pinned.on, true))
return <div className="queue">
<div className="row between" style={{ marginBottom: 8 }}>
<div className="small muted" style={{ fontWeight: 500 }}>{v.label}</div>
@@ -31,7 +38,7 @@ export default function QueueRow({ S, today, onStart }) {
{v.items.map((i, n) => <button key={n} className={'chip' + (i.state === 'next' ? ' on' : '')}
disabled={i.state === 'done'} onClick={() => onStart(i.id)}
style={{ display: 'inline-flex', alignItems: 'center', gap: 5, opacity: i.state === 'done' ? 0.55 : undefined }}>
- {i.state === 'done' && <Icon name="check" />}{i.name}<span className="dim">{word[i.state]}</span>
+ {i.state === 'done' && <Icon name="check" />}{i.name}<span className="dim">{i.state === 'pinned' ? fmtDate(i.on, true) : word[i.state]}</span>
</button>)}
</div>
<div className="small muted queue-status" style={{ marginTop: 8 }}>{status}</div>
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index d69e3c103..7f1306def 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -17,7 +17,7 @@ const workRowsForMode = (entry = {}, mode = 'reps') => {
// for the hook — and it re-exports this very `t` from core, so nothing changes here except what
// gets dragged along behind it.
import { t } from './i18n-core.js'
-import { queueNext } from './queue.js'
+import { queueNext, pinState, queueLiveOn } from './queue.js'
// How an exercise is logged (issue #16). This used to be derived from the body part alone,
// which meant a plank or a farmer's carry could only be timed by filing it under cardio.
@@ -399,15 +399,23 @@ export function bestWeightFor(S, exId) {
* holds. The planner's own weekday pointers (a week applied before the queue existed) are
* hidden behind it; routines you planned yourself ride along as a combined day. `today` is a
* parameter so tests and the reminder builder can pin the clock; the override still wins.
+ *
+ * An override naming a queue session is a PIN (queue.js): the session is that day's, with the
+ * weekday's own routines riding along as on any queue day, and the floating rule skips it on
+ * other days. Once the session is done the pin is fulfilled and the day reads as if unpinned.
*/
export function effectiveRoutineIds(S, iso, today = todayISO()) {
const ov = S.dayPlan[iso]
if (ov === 'rest') return []
- if (ov && S.routines.some(r => r.id === ov)) return [ov]
+ const pin = pinState(S, ov)
+ if (!pin && ov && S.routines.some(r => r.id === ov)) return [ov]
const wd = new Date(iso + 'T12:00:00').getDay()
const weekday = [].concat(S.week[wd] || []).filter(id => S.routines.some(r => r.id === id))
- const q = queueNext(S, iso, today)
- return q ? [q, ...weekday.filter(id => !S.queue.ids.includes(id))] : weekday
+ const q = pin === 'open' ? ov : queueNext(S, iso, today)
+ // The planner's weekday pointers stay hidden on the queue's day even when it has no session for
+ // it (every remaining one pinned to another day): those sessions have their days.
+ const own = q || queueLiveOn(S, iso, today) ? weekday.filter(id => !S.queue.ids.includes(id)) : weekday
+ return q ? [q, ...own] : own
}
export function effectiveRoutines(S, iso) {
return effectiveRoutineIds(S, iso).map(id => S.routines.find(r => r.id === id)).filter(Boolean)
diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js
index 0f022c943..033b8e2f0 100644
--- a/frontend/src/lib/history.test.js
+++ b/frontend/src/lib/history.test.js
@@ -1346,6 +1346,34 @@ describe('effectiveRoutineIds — coach queue', () => {
it('without a queue the weekday plan answers as before', () => {
expect(effectiveRoutineIds(S({ queue: null, week: { 3: ['own'] } }), TODAY, TODAY)).toEqual(['own'])
})
+
+ // ---- pins: an override naming a queue session re-dates it (lib/queue.js pinState) ----
+ it('a session pinned to a later day is that day\'s, with the weekday\'s own routine riding along; today floats past it', () => {
+ const s = S({ dayPlan: { '2026-09-11': 'd1' }, week: { 5: ['own'] } })
+ expect(effectiveRoutineIds(s, '2026-09-11', TODAY)).toEqual(['d1', 'own'])
+ expect(effectiveRoutineIds(s, TODAY, TODAY)).toEqual(['d2'])
+ // Pinned to today: it is today's session, ahead of the floating order.
+ expect(effectiveRoutineIds(S({ dayPlan: { [TODAY]: 'd2' } }), TODAY, TODAY)).toEqual(['d2'])
+ })
+
+ it('a fulfilled pin reads as no override: the day goes back to the floating rule or the weekday', () => {
+ const s = S({ dayPlan: { '2026-09-11': 'd1' }, workouts: [done('d1')], week: { 5: ['own'] } })
+ expect(effectiveRoutineIds(s, '2026-09-11', TODAY)).toEqual(['own'])
+ expect(effectiveRoutineIds(s, TODAY, TODAY)).toEqual(['d2'])
+ // Done early on the pinned day itself: today's answer is the next floating session.
+ expect(effectiveRoutineIds(S({ dayPlan: { [TODAY]: 'd1' }, workouts: [done('d1')] }), TODAY, TODAY)).toEqual(['d2'])
+ })
+
+ it('with every remaining session pinned to other days, today shows only your own routines — a coach pointer on the weekday stays hidden', () => {
+ const s = S({ dayPlan: { '2026-09-11': 'd1', '2026-09-12': 'd2' }, week: { 3: ['d2', 'own'] } })
+ expect(effectiveRoutineIds(s, TODAY, TODAY)).toEqual(['own'])
+ expect(effectiveRoutineIds(S({ dayPlan: { '2026-09-11': 'd1', '2026-09-12': 'd2' }, week: { 3: 'd1' } }), TODAY, TODAY)).toEqual([])
+ })
+
+ it('a plain routine override is still single-pick, and \'rest\' still wins over a pin', () => {
+ expect(effectiveRoutineIds(S({ dayPlan: { [TODAY]: 'own' }, week: { 3: ['own'] } }), TODAY, TODAY)).toEqual(['own'])
+ expect(effectiveRoutineIds(S({ dayPlan: { [TODAY]: 'rest', '2026-09-11': 'd1' } }), TODAY, TODAY)).toEqual([])
+ })
})
describe('nextTrainingDay on a combined day', () => {
diff --git a/frontend/src/lib/queue.js b/frontend/src/lib/queue.js
index 51f4a9c5a..059b4051b 100644
--- a/frontend/src/lib/queue.js
+++ b/frontend/src/lib/queue.js
@@ -13,6 +13,15 @@
// The app never writes `S.queue`; a planner does — any API client that PUTs state with a queue
// (a coaching agent, a script). null = the weekday model alone.
//
+// PINS — a session can be given a day. The day sheet writes the per-date override that already
+// exists (`S.dayPlan[iso] = <queue routine id>`); nothing new is stored. A pin re-dates the
+// session: on its day it is the day's session (the weekday's own routines ride along, as on any
+// queue day — effectiveRoutineIds in history.js), on every other day from today on the floating
+// rule skips it, and once it is done — on its day or early — the pin is fulfilled and reads as no
+// override. A pin on a past date is stale: the session floats again. Pins change which session
+// is NEXT, never what counts as DONE, so weekTally, the reminders' tally and whatever a planner
+// reads back are untouched.
+//
// DONE RULE — kept word for word with the api's reminder copy (api/queue.js), and the rule a
// planner has to mirror, so nobody disagrees about which session is next: a session is done
// when any FINISHED workout on that routine exists after the week was applied. Missed sets are
@@ -74,27 +83,69 @@ export function queueNext(S, iso, today) {
// asks for thirty dates in a row, so the done-scan runs only for the one that can match.
const on = today > q.startsOn ? today : q.startsOn
if (iso !== on) return null
- const remaining = queueRemaining(S)
- return remaining.length ? remaining[0] : null
+ return nextOn(S, queueRemaining(S), on, today)
+}
+
+/** Active pins, `[{ iso, id }]`: dayPlan entries naming a session still to do, dated today or later. */
+const activePins = (S, remaining, today) => Object.entries(S.dayPlan || {})
+ .filter(([iso, id]) => iso >= today && remaining.includes(id))
+ .map(([iso, id]) => ({ iso, id }))
+
+/** The queue's session for the date `on`: the one pinned there, else the first undone one not pinned to another day. */
+const nextOn = (S, remaining, on, today) => {
+ const pins = activePins(S, remaining, today)
+ const here = pins.find(p => p.iso === on)
+ if (here) return here.id
+ return remaining.find(id => !pins.some(p => p.id === id)) ?? null
+}
+
+/**
+ * Is `iso` the day the queue speaks for, with sessions still to do? True even when queueNext is
+ * null there because every remaining session is pinned to another day: the planner's weekday
+ * pointers stay hidden behind the queue on that day (history.js) whatever it answers.
+ */
+export function queueLiveOn(S, iso, today) {
+ const q = queueOf(S)
+ return !!q && iso === (today > q.startsOn ? today : q.startsOn) && queueRemaining(S).length > 0
+}
+
+/**
+ * What a per-date override pointing at `id` means for the queue: 'open' — a pin on a session
+ * still to do (its day's session, skipped elsewhere); 'done' — a fulfilled pin, to be read as no
+ * override; null — not a queue session (or no queue), the plain override rules apply.
+ */
+export function pinState(S, id) {
+ const q = queueOf(S)
+ if (!q || !id || !q.ids.includes(id)) return null
+ return isDone(S, q, id) ? 'done' : 'open'
}
/**
* Everything Home's progress row shows, derived once. `items` keep slot order; `state` is
- * 'done', 'next' (the first undone one, whether or not the queue is active yet) or 'later'.
- * `waiting` = the queue is sitting on a future `startsOn`. null without a queue.
+ * 'done', 'next' (the session for the day the queue answers on — pinned there, or the first
+ * undone one not pinned to another day — whether or not the queue is active yet), 'pinned'
+ * (given another day, carried as `on`; the earliest such day when there are several) or
+ * 'later'. `waiting` = the queue is sitting on a future `startsOn`. null without a queue.
*/
export function queueView(S, today) {
const q = queueOf(S)
if (!q) return null
const remaining = queueRemaining(S)
+ const on = today > q.startsOn ? today : q.startsOn
+ const next = nextOn(S, remaining, on, today)
+ const pins = activePins(S, remaining, today).sort((a, b) => (a.iso < b.iso ? -1 : a.iso > b.iso ? 1 : 0))
// A routine the planner has since retired keeps its id as the name — better than a blank chip.
const nameOf = id => S.routines.find(r => r.id === id)?.name ?? id
return {
label: q.label || '',
- items: q.ids.map(id => ({
- id, name: nameOf(id),
- state: !remaining.includes(id) ? 'done' : id === remaining[0] ? 'next' : 'later',
- })),
+ items: q.ids.map(id => {
+ const pin = id !== next && pins.find(p => p.id === id && p.iso !== on)
+ return {
+ id, name: nameOf(id),
+ state: !remaining.includes(id) ? 'done' : id === next ? 'next' : pin ? 'pinned' : 'later',
+ ...(pin ? { on: pin.iso } : {}),
+ }
+ }),
remaining,
complete: remaining.length === 0,
startsOn: q.startsOn,
diff --git a/frontend/src/lib/queue.test.js b/frontend/src/lib/queue.test.js
index e750c7e5d..a865698ec 100644
--- a/frontend/src/lib/queue.test.js
+++ b/frontend/src/lib/queue.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { queueDone, queueRemaining, queueNext, queueView, weekTally } from './queue.js'
+import { queueDone, queueRemaining, queueNext, queueView, weekTally, pinState } from './queue.js'
// The DONE RULE is shared with the api's reminder copy (and any planner writing S.queue); these
// cases are the ones every copy must agree on. Dates are plain strings so nothing here reads the clock.
@@ -107,6 +107,66 @@ describe('queueNext', () => {
})
})
+describe('pins — a session given a day (S.dayPlan[iso] = queue routine id)', () => {
+ const FRI = '2026-09-11'
+ it('a session pinned to another day is skipped by the floating rule until that day', () => {
+ expect(queueNext(S({ dayPlan: { [FRI]: 'd1' } }), TODAY, TODAY)).toBe('d2')
+ // …and on its day it is the day's session, ahead of the floating order.
+ expect(queueNext(S({ dayPlan: { [TODAY]: 'd3' } }), TODAY, TODAY)).toBe('d3')
+ // Every remaining session pinned elsewhere: nothing floats today.
+ expect(queueNext(S({ dayPlan: { [FRI]: 'd1', '2026-09-12': 'd2', '2026-09-13': 'd3' } }), TODAY, TODAY)).toBeNull()
+ })
+
+ it('a pin on a past day is stale, and a pin on a done session is fulfilled: both let the session float', () => {
+ expect(queueNext(S({ dayPlan: { '2026-09-08': 'd1' } }), TODAY, TODAY)).toBe('d1')
+ const done = S({ dayPlan: { [FRI]: 'd1' }, workouts: [w({ routineIds: ['d1'] })] })
+ expect(queueNext(done, TODAY, TODAY)).toBe('d2')
+ expect(pinState(done, 'd1')).toBe('done')
+ })
+
+ it('pinState: open for a session still to do, done once logged, null for anything else', () => {
+ expect(pinState(S(), 'd2')).toBe('open')
+ expect(pinState(S({ workouts: [w({ routineIds: ['d2'] })] }), 'd2')).toBe('done')
+ expect(pinState(S(), 'own')).toBeNull()
+ expect(pinState(S(), 'rest')).toBeNull()
+ expect(pinState(S(), undefined)).toBeNull()
+ expect(pinState(S({ queue: null }), 'd1')).toBeNull()
+ // A pinned session whose routine the planner deleted is not a pin any more.
+ expect(pinState(S({ routines: routines.filter(r => r.id !== 'd1') }), 'd1')).toBeNull()
+ })
+
+ it('a pin dated between today and a future startsOn is honoured on its day, and skipped on the start day', () => {
+ const s = S({ queue: { ...S().queue, startsOn: '2026-09-14' }, dayPlan: { '2026-09-12': 'd1' } })
+ expect(queueNext(s, '2026-09-14', TODAY)).toBe('d2')
+ expect(queueNext(s, TODAY, TODAY)).toBeNull()
+ expect(pinState(s, 'd1')).toBe('open')
+ })
+
+ it('queueView lights the floating session and shows a pinned one with its day', () => {
+ const v = queueView(S({ dayPlan: { [FRI]: 'd1', '2026-09-13': 'd1' } }), TODAY)
+ expect(v.items).toEqual([
+ { id: 'd1', name: 'US W1 D1', state: 'pinned', on: FRI },
+ { id: 'd2', name: 'US W1 D2', state: 'next' },
+ { id: 'd3', name: 'US W1 D3', state: 'later' },
+ ])
+ // Pinned to today: it is 'next', and the would-be first session is 'later'.
+ const today = queueView(S({ dayPlan: { [TODAY]: 'd3' } }), TODAY)
+ expect(today.items.map(i => i.state)).toEqual(['later', 'later', 'next'])
+ // All pinned elsewhere: no 'next' at all today.
+ const all = queueView(S({ dayPlan: { [FRI]: 'd1', '2026-09-12': 'd2', '2026-09-13': 'd3' } }), TODAY)
+ expect(all.items.map(i => i.state)).toEqual(['pinned', 'pinned', 'pinned'])
+ expect(all.items.map(i => i.on)).toEqual([FRI, '2026-09-12', '2026-09-13'])
+ // A fulfilled pin is just done.
+ const done = queueView(S({ dayPlan: { [FRI]: 'd1' }, workouts: [w({ routineIds: ['d1'] })] }), TODAY)
+ expect(done.items[0]).toEqual({ id: 'd1', name: 'US W1 D1', state: 'done' })
+ })
+
+ it('pins never change the tally', () => {
+ expect(weekTally(S({ dayPlan: { [FRI]: 'd1' } }), TODAY)).toEqual({ done: 0, planned: 3 })
+ expect(queueRemaining(S({ dayPlan: { [FRI]: 'd1' } }))).toEqual(['d1', 'd2', 'd3'])
+ })
+})
+
describe('queueView', () => {
it('lists the sessions in slot order with one lit as next', () => {
const v = queueView(S({ workouts: [w({ routineIds: ['d1'] })] }), TODAY)
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index 769e424b7..24331de32 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -1716,11 +1716,12 @@ export default {
'Teal': 'أزرق مخضر',
'Yellow': 'أصفر',
'Enter how long it took — at least 1 minute.': 'أدخل المدة التي استغرقها — دقيقة واحدة على الأقل.',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'التالي: {0}، اليوم',
'Next: {0}': 'التالي: {0}',
'Next week starts {0}': 'يبدأ الأسبوع التالي {0}',
'Week complete, ask the coach': 'اكتمل الأسبوع، اسأل المدرب',
'Up next': 'التالي',
'Later': 'لاحقًا',
+ 'Coach week': 'أسبوع المدرب',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 85d055e4b..5932ba48a 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -1399,7 +1399,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Prüfsumme nicht verfügbar — Installation abgebrochen',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Als Nächstes: {0}, heute',
'Next: {0}': 'Als Nächstes: {0}',
'Next week starts {0}': 'Nächste Woche beginnt am {0}',
@@ -1690,4 +1690,5 @@ export default {
'Teal': 'Türkis',
'Yellow': 'Gelb',
'Enter how long it took — at least 1 minute.': 'Gib ein, wie lange es gedauert hat — mindestens 1 Minute.',
+ 'Coach week': 'Coach-Woche',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 6aff8fd1f..6db6379db 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Suma de verificación no disponible — no se instala',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Siguiente: {0}, hoy',
'Next: {0}': 'Siguiente: {0}',
'Next week starts {0}': 'La próxima semana empieza el {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turquesa',
'Yellow': 'Amarillo',
'Enter how long it took — at least 1 minute.': 'Indica cuánto duró — al menos 1 minuto.',
+ 'Coach week': 'Semana del entrenador',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 5e5de7745..d7878c08a 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} Mo',
'Checksum not available — not installing': 'Somme de contrôle indisponible — installation annulée',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'À suivre : {0}, aujourd’hui',
'Next: {0}': 'À suivre : {0}',
'Next week starts {0}': 'La semaine prochaine commence le {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turquoise',
'Yellow': 'Jaune',
'Enter how long it took — at least 1 minute.': 'Indique combien de temps ça a duré — au moins 1 minute.',
+ 'Coach week': 'Semaine du coach',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index b26c7ba02..fe937c8f8 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0}%',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'चेकसम उपलब्ध नहीं — इंस्टॉल नहीं किया गया',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'अगला: {0}, आज',
'Next: {0}': 'अगला: {0}',
'Next week starts {0}': 'अगला सप्ताह {0} से शुरू होगा',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'फ़िरोज़ी',
'Yellow': 'पीला',
'Enter how long it took — at least 1 minute.': 'बताएँ कि इसमें कितना समय लगा — कम से कम 1 मिनट।',
+ 'Coach week': 'कोच का सप्ताह',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index f49278c24..b34f60996 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -1382,7 +1382,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Ellenőrző összeg nem érhető el — nincs telepítés',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Következő: {0}, ma',
'Next: {0}': 'Következő: {0}',
'Next week starts {0}': 'A következő hét kezdete: {0}',
@@ -1673,4 +1673,5 @@ export default {
'Teal': 'Türkiz',
'Yellow': 'Sárga',
'Enter how long it took — at least 1 minute.': 'Add meg, meddig tartott — legalább 1 perc.',
+ 'Coach week': 'Edzői hét',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 3cf16565a..61d4f8ee6 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Checksum non disponibile — installazione annullata',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Prossima: {0}, oggi',
'Next: {0}': 'Prossima: {0}',
'Next week starts {0}': 'La prossima settimana inizia {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turchese',
'Yellow': 'Giallo',
'Enter how long it took — at least 1 minute.': 'Inserisci quanto è durato — almeno 1 minuto.',
+ 'Coach week': 'Settimana del coach',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 1204b0322..616d2d3e7 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0}%',
'{0} MB': '{0} MB',
'Checksum not available — not installing': '체크섬을 확인할 수 없어 설치하지 않습니다',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': '다음: {0}, 오늘',
'Next: {0}': '다음: {0}',
'Next week starts {0}': '다음 주는 {0}에 시작됩니다',
@@ -1670,4 +1670,5 @@ export default {
'Teal': '청록',
'Yellow': '노랑',
'Enter how long it took — at least 1 minute.': '걸린 시간을 입력하세요 — 최소 1분.',
+ 'Coach week': '코치 주간',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 1d32c58bf..f4b6447b1 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0}%',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Suma kontrolna niedostępna — instalacja przerwana',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Następny: {0}, dziś',
'Next: {0}': 'Następny: {0}',
'Next week starts {0}': 'Następny tydzień zaczyna się {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turkusowy',
'Yellow': 'Żółty',
'Enter how long it took — at least 1 minute.': 'Wpisz, ile to trwało — co najmniej 1 minutę.',
+ 'Coach week': 'Tydzień trenera',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 28a2ef308..eeaf4a415 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1008,13 +1008,14 @@ export const PT_BR_OVERRIDES = {
'Teal': 'Turquesa',
'Yellow': 'Amarelo',
'Enter how long it took — at least 1 minute.': 'Informe quanto tempo levou — pelo menos 1 minuto.',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Próximo: {0}, hoje',
'Next: {0}': 'Próximo: {0}',
'Next week starts {0}': 'A próxima semana começa em {0}',
'Week complete, ask the coach': 'Semana concluída, pergunte ao Coach',
'Up next': 'Próximo',
'Later': 'Depois',
+ 'Coach week': 'Semana do Coach',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index e8ab6a34b..ebb820ac2 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Soma de verificação indisponível — não instalado',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'A seguir: {0}, hoje',
'Next: {0}': 'A seguir: {0}',
'Next week starts {0}': 'A próxima semana começa a {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turquesa',
'Yellow': 'Amarelo',
'Enter how long it took — at least 1 minute.': 'Indica quanto tempo demorou — pelo menos 1 minuto.',
+ 'Coach week': 'Semana do treinador',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 58b2e9836..ef0fdea1b 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0} %',
'{0} MB': '{0} МБ',
'Checksum not available — not installing': 'Контрольная сумма недоступна — установка отменена',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Далее: {0}, сегодня',
'Next: {0}': 'Далее: {0}',
'Next week starts {0}': 'Следующая неделя начнётся {0}',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Бирюзовый',
'Yellow': 'Жёлтый',
'Enter how long it took — at least 1 minute.': 'Укажите, сколько это длилось — не меньше 1 минуты.',
+ 'Coach week': 'Неделя тренера',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 6cd2ef0d6..ea4d36b4e 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -1390,7 +1390,7 @@ export default {
'{0} %': '{0}%',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'ไม่มีค่าตรวจสอบ — ยกเลิกการติดตั้ง',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'ถัดไป: {0}, วันนี้',
'Next: {0}': 'ถัดไป: {0}',
'Next week starts {0}': 'สัปดาห์หน้าเริ่ม {0}',
@@ -1681,4 +1681,5 @@ export default {
'Teal': 'เขียวน้ำทะเล',
'Yellow': 'เหลือง',
'Enter how long it took — at least 1 minute.': 'ใส่ระยะเวลาที่ใช้ — อย่างน้อย 1 นาที',
+ 'Coach week': 'สัปดาห์ของโค้ช',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 53905b41e..14400285c 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '%{0}',
'{0} MB': '{0} MB',
'Checksum not available — not installing': 'Sağlama toplamı yok — yüklenmedi',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Sıradaki: {0}, bugün',
'Next: {0}': 'Sıradaki: {0}',
'Next week starts {0}': 'Gelecek hafta {0} başlıyor',
@@ -1670,4 +1670,5 @@ export default {
'Teal': 'Turkuaz',
'Yellow': 'Sarı',
'Enter how long it took — at least 1 minute.': 'Ne kadar sürdüğünü gir — en az 1 dakika.',
+ 'Coach week': 'Koç haftası',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 04c3fc8d4..2a3b9faae 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -1660,11 +1660,12 @@ export default {
'Teal': 'Бірюзовий',
'Yellow': 'Жовтий',
'Enter how long it took — at least 1 minute.': 'Вкажи, скільки це тривало — щонайменше 1 хвилину.',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': 'Далі: {0}, сьогодні',
'Next: {0}': 'Далі: {0}',
'Next week starts {0}': 'Наступний тиждень починається {0}',
'Week complete, ask the coach': 'Тиждень завершено, звернися до тренера',
'Up next': 'Далі',
'Later': 'Пізніше',
+ 'Coach week': 'Тиждень тренера',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index eb862c175..69c1a6d0b 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -1379,7 +1379,7 @@ export default {
'{0} %': '{0}%',
'{0} MB': '{0} MB',
'Checksum not available — not installing': '校验和不可用,已取消安装',
- // --- coach week (Home progress row, components/QueueRow.jsx) ---
+ // --- coach week (Home progress row, components/QueueRow.jsx; day sheet, sheets.jsx) ---
'Next: {0}, today': '下一个:{0},今天',
'Next: {0}': '下一个:{0}',
'Next week starts {0}': '下周于 {0} 开始',
@@ -1670,4 +1670,5 @@ export default {
'Teal': '青色',
'Yellow': '黄色',
'Enter how long it took — at least 1 minute.': '请输入用时 — 至少 1 分钟。',
+ 'Coach week': '教练周',
}
diff --git a/frontend/src/sheets.dayoverride.test.jsx b/frontend/src/sheets.dayoverride.test.jsx
index 55930c850..a32914ada 100644
--- a/frontend/src/sheets.dayoverride.test.jsx
+++ b/frontend/src/sheets.dayoverride.test.jsx
@@ -1,14 +1,16 @@
// @vitest-environment happy-dom
// The day sheet's header names the plan the day would have without its override. In a coach
// week that is the queue's session for the day, in front of the weekday's own routines — the
-// same answer the Home row gives — not the weekday list alone.
+// same answer the Home row gives — not the weekday list alone. The list itself puts the
+// week's remaining sessions first under 'Coach week': picking one pins it to the day (the
+// same per-date override), and one already pinned to another day shows that day.
import React, { act } from 'react'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { createRoot } from 'react-dom/client'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
import { dayOverrideSheet } from './sheets.jsx'
-import { todayISO, isoOf } from './lib/format.js'
+import { todayISO, isoOf, fmtDate, exCount } from './lib/format.js'
const routines = [
{ id: 'd1', name: 'US W1 D1', emoji: null, ex: [{ id: '0025' }] },
@@ -18,6 +20,11 @@ const routines = [
const SINCE = Date.now() - 2 * 86400000
const daysFromToday = n => { const d = new Date(todayISO() + 'T12:00:00'); d.setDate(d.getDate() + n); return isoOf(d) }
const queue = { ids: ['d1', 'd2'], since: SINCE, startsOn: daysFromToday(-1), label: 'US W1' }
+// A finished workout on `id`, started after the apply — the DONE RULE counts it for this week.
+const logged = id => {
+ const start = SINCE + 3600000
+ return { id: 'w-' + id, d: isoOf(new Date(start)), start, end: start + 3600000, routineIds: [id], routineId: id, name: routines.find(r => r.id === id).name, entries: [] }
+}
const mounted = []
function renderTop() {
@@ -30,6 +37,9 @@ function renderTop() {
return host
}
const header = host => host.querySelector('.muted.small').textContent
+const heading = host => host.querySelector('h4.sec')?.textContent
+const lists = host => [...host.querySelectorAll('.list')].map(l => [...l.querySelectorAll('.item .tt')].map(e => e.textContent))
+const rowOf = (host, name) => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)
const setS = (over = {}) => useStore.setState(s => ({ S: { ...s.S, routines, week: {}, dayPlan: {}, workouts: [], active: null, queue, ...over }, user: null }))
beforeEach(() => {
@@ -67,3 +77,67 @@ describe('Day sheet header in a coach week', () => {
expect(header(renderTop())).toMatch(/^Weekly plan: Rest/)
})
})
+
+describe('Day sheet list in a coach week', () => {
+ it('a fulfilled pin — the session pinned here already done — reads as no change; the clear row stays', () => {
+ setS({ dayPlan: { [todayISO()]: 'd1' }, workouts: [logged('d1')] })
+ dayOverrideSheet(todayISO())
+ const host = renderTop()
+ expect(header(host)).toMatch(/^Weekly plan: US W1 D2/)
+ expect(header(host)).not.toContain('changed for this day')
+ expect(rowOf(host, 'Back to weekly plan')).toBeTruthy()
+ })
+
+ it("the pinned day's own sheet shows the exercise count, not its own date again", () => {
+ const friday = daysFromToday(2)
+ setS({ dayPlan: { [friday]: 'd2' } })
+ dayOverrideSheet(friday)
+ const host = renderTop()
+ expect(rowOf(host, 'US W1 D2').querySelector('.ss').textContent).toBe(exCount(1))
+ // …while from today's sheet the same session wears Friday.
+ dayOverrideSheet(todayISO())
+ expect(rowOf(renderTop(), 'US W1 D2').querySelector('.ss').textContent).toBe(fmtDate(friday, true))
+ // A session pinned to today wears today from another day's sheet, though the row lights it as next.
+ setS({ dayPlan: { [todayISO()]: 'd2' } })
+ dayOverrideSheet(friday)
+ expect(rowOf(renderTop(), 'US W1 D2').querySelector('.ss').textContent).toBe(fmtDate(todayISO(), true))
+ })
+
+ it('lists the remaining sessions first under Coach week, a done session down in the plain list', () => {
+ setS({ workouts: [logged('d1')] })
+ dayOverrideSheet(todayISO())
+ const host = renderTop()
+ expect(heading(host)).toBe('Coach week')
+ const [coach, plain] = lists(host)
+ expect(coach).toEqual(['US W1 D2'])
+ expect(plain).toEqual(['US W1 D1', 'Core', 'Rest / skip this day'])
+ })
+
+ it('picking a coach row pins that session to the day', () => {
+ const friday = daysFromToday(2)
+ setS()
+ dayOverrideSheet(friday)
+ const host = renderTop()
+ act(() => rowOf(host, 'US W1 D2').click())
+ expect(useStore.getState().S.dayPlan[friday]).toBe('d2')
+ expect(useUI.getState().sheets).toHaveLength(0)
+ expect(useUI.getState().toastMsg).toBe(`US W1 D2 planned for ${fmtDate(friday)}`)
+ })
+
+ it('a session pinned to another day shows that day instead of its exercise count', () => {
+ const friday = daysFromToday(2)
+ setS({ dayPlan: { [friday]: 'd2' } })
+ dayOverrideSheet(todayISO())
+ const host = renderTop()
+ expect(rowOf(host, 'US W1 D2').querySelector('.ss').textContent).toBe(fmtDate(friday, true))
+ expect(rowOf(host, 'US W1 D1').querySelector('.ss').textContent).toBe(exCount(1))
+ })
+
+ it('without a queue there is no heading and one plain list', () => {
+ setS({ queue: null })
+ dayOverrideSheet(todayISO())
+ const host = renderTop()
+ expect(heading(host)).toBeUndefined()
+ expect(lists(host)).toEqual([['US W1 D1', 'US W1 D2', 'Core', 'Rest / skip this day']])
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 7508426ee..ca44b4d98 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -51,6 +51,7 @@ import { stampWorkout } from './lib/sync-merge.js'
import { weeklyWeights } from './lib/bodyweight.js'
import { workoutText } from './lib/workout-text.js'
import { copyText } from './lib/clipboard.js'
+import { queueRemaining, pinState } from './lib/queue.js'
const S = () => useStore.getState().S
const update = (...a) => useStore.getState().update(...a)
@@ -1811,6 +1812,9 @@ function PlanImport({ bundle, close }) {
function DayOverride({ iso, close }) {
const st = useStore(s => s.S)
const hasOvr = st.dayPlan[iso] !== undefined
+ // A fulfilled pin (a coach session pinned here and since done) reads as no override, as it does
+ // everywhere else — the row to clear the leftover entry stays.
+ const changed = hasOvr && pinState(st, st.dayPlan[iso]) !== 'done'
// The plan the day would have without its override — the weekday's routines, and in a coach
// week the queue's session for the day in front of them, same as the Home row shows.
const { [iso]: _ovr, ...noOvr } = st.dayPlan
@@ -1824,20 +1828,35 @@ function DayOverride({ iso, close }) {
// that date with the day's routines picked, where the time and the duration can still change.
const missed = iso < todayISO() && effIds.length > 0 && !workoutsOn(st, iso).length
const logIt = () => { close(); logPastWorkoutSheet({ iso, routineIds: effIds }) }
+ // The coach week's sessions still to do come first, in slot order: picking one here pins it
+ // to this day — the same per-date override, read back by queueNext (lib/queue.js). A session
+ // already pinned to another day says so in place of its exercise count. Done sessions and
+ // your own routines follow in the plain list.
+ const remaining = queueRemaining(st)
+ const coach = remaining.map(id => st.routines.find(r => r.id === id)).filter(Boolean)
+ // Active pins straight from the plan (earliest day per session, today or later) — not the
+ // row's 'pinned' items, which leave out the session pinned to today itself.
+ const pinnedOn = Object.entries(st.dayPlan).filter(([d, id]) => d >= todayISO() && remaining.includes(id)).sort()
+ .reduce((m, [d, id]) => (m[id] ? m : { ...m, [id]: d }), {})
const set = v => {
update(s => { if (!v) delete s.dayPlan[iso]; else s.dayPlan[iso] = v })
close()
toast(v === '' ? t('Back to weekly plan') : v === 'rest' ? t('{0} set to rest', fmtDate(iso)) : t('{0} planned for {1}', (st.routines.find(r => r.id === v) || {}).name, fmtDate(iso)))
}
+ const row = r => <div key={r.id} className="item" {...tappable(() => set(r.id))}>
+ <span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
+ <div className="grow"><div className="tt">{r.name}</div><div className="ss">{pinnedOn[r.id] && pinnedOn[r.id] !== iso ? fmtDate(pinnedOn[r.id], true) : exCount(r.ex.length)}</div></div>
+ {effIds.includes(r.id) && <Icon name="check" className="accent" />}</div>
return <>
<h3>{fmtDate(iso, true)}</h3>
- <div className="muted small" style={{ marginBottom: 12 }}>{t('Weekly plan:')} {weeklyNames.length ? deriveSessionName(weeklyNames) : t('Rest')}{hasOvr && <span style={{ color: 'var(--orange)' }}> · {t('changed for this day')}</span>}<br />{t('Sick, missed a day or want a different session? Pick what to train instead.')}</div>
+ <div className="muted small" style={{ marginBottom: 12 }}>{t('Weekly plan:')} {weeklyNames.length ? deriveSessionName(weeklyNames) : t('Rest')}{changed && <span style={{ color: 'var(--orange)' }}> · {t('changed for this day')}</span>}<br />{t('Sick, missed a day or want a different session? Pick what to train instead.')}</div>
{missed && <div style={{ marginBottom: 14 }}><Button variant="primary" icon="checkCircle" onClick={logIt}>{t('Log this workout')}</Button></div>}
+ {coach.length > 0 && <>
+ <h4 className="sec" style={{ marginTop: 0 }}>{t('Coach week')}</h4>
+ <div className="list" style={{ marginBottom: 8 }}>{coach.map(row)}</div>
+ </>}
<div className="list">
- {st.routines.map(r => <div key={r.id} className="item" {...tappable(() => set(r.id))}>
- <span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
- <div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
- {effIds.includes(r.id) && <Icon name="check" className="accent" />}</div>)}
+ {st.routines.filter(r => !remaining.includes(r.id)).map(row)}
<div className="item" {...tappable(() => set('rest'))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest / skip this day')}</div></div>{effIds.length === 0 && <Icon name="check" className="accent" />}</div>
{hasOvr && <div className="item" {...tappable(() => set(''))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="reset" /></span><div className="grow"><div className="tt">{t('Back to weekly plan')}</div></div></div>}
</div>
@@ -2124,7 +2143,8 @@ function Calendar({ start, close }) {
for (let i = 0; i < startOffset; i++) cells.push(<div key={'e' + i} />)
for (let d = 1; d <= daysIn; d++) {
const iso = y + '-' + String(mo + 1).padStart(2, '0') + '-' + String(d).padStart(2, '0')
- const ws = byDay[iso], planned = effectiveRoutineIds(st, iso).length > 0, ovr = st.dayPlan[iso] !== undefined
+ // A fulfilled pin (a coach session pinned here and since done) reads as no override, as it does everywhere else.
+ const ws = byDay[iso], planned = effectiveRoutineIds(st, iso).length > 0, ovr = st.dayPlan[iso] !== undefined && pinState(st, st.dayPlan[iso]) !== 'done'
const dotCls = ws ? 'done' : ovr && planned ? 'ovr' : planned ? 'plan' : ''
cells.push(<button key={d} className={'cal-d' + (ws ? ' has' : '') + (iso === todayISO() ? ' today' : '')} onClick={() => {
if (!ws) { close(); dayOverrideSheet(iso); return }
diff --git a/frontend/src/views/Home.jsx b/frontend/src/views/Home.jsx
index 4cc1ad633..f4a26e484 100644
--- a/frontend/src/views/Home.jsx
+++ b/frontend/src/views/Home.jsx
@@ -8,7 +8,7 @@ import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, starter
import LineChart from '../components/LineChart.jsx'
import Icon from '../components/Icon.jsx'
import QueueRow from '../components/QueueRow.jsx'
-import { queueView, weekTally } from '../lib/queue.js'
+import { queueView, weekTally, pinState } from '../lib/queue.js'
import { Button } from '../components/ui.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
import { glyphOf } from '../lib/glyphs.js'
@@ -26,7 +26,8 @@ export default function Home() {
const todayRoutines = effectiveRoutines(S, todayISO())
const routine = todayRoutines[0] || null
const todayName = todayRoutines.map(r => r.name).join(' + ')
- const todayOvr = S.dayPlan[todayISO()] !== undefined
+ // A fulfilled pin (a coach session pinned to today and since done) reads as no override.
+ const todayOvr = S.dayPlan[todayISO()] !== undefined && pinState(S, S.dayPlan[todayISO()]) !== 'done'
// An open editor on a saved workout (lib/session-edit.js) holds S.active too, but it is not a
// session in progress: the row takes you back to it as an edit, the way the tab bar does.
const editingSaved = !!S.active?.editingWorkoutId
diff --git a/frontend/src/views/Home.queue.test.jsx b/frontend/src/views/Home.queue.test.jsx
index 6dac4fee6..50ad29510 100644
--- a/frontend/src/views/Home.queue.test.jsx
+++ b/frontend/src/views/Home.queue.test.jsx
@@ -1,8 +1,9 @@
// @vitest-environment happy-dom
// A coach week (S.queue) runs by order, not by weekday, so Home swaps the seven dots for a
-// progress row. Pinned here: one chip per session in slot order with its state word, a tap on
+// progress row. Covered here: one chip per session in slot order with its state word, a tap on
// an undone chip starting that routine alone, a done chip staying inert, the status line's
-// three states, and the today row still answering through the same helper.
+// states, the today row still answering through the same helper, and a session pinned to a day
+// (S.dayPlan[iso] = queue routine id) wearing its day on the chip and yielding the light.
import React, { act } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createRoot } from 'react-dom/client'
@@ -164,3 +165,57 @@ describe('Home — coach week progress row', () => {
expect(host.querySelectorAll('.wday').length).toBe(7)
})
})
+
+describe('Home — a session pinned to a day', () => {
+ it('a fulfilled pin — pinned to today, done on an earlier day — reads as no override on the today row', () => {
+ setS({ dayPlan: { [todayISO()]: 'd1' }, workouts: [logged('d1')] })
+ mount()
+ expect(chipTexts()).toEqual(['US W1 D1Done', 'US W1 D2Up next', 'US W1 D3Later'])
+ expect(status()).toBe('Next: US W1 D2, today')
+ expect(todayTitle()).toBe('US W1 D2')
+ })
+
+ it('a session pinned ahead wears its day, is not lit, and the light moves to the next floating one', () => {
+ const on = daysFromToday(2)
+ setS({ dayPlan: { [on]: 'd1' } })
+ mount()
+ expect(chipTexts()).toEqual(['US W1 D1' + fmtDate(on, true), 'US W1 D2Up next', 'US W1 D3Later'])
+ expect(chips()[0].className).toBe('chip')
+ expect(chips()[0].disabled).toBe(false)
+ expect(chips()[1].className).toBe('chip on')
+ expect(status()).toBe('Next: US W1 D2, today')
+ expect(todayTitle()).toBe('US W1 D2')
+ })
+
+ it('a session pinned to today is the day\'s session, ahead of the floating order', () => {
+ setS({ dayPlan: { [todayISO()]: 'd3' } })
+ mount()
+ expect(chipTexts()).toEqual(['US W1 D1Later', 'US W1 D2Later', 'US W1 D3Up next'])
+ expect(chips()[2].className).toBe('chip on')
+ expect(status()).toBe('Next: US W1 D3, today')
+ // Home reads any per-date override on today as a reschedule — a pin is one.
+ expect(todayTitle()).toBe('US W1 D3 · rescheduled')
+ })
+
+ it('every session pinned ahead: no chip is lit, the line names the soonest with its day, today rests', () => {
+ const d1 = daysFromToday(1), d2 = daysFromToday(3), d3 = daysFromToday(2)
+ setS({ dayPlan: { [d1]: 'd1', [d2]: 'd2', [d3]: 'd3' } })
+ mount()
+ expect(chipTexts()).toEqual(['US W1 D1' + fmtDate(d1, true), 'US W1 D2' + fmtDate(d2, true), 'US W1 D3' + fmtDate(d3, true)])
+ expect(chips().some(c => c.className.includes('on'))).toBe(false)
+ expect(chips().every(c => !c.disabled)).toBe(true)
+ expect(status()).toBe('Next: US W1 D1 · ' + fmtDate(d1, true))
+ expect(todayTitle()).toBe('Rest day')
+ // Soonest by date, not first in slot order.
+ act(() => setS({ dayPlan: { [daysFromToday(3)]: 'd1', [daysFromToday(1)]: 'd2', [daysFromToday(2)]: 'd3' } }))
+ expect(status()).toBe('Next: US W1 D2 · ' + fmtDate(daysFromToday(1), true))
+ })
+
+ it('tapping a pinned chip starts that routine alone, today', () => {
+ setS({ dayPlan: { [daysFromToday(2)]: 'd1' } })
+ mount()
+ act(() => { chips()[0].click() })
+ expect(startFlow).toHaveBeenCalledTimes(1)
+ expect(startFlow).toHaveBeenCalledWith(['d1'])
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 39340a4ed..b65bc7a68 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -11,6 +11,7 @@ import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, be
import { fmtNum, fmtPlate, exerciseNameText, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
import { speedUnitOf, toSpeed, fromSpeed } from '../lib/speed.js'
import { beep, vibrate, unlock } from '../lib/sound.js'
+import { pinState } from '../lib/queue.js'
import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'
import { api, beacon } from '../lib/api.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from '../lib/supersetFlow.js'
@@ -43,7 +44,7 @@ function StartChooser() {
const todayIds = effectiveRoutineIds(S, todayISO())
const todayRoutines = effectiveRoutines(S, todayISO())
const todayName = todayRoutines.map(r => r.name).join(' + ')
- const todayOvr = S.dayPlan[todayISO()] !== undefined
+ const todayOvr = S.dayPlan[todayISO()] !== undefined && pinState(S, S.dayPlan[todayISO()]) !== 'done' // a fulfilled pin is no override
const idSet = new Set(todayIds)
const others = S.routines.filter(r => !idSet.has(r.id))
return <div className="narrow">