v1.3.4: effort picker restyled as a menu list, media falls back to the still or a tile instead of a broken image

This commit is contained in:
Duarte Santos committed 2026-09-05 15:03:52 +02:00
1 parent 4e015ec74d
commit 9c7c351345
11 files changed
+88 -88

No files matched your search

+17 -3
View File
@@ -13,21 +13,35 @@ import Icon from './Icon.jsx'
// a custom exercise without media. Any other/legacy value behaves as 'full'.
export default function Media({ ex, id, compact, minimizable }) {
const [playing, setPlaying] = useState(true)
// 'gif' → the animation failed, the still is showing; 'all' → the still failed too. Media is
// fetched from wherever the build points (a mount, a CDN): a dropped connection, an expired
// session on a gated instance or a CDN hiccup used to leave the browser's broken-image glyph
// on a white block. Now the still stands in for the animation, a neutral tile stands in for
// both, and a tap tries again — no text, so nothing new to translate.
const [failed, setFailed] = useState(null)
const gifSize = useStore(s => s.S.gifSize)
const update = useStore(s => s.update)
if (!ex.gif) return null
if (minimizable && gifSize === 'off') return null
const mini = minimizable && gifSize === 'mini'
const toggleSize = e => { e.stopPropagation(); update(s => { s.gifSize = mini ? 'full' : 'mini' }) }
const showGif = playing && failed == null
const onError = () => setFailed(showGif ? 'gif' : 'all')
const onTap = () => {
if (failed) { setFailed(null); setPlaying(true); return }
setPlaying(p => !p)
}
return (
<div className={'exmedia' + (compact ? ' compact' : '') + (mini ? ' mini' : '')} id={id} onClick={() => setPlaying(p => !p)}>
<img decoding="async" draggable={false} src={playing ? gifSrc(ex) : imgSrc(ex)} alt={exerciseNameFor(ex)} />
<div className={'exmedia' + (compact ? ' compact' : '') + (mini ? ' mini' : '') + (failed === 'all' ? ' broken' : '')} id={id} onClick={onTap}>
{failed === 'all'
? <div className="exmedia-x"><Icon name="dumbbell" /></div>
: <img decoding="async" draggable={false} src={showGif ? gifSrc(ex) : imgSrc(ex)} alt={exerciseNameFor(ex)} onError={onError} />}
{minimizable && (
<button className="giftoggle" onClick={toggleSize}>
<Icon name={mini ? 'expand' : 'minimize'} />{mini ? t('Expand') : t('Minimize')}
</button>
)}
{!mini && (
{!mini && !failed && (
<span className="gifhint">
<Icon name={playing ? 'pause' : 'play'} />{playing ? t('tap to pause') : t('tap to play')}
</span>
+17 -43
View File
@@ -639,6 +639,12 @@ h4.sec{
at 180px you had to scroll a full screen between two exercises done back-to-back */
.exmedia.compact img{height:120px}
.exmedia.mini img{height:84px}
/* both the animation and the still failed to load: a neutral tile instead of the browser's
broken-image glyph; same heights as the picture so the card does not jump. tap retries. */
.exmedia.broken{background:var(--surface-2)}
.exmedia-x{width:100%;height:320px;display:flex;align-items:center;justify-content:center;color:var(--label-3);font-size:34px}
.exmedia.compact .exmedia-x{height:120px}
.exmedia.mini .exmedia-x{height:84px}
.sethead{
display:flex;align-items:center;gap:8px;padding:0 0 6px;
@@ -715,50 +721,18 @@ h4.sec{
.setrow.eff3 .effcell-stp>button[aria-label="Increase"]{width:22px}
.setrow.eff3 .effcell-stp .val{font-size:14px}
/* effort quick picker sheet: colour-coded preset buttons, hardest (purple) first */
.effpick{display:grid;grid-template-columns:repeat(2,1fr);gap:9px;margin-bottom:16px}
.effpick-b{
display:flex;flex-direction:column;align-items:flex-start;gap:3px;
padding:12px 14px;border-radius:13px;text-align:left;
background:var(--surface);border:1.5px solid var(--sep-op);
border-left:4px solid var(--bc);
transition:background var(--fast),transform var(--fast),border-color var(--fast);
/* effort picker: the ⋯-menu list with the value in the icon square, tinted per band; the
exact-value row carries the same stepper as the logged cell in the set row. */
.effpick.menu-list .menu-item .effpick-n{
background:var(--bc);color:#fff;font-size:13px;font-weight:700;letter-spacing:-.02em;
font-variant-numeric:tabular-nums;
}
.effpick-b:active{transform:scale(.97)}
.effpick-b.on{background:color-mix(in srgb,var(--bc) 16%,var(--surface));border-color:var(--bc)}
.effpick-n{font-size:20px;font-weight:700;color:var(--bc);line-height:1;font-variant-numeric:tabular-nums}
.effpick-f{font-size:12px;color:var(--label-2);line-height:1.25}
/* the free field sits as a full-width row the same size as a preset button: its "Exact RIR"
label on the left, a −/value/+ group in the middle, and the scale name on the right, same
padding and radius as .effpick-b. the whole row borders in the current band colour. */
.effpick-free{
display:flex;align-items:center;justify-content:space-between;gap:10px;
padding:10px 14px;border-radius:13px;margin-top:2px;
background:var(--surface);border:1.5px solid var(--sep-op);
transition:border-color var(--fast);
}
.effpick-free-l{font-size:14px;color:var(--label-2);flex:none}
.effpick-free-unit{font-size:13px;font-weight:600;color:var(--label-3);flex:none}
/* the −/value/+ group: a rounded surface holding a big tappable number between two step
buttons. tinted (color:inherit) to the band colour when a value is set. */
.effpick-step{
display:flex;align-items:center;gap:2px;flex:none;
background:var(--surface-2);border-radius:10px;overflow:hidden;
}
.effpick-step button{
width:38px;height:40px;flex:none;color:currentColor;font-size:16px;--icon-stroke:2.2;
display:flex;align-items:center;justify-content:center;transition:background var(--fast);
}
.effpick-step button:active{background:var(--surface-3)}
/* the `.num` base styling (transparent bg, no border) is scoped to `.stp .num`; this input is
not in a `.stp`, so it must set its own or the browser paints a native white field. */
.effpick-free-in.num{
flex:none;width:64px;text-align:center;padding:0;height:40px;
background:none;border:none;outline:none;color:currentColor;
font-size:20px;font-weight:700;font-variant-numeric:tabular-nums;
-moz-appearance:textfield;appearance:textfield;
}
.effpick-free-in.num::-webkit-inner-spin-button{display:none}
.effpick-free-in.num::placeholder{color:var(--label-3);font-weight:600}
.effpick .menu-item.on{background:color-mix(in srgb,var(--bc) 14%,var(--surface))}
.effpick .menu-on.is-on{color:var(--bc)}
.effpick .effpick-free{padding-right:8px}
.effpick .effpick-free .stp{flex:none;width:148px}
.effpick .effpick-free .stp .num{font-size:17px;font-weight:600}
.effpick .effpick-free .stp .num::placeholder{color:var(--label-3);font-weight:500}
.setrow.done .n{background:var(--acc);color:var(--on-acc)}
.setrow.done{opacity:.45}
/* drop-set drops / rest-pause bursts riding on a work row, editable like the row itself
+28 -31
View File
@@ -1368,53 +1368,50 @@ export const glyphPicker = (current, onPick) => {
// RPE sees the same buttons labelled on its own scale (toScale), coloured identically — the
// colour is the effort, not the number, so 0 RIR and 10 RPE are both the "went to failure" end.
function EffortPicker({ kind, value, onPick, close }) {
// Local mirror so the highlighted preset and the free field track typing live; the store is
// Local mirror so the ticked preset and the exact field track typing live; the store is
// written on every change through onPick, the same as the stepper did.
const [v, setV] = useState(value ?? null)
const set = nv => { setV(nv); onPick(nv) }
// `v` is in the profile's own scale (whatever sits on the set: s.rir or s.rpe). Compare in
// RIR so the highlighted preset is right on either scale, and so a typed RPE colours the
// RIR so the tick lands on the right preset on either scale, and so a typed RPE colours the
// same as the RIR it equals.
const curRir = rirOf(kind === 'rpe' ? { rpe: v } : { rir: v })
// The band colour for the value currently on the field, so the exact-value row is tinted the
// same way the presets and the workout row cell are — null (nothing typed) stays neutral.
const curColor = effortColor(curRir)
const commit = nv => { close(); onPick(nv) }
const pick = rir => commit(toScale(kind, rir))
const hd = EFFORT[kind].hd
// Same list the ⋯ menus use: a tinted square with the value where the icon goes, the sentence
// as the row title, a tick on the current one. The exact field is the app's own stepper,
// tinted like the logged cell in the set row, so the sheet and the row read as one thing.
return <>
<h3>{t('How hard was that set?')}</h3>
<div className="muted small" style={{ marginBottom: 14, lineHeight: 1.45 }}>
{t('Tap how many reps you had left, or type an exact {0}.', EFFORT[kind].hd)}
</div>
<div className="effpick">
<h3 style={{ marginBottom: 2 }}>{t('How hard was that set?')}</h3>
<div className="muted small" style={{ marginBottom: 10 }}>{t('Tap how many reps you had left, or type an exact {0}.', hd)}</div>
<div className="list menu-list effpick">
{EFFORT_PRESETS.map(p => {
const label = fmtNum(toScale(kind, p.rir)) + (p.tail ? '+' : '')
const on = curRir != null && curRir === p.rir
return <button key={p.rir} className={'effpick-b' + (on ? ' on' : '')}
style={{ '--bc': p.color }} onClick={() => pick(p.rir)}>
<span className="effpick-n">{label}</span>
<span className="effpick-f">{t(p.feel)}</span>
</button>
return <div key={p.rir} className={'item menu-item' + (on ? ' on' : '')} style={{ '--bc': p.color }}
{...tappable(() => pick(p.rir))}>
<span className="lrow-i effpick-n">{label}</span>
<div className="grow"><div className="tt">{t(p.feel)}</div></div>
<span className={'menu-on' + (on ? ' is-on' : '')}><Icon name="check" /></span>
</div>
})}
</div>
{/* The free field keeps the flexibility the stepper had: a value between two presets, in
the profile's own scale, capped to the top of it (there is no RPE 12). Sized like a
preset so it reads as the seventh option — "or type your own" — not an afterthought.
A −/+ pair flanks the number for 0.5-step nudging without leaving the sheet, coloured
by the band the current value falls in (the same colour the presets and the row cell
use); tapping the number itself still types an exact value. */}
<div className="effpick-free" style={curColor ? { borderColor: curColor } : undefined}>
<span className="effpick-free-l">{t('Exact {0}', EFFORT[kind].hd)}</span>
<div className="effpick-step" style={curColor ? { color: curColor } : undefined}>
<button aria-label="Decrease" onClick={() => set(stepEffort(kind, v, -1))}><Icon name="minus" /></button>
<NumberField className="effpick-free-in" decimal nullable value={v ?? ''}
placeholder={EFFORT[kind].hd} onChange={nv => set(capEffort(kind, nv))} />
<button aria-label="Increase" onClick={() => set(stepEffort(kind, v, 1))}><Icon name="plus" /></button>
<div className="item menu-item effpick-free">
<div className="grow"><div className="tt">{t('Exact {0}', hd)}</div></div>
<div className="stp effcell-stp"
style={curColor ? { color: curColor, background: `color-mix(in srgb, ${curColor} 20%, var(--surface-2))` } : undefined}>
<button aria-label="Decrease" onClick={() => set(stepEffort(kind, v, -1))}><Icon name="minus" /></button>
<span className="val"><NumberField decimal nullable value={v ?? ''} placeholder="–"
onChange={nv => set(capEffort(kind, nv))} /></span>
<button aria-label="Increase" onClick={() => set(stepEffort(kind, v, 1))}><Icon name="plus" /></button>
</div>
</div>
<span className="effpick-free-unit">{EFFORT[kind].hd}</span>
</div>
<div style={{ height: 10 }} />
{v != null && <Button variant="ghost" className="dim" icon="xmark" onClick={() => commit(null)}>{t('Clear rating')}</Button>}
{v != null && <>
<div style={{ height: 10 }} />
<Button variant="ghost" className="dim" icon="xmark" onClick={() => commit(null)}>{t('Clear rating')}</Button>
</>}
<div style={{ height: 4 }} />
</>
}