diff --git a/app/app.js b/app/app.js index 393f6e0..078a56b 100644 --- a/app/app.js +++ b/app/app.js @@ -1097,6 +1097,34 @@ function exercisePicker(onPick) { draw(); } +/* ---------- add exercise straight to a routine (from library browsing) ---------- */ +function addToRoutineSheet(ex) { + const m = openModal(` +

Add โ€œ${esc(ex.n)}โ€

+
Pick a routine โ€” sets, reps & weight come next.
+
+ ${S.routines.map(r => `
+
${r.emoji || '๐Ÿ’ช'}
+
${esc(r.name)}
${r.ex.length} exercises
+ ${r.ex.some(e => e.id === ex.id) ? 'already in' : ''}๏ผ‹
`).join('')} +
โœจ
+
New routine
Create one and start with this exercise
๏ผ‹
+
`); + m.el.querySelectorAll('[data-r]').forEach(el => el.addEventListener('click', () => { + m.close(); + const isNew = el.dataset.r === '_new'; + let r = isNew ? null : S.routines.find(x => x.id === el.dataset.r); + exConfigSheet(ex, null, cfg => { + if (isNew) { r = { id: uid(), name: 'New routine', emoji: '๐Ÿ’ช', ex: [] }; S.routines.push(r); } + if (!r) return; + r.ex.push({ id: ex.id, ...cfg }); + save(); + toast('โ€œ' + ex.n + 'โ€ added to ' + r.name + ' โœ“'); + if (isNew) nav('#plan/r/' + r.id); + }); + })); +} + /* ---------- exercise config (sets/reps/weight) ---------- */ function stepperHTML(id, val, step, label) { return `
${label}
@@ -1658,9 +1686,13 @@ function viewLibrary(app) {
${esc(e.n)}
${e.tg || e.bp} ยท ${e.eq}
${bestWeightFor(e.id) ? `${fmtNum(bestWeightFor(e.id))}` : ''} - โ€บ
`).join('') || '
No match ๐Ÿคท
'; + `).join('') || '
No match ๐Ÿคท
'; moreBtn.style.display = f.length > libShown ? '' : 'none'; listEl.querySelectorAll('[data-ex]').forEach(el => el.addEventListener('click', () => exerciseDetailSheet(EXIDX[el.dataset.ex]))); + listEl.querySelectorAll('[data-addex]').forEach(b => b.addEventListener('click', ev => { + ev.stopPropagation(); + addToRoutineSheet(EXIDX[b.dataset.addex]); + })); } moreBtn.onclick = () => { libShown += 40; draw(); }; $('#lib-q').addEventListener('input', ev => { libQ = ev.target.value.toLowerCase().trim(); libShown = 40; draw(); }); @@ -1680,9 +1712,11 @@ function exerciseDetailSheet(ex) { ${(ex.sm || []).slice(0, 3).map(s => `${s}`).join('')} ${best ? `
๐Ÿ† Best: ${fmtNum(best)} ${S.unit}${last ? ` ยท last ${fmtDate(last.d)}: ${last.sets.map(s => fmtNum(s.w) + 'ร—' + s.r).join(', ')}` : ''}
` : ''} + ${ex.st && ex.st.length ? `

How to

    ${ex.st.map(s => `
  1. ${esc(s)}
  2. `).join('')}
` : ''} `); bindMediaToggle(m.el.querySelector('.exmedia'), ex); + m.el.querySelector('#dt-add').onclick = () => { m.close(); addToRoutineSheet(ex); }; } /* ============================================================ diff --git a/app/index.html b/app/index.html index 22a25ba..d144674 100644 --- a/app/index.html +++ b/app/index.html @@ -13,7 +13,7 @@ - +
๐Ÿ‹๏ธ
@@ -45,7 +45,7 @@
- - + + diff --git a/app/sw.js b/app/sw.js index 8eda0e5..fcd1466 100644 --- a/app/sw.js +++ b/app/sw.js @@ -1,6 +1,6 @@ /* GymLog service worker โ€” network-first for app shell, cache-first for media */ -const CACHE = 'gymlog-v11'; -const SHELL = ['./', 'index.html', 'style.css?v=11', 'app.js?v=11', 'data.js?v=11', 'manifest.json']; +const CACHE = 'gymlog-v12'; +const SHELL = ['./', 'index.html', 'style.css?v=12', 'app.js?v=12', 'data.js?v=12', 'manifest.json']; self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).then(() => self.skipWaiting()));