Arbeitsgewicht-Abfrage mit Slider, eigene Bestätigungs-Dialoge, Gewichts-History nur letzte 3
- Die 'Arbeitsgewicht bestätigen'-Abfrage im Workout nutzt jetzt denselben Slider + Plus/Minus (geteilte WeightInput-Komponente) - Alle window.confirm-Systemdialoge durch eigene, app-farbige Center-Dialoge ersetzt (confirmSheet): Workout verwerfen/vorzeitig beenden, Routine/Workout löschen, Abmelden, Reset, Backup importieren - Log-Sheet zeigt nur noch die letzten 3 Gewichts-Einträge
This commit is contained in:
1 parent
64f33dd3bd
commit
6e473a9815
4 files changed
+48
-28
No files matched your search
+30
-11
@@ -15,6 +15,21 @@ const ui = () => useUI.getState()
|
||||
const toast = m => ui().toast(m)
|
||||
const snd = () => S().sound
|
||||
|
||||
/* ============================ custom confirm dialog ============================ */
|
||||
function ConfirmDialog({ title, message, confirmText, cancelText, danger, onConfirm, close }) {
|
||||
return <div style={{ textAlign: 'center', padding: '4px 0' }}>
|
||||
{title && <h3 style={{ marginBottom: 8 }}>{title}</h3>}
|
||||
<div className="muted" style={{ marginBottom: 18, lineHeight: 1.5 }}>{message}</div>
|
||||
<button className={'btn ' + (danger ? 'danger' : 'primary')} onClick={() => { close(); onConfirm && onConfirm() }}>{confirmText || 'Confirm'}</button>
|
||||
<div style={{ height: 8 }} />
|
||||
<button className="btn ghost dim" onClick={close}>{cancelText || 'Cancel'}</button>
|
||||
</div>
|
||||
}
|
||||
// Themed replacement for window.confirm — callback-based (no blocking).
|
||||
export function confirmSheet(opts) {
|
||||
ui().openSheet(close => <ConfirmDialog {...opts} close={close} />, { kind: 'center' })
|
||||
}
|
||||
|
||||
/* ============================ starter plan ============================ */
|
||||
export function loadStarterPlan() {
|
||||
const mk = (name, emoji, list) => ({ id: uid(), name, emoji, ex: list.map(([id, sets, reps]) => ({ id, sets, reps, weight: 0 })) })
|
||||
@@ -66,7 +81,7 @@ function BwSheet({ required, onDone, close }) {
|
||||
close()
|
||||
if (onDone) onDone(n); else toast('Weight saved ✓')
|
||||
}
|
||||
const recent = [...st.bodyweight].reverse().slice(0, 6)
|
||||
const recent = [...st.bodyweight].reverse().slice(0, 3)
|
||||
const delEntry = d => update(s => { s.bodyweight = s.bodyweight.filter(b => b.d !== d) })
|
||||
return <>
|
||||
<h3>{required ? 'Quick check-in ⚖️' : 'Log body weight'}</h3>
|
||||
@@ -315,7 +330,7 @@ function WorkoutDetail({ w, close }) {
|
||||
<div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s)).join(' · ') || 'no sets'}</div></div>
|
||||
</div>
|
||||
})}
|
||||
<button className="btn danger" onClick={() => { if (confirm('Delete this workout from history?')) { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast('Workout deleted') } }}>Delete workout</button>
|
||||
<button className="btn danger" onClick={() => confirmSheet({ title: 'Delete workout?', message: 'This removes it from your history for good.', confirmText: 'Delete', danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast('Workout deleted') } })}>Delete workout</button>
|
||||
</>
|
||||
}
|
||||
export const workoutDetailSheet = w => ui().openSheet(close => <WorkoutDetail w={w} close={close} />)
|
||||
@@ -396,9 +411,7 @@ function TopWeight({ entryIdx, close }) {
|
||||
const ex = EXIDX[entry.id]
|
||||
const maxSet = Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0))
|
||||
const prevBest = Math.max((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id))
|
||||
const [v, setV] = useState(String(Math.max(maxSet, prevBest) || entry.target.weight || 0))
|
||||
const ref = useRef(null)
|
||||
useEffect(() => { setTimeout(() => { ref.current?.focus(); ref.current?.select() }, 250) }, [])
|
||||
const [v, setV] = useState(Math.max(maxSet, prevBest) || entry.target.weight || 0)
|
||||
|
||||
const units = supersetUnits(A.entries)
|
||||
const unit = unitOf(units, entryIdx)
|
||||
@@ -407,7 +420,7 @@ function TopWeight({ entryIdx, close }) {
|
||||
const isLastUnit = unitIdx === units.length - 1
|
||||
|
||||
const commit = advance => {
|
||||
const n = parseFloat(v)
|
||||
const n = Math.round((v || 0) * 10) / 10
|
||||
if (!isFinite(n) || n < 0) { toast('Enter a valid weight'); return }
|
||||
update(s => {
|
||||
s.active.entries[entryIdx].topW = n
|
||||
@@ -423,7 +436,8 @@ function TopWeight({ entryIdx, close }) {
|
||||
return <>
|
||||
<h3 className="capitalize">✅ {ex.n} done</h3>
|
||||
<div className="muted small">Confirm the weight you worked with — your highest becomes the default next time.{!unitDone && unit.length > 1 ? ' Then finish the superset partner.' : ''}</div>
|
||||
<div className="bwin"><input ref={ref} type="number" inputMode="decimal" step="0.5" value={v} onChange={e => setV(e.target.value)} /><span>{st.unit}</span></div>
|
||||
<WeightInput value={v} setValue={setV} unit={st.unit} />
|
||||
<div style={{ height: 10 }} />
|
||||
{prevBest > 0 ? <div className="small dim" style={{ textAlign: 'center', marginBottom: 12 }}>Previous best: {fmtNum(prevBest)} {st.unit}{maxSet > prevBest && <span style={{ color: 'var(--gold)' }}> — new record! 🏆</span>}</div> : <div style={{ height: 4 }} />}
|
||||
{unitDone ? <>
|
||||
<button className="btn primary" onClick={() => commit(true)}>{isLastUnit ? 'Save ✓' : 'Save & next exercise ›'}</button>
|
||||
@@ -462,13 +476,18 @@ function FinishSummary({ w, prs, close }) {
|
||||
</div>
|
||||
}
|
||||
export function finishWorkout() {
|
||||
const st = S()
|
||||
const A = st.active
|
||||
const A = S().active
|
||||
if (!A) return
|
||||
const done = setsDoneActive(A)
|
||||
const total = A.entries.reduce((n, e) => n + e.sets.length, 0)
|
||||
if (!done && !confirm('No sets logged — finish anyway?')) return
|
||||
if (done < total && done > 0 && !confirm('Some sets are unchecked. Finish workout?')) return
|
||||
if (!done) { confirmSheet({ title: 'Nothing logged yet', message: 'You haven’t checked off any sets. Finish the workout anyway?', confirmText: 'Finish anyway', onConfirm: doFinishWorkout }); return }
|
||||
if (done < total) { confirmSheet({ title: 'Finish early?', message: `${total - done} set${total - done === 1 ? '' : 's'} still unchecked. Finish the workout now?`, confirmText: 'Finish workout', onConfirm: doFinishWorkout }); return }
|
||||
doFinishWorkout()
|
||||
}
|
||||
function doFinishWorkout() {
|
||||
const st = S()
|
||||
const A = st.active
|
||||
if (!A) return
|
||||
const prs = []
|
||||
A.entries.forEach(e => {
|
||||
const mx = Math.max(0, ...e.sets.filter(s => s.done).map(s => s.w))
|
||||
|
||||
@@ -5,7 +5,7 @@ import { EXIDX, isCardio } from '../lib/exercises.js'
|
||||
import { fmtNum, uid } from '../lib/format.js'
|
||||
import { supersetUnits } from '../lib/history.js'
|
||||
import { Thumb } from '../components/Media.jsx'
|
||||
import { emojiPicker, exercisePicker, exConfigSheet } from '../sheets.jsx'
|
||||
import { emojiPicker, exercisePicker, exConfigSheet, confirmSheet } from '../sheets.jsx'
|
||||
|
||||
// drop superset ids that no longer have an adjacent partner (after unlink/reorder)
|
||||
function cleanupSg(ex) {
|
||||
@@ -71,14 +71,16 @@ export default function RoutineEdit() {
|
||||
<div className="small dim" style={{ margin: '10px 2px' }}>Tip: tap 🔗 on an exercise to superset it with the one above — you’ll do them back-to-back.</div>
|
||||
<button className="btn primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) })))}>+ Add exercise</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn danger" onClick={() => {
|
||||
if (!confirm('Delete "' + r.name + '"?')) return
|
||||
update(s => {
|
||||
s.routines = s.routines.filter(x => x.id !== id)
|
||||
Object.keys(s.week).forEach(k => { if (s.week[k] === id) delete s.week[k] })
|
||||
Object.keys(s.dayPlan).forEach(k => { if (s.dayPlan[k] === id) delete s.dayPlan[k] })
|
||||
})
|
||||
nav('/plan')
|
||||
}}>Delete routine</button>
|
||||
<button className="btn danger" onClick={() => confirmSheet({
|
||||
title: 'Delete routine?', message: `“${r.name}” and its exercises will be removed.`, confirmText: 'Delete', danger: true,
|
||||
onConfirm: () => {
|
||||
update(s => {
|
||||
s.routines = s.routines.filter(x => x.id !== id)
|
||||
Object.keys(s.week).forEach(k => { if (s.week[k] === id) delete s.week[k] })
|
||||
Object.keys(s.dayPlan).forEach(k => { if (s.dayPlan[k] === id) delete s.dayPlan[k] })
|
||||
})
|
||||
nav('/plan')
|
||||
}
|
||||
})}>Delete routine</button>
|
||||
</div>
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { useStore, DEF, hasData } from '../store/useStore.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { ACCENTS, todayISO } from '../lib/format.js'
|
||||
import { webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js'
|
||||
import { loadStarterPlan } from '../sheets.jsx'
|
||||
import { loadStarterPlan, confirmSheet } from '../sheets.jsx'
|
||||
|
||||
export default function Settings() {
|
||||
const nav = useNavigate()
|
||||
@@ -26,8 +26,7 @@ export default function Settings() {
|
||||
try {
|
||||
const data = JSON.parse(rd.result)
|
||||
if (!data.workouts || !data.routines) throw new Error('not an openGym backup')
|
||||
if (!confirm('Replace all current data with this backup?')) return
|
||||
replaceState(Object.assign(JSON.parse(JSON.stringify(DEF)), data), true); toast('Backup imported ✓')
|
||||
confirmSheet({ title: 'Import backup?', message: 'This replaces all current data with the backup file.', confirmText: 'Import', danger: true, onConfirm: () => { replaceState(Object.assign(JSON.parse(JSON.stringify(DEF)), data), true); toast('Backup imported ✓') } })
|
||||
} catch (e) { toast('Import failed: ' + e.message) }
|
||||
}
|
||||
rd.readAsText(f)
|
||||
@@ -45,7 +44,7 @@ export default function Settings() {
|
||||
<h2>Account</h2>
|
||||
{user ? <div className="row between">
|
||||
<div><b>{user.name}</b><div className="small muted">Signed in with passkey — data syncs to this profile.</div></div>
|
||||
<button className="btn sm danger" onClick={() => { if (confirm('Sign out? Local data is synced to your profile first, then cleared from this device.')) { signOut(); nav('/home') } }}>Sign out</button>
|
||||
<button className="btn sm danger" onClick={() => confirmSheet({ title: 'Sign out?', message: 'Your data is synced to your profile first, then cleared from this device.', confirmText: 'Sign out', danger: true, onConfirm: () => { signOut(); nav('/home') } })}>Sign out</button>
|
||||
</div> : <>
|
||||
<div className="small muted" style={{ marginBottom: 10 }}>Guest mode — data lives only in this browser. Create a passkey profile to keep it safe and separate per person.</div>
|
||||
{webauthnOK() ? <>
|
||||
@@ -89,7 +88,7 @@ export default function Settings() {
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={() => fileRef.current.click()}>⬆️ Import backup</button>
|
||||
<input ref={fileRef} type="file" accept=".json,application/json" style={{ display: 'none' }} onChange={doImport} />
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={loadStarterPlan}>Load starter plan (PPL)</button>
|
||||
<div style={{ height: 8 }} /><button className="btn danger" onClick={() => { if (confirm('Delete ALL data (plan, workouts, body weight)?') && confirm('Really sure? This cannot be undone.')) { replaceState(JSON.parse(JSON.stringify(DEF)), true); nav('/home'); toast('All data reset') } }}>Reset everything</button>
|
||||
<div style={{ height: 8 }} /><button className="btn danger" onClick={() => confirmSheet({ title: 'Reset everything?', message: 'Deletes your plan, workouts and body weight on this device. This cannot be undone.', confirmText: 'Delete everything', danger: true, onConfirm: () => { replaceState(JSON.parse(JSON.stringify(DEF)), true); nav('/home'); toast('All data reset') } })}>Reset everything</button>
|
||||
</div>
|
||||
|
||||
<div className="card"><h2>Tip</h2>
|
||||
|
||||
@@ -7,7 +7,7 @@ import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, setsDoneActiv
|
||||
import { fmtNum, fmtDate, todayISO, DAYN } from '../lib/format.js'
|
||||
import { beep, vibrate } from '../lib/sound.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet } from '../sheets.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet } from '../sheets.jsx'
|
||||
|
||||
/* ---------- start chooser (no active workout) ---------- */
|
||||
function StartChooser() {
|
||||
@@ -144,7 +144,7 @@ function ActiveWorkout() {
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" onClick={() => { if (confirm('Discard this workout? Logged sets will be lost.')) { update(s => { s.active = null }); stopRest(); nav('/home') } }}>✕</button>
|
||||
<button className="iconbtn" onClick={() => confirmSheet({ title: 'Discard workout?', message: 'The sets you logged in this session will be lost.', confirmText: 'Discard', danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); nav('/home') } })}>✕</button>
|
||||
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 800 }}>{A.name}</div><div className="sub"><Elapsed start={A.start} /> · {done}/{total} sets</div></div>
|
||||
<button className="iconbtn" style={{ color: 'var(--acc)' }} onClick={finishWorkout}>✓</button>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user