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 => `- ${esc(s)}
`).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 @@
-
-
+
+