From 6ba9992e55b27892da238c8ed338745e14ccbc8a Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Thu, 29 Oct 2026 09:09:31 -0400 Subject: [PATCH] Family board: choosing a goal from the chore picker returns to it with the new progress bar --- public/board.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/board.js b/public/board.js index ec793e6..9dc2d2e 100644 --- a/public/board.js +++ b/public/board.js @@ -12,11 +12,11 @@ function weekCard(w) { return w.people.map(p => { const mine = w.tiers.filter(t => p.tiers.includes(t.id)), goal = mine.find(t => t.id === p.goal), top = Math.max(1, goal ? goal.points : 0, p.points); return `
${esc(p.name)}${p.points} pts ยท ${p.count} done
${goal ? `` : ''}
${goal ? `${p.points >= goal.points ? '๐ŸŽฏ ' + esc(goal.title) + ' reached! ๐ŸŽ‰' : '๐ŸŽฏ ' + (goal.points - p.points) + ' more for ' + esc(goal.title)}` : mine.length ? `` : ''}
`; }).join(''); } // ---- Choose a reward to aim for: pick it from a pop-up, then PIN (unless a child with no PIN), and it is set as that person -function goalFlow(pid) { +function goalFlow(pid, back) { const p = data.people.find(x => x.id === pid), w = data.week; if (!p || !w) return; const mine = w.tiers.filter(t => ((w.people.find(x => x.id === pid) || {}).tiers || []).includes(t.id)); const { box, close } = sheet(`

${esc(p.name.split(' ')[0])}, what are you aiming for?

Pick one reward for this week.

${mine.map(t => ``).join('')}

`); box.querySelector('#no').onclick = close; - const send = async (reward, pin) => { const r = await fetch('/api/board/goal', { method: 'POST', body: JSON.stringify({ uid: p.id, pin, reward, date: ymd(new Date()) }) }), j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error || 'That did not work'); close(); await load(); toast('Goal chosen'); }; + const send = async (reward, pin) => { const r = await fetch('/api/board/goal', { method: 'POST', body: JSON.stringify({ uid: p.id, pin, reward, date: ymd(new Date()) }) }), j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error || 'That did not work'); const wp = data.week && data.week.people.find(x => x.id === p.id); if (wp) wp.goal = reward || null; close(); await load(); if (back) back(pin); else toast('Goal chosen'); }; box.querySelectorAll('[data-g]').forEach(b => b.onclick = () => { const reward = b.dataset.g; if (p.kid && !p.pin) return send(reward).catch(e => { box.querySelector('#e').textContent = e.message; }); if (!p.pin) { box.querySelector('#e').textContent = p.name + ' has not set a PIN yet. Set one in Settings on your own device.'; return; } @@ -115,8 +115,8 @@ function whoThen(title, payload, doneMsg) { function toast(msg) { let t = document.getElementById('bt'); if (!t) { t = document.createElement('div'); t.id = 'bt'; t.style.cssText = 'position:fixed;left:50%;bottom:24px;transform:translateX(-50%);background:var(--panel2);border:1px solid var(--line);padding:12px 20px;border-radius:20px;font-size:18px;z-index:99'; document.body.appendChild(t); } t.textContent = msg; t.hidden = false; clearTimeout(t._t); t._t = setTimeout(() => { t.hidden = true; }, 2500); } // ---- Pick your chores: tap your name, enter your PIN once (a child with no PIN goes straight in), then do, take or put back as many chores as you like -function choreHub(p) { - if (!p) return; let pin = ''; +function choreHub(p, pin0) { + if (!p) return; let pin = pin0 || ''; const { box, close } = sheet(''), today = ymd(new Date()), head = `
${esc((p.name.trim()[0] || '?').toUpperCase())}

${esc(p.name.split(' ')[0])}'s chores

`; const act = async (c, action) => { const r = await fetch('/api/board/chore', { method: 'POST', body: JSON.stringify({ uid: p.id, pin, chore: c.chore, action, date: today }) }), j = await r.json().catch(() => ({})); if (!r.ok) { if (p.pin && /pin/i.test(j.error || '')) { pin = ''; return askPin(j.error); } box.querySelector('#e').textContent = j.error || 'That did not work'; return; } await load(); paint(); }; const paint = () => { @@ -128,7 +128,7 @@ function choreHub(p) { + (pool.length ? h('Up for grabs. Take one!') + pool.map(c => row(c, ``)).join('') : '') + (done.length ? h('Finished') + done.map(c => row(c, ``, 'dn')).join('') : '') + `
`; - const pg = box.querySelector('#pgl'); if (pg) pg.onclick = e => { e.preventDefault(); close(); goalFlow(p.id); }; + const pg = box.querySelector('#pgl'); if (pg) pg.onclick = e => { e.preventDefault(); close(); goalFlow(p.id, pn => choreHub(p, pn)); }; box.querySelector('#no').onclick = close; box.querySelector('#sgn').onclick = () => { close(); pick(p); }; box.querySelectorAll('[data-a]').forEach(b => b.onclick = () => { b.disabled = true; const c = data.chores.find(x => x.chore === b.dataset.c && (x.user || '') === b.dataset.u); if (c) act(c, b.dataset.a); else { b.disabled = false; load().then(paint); } }); }; @@ -137,5 +137,5 @@ function choreHub(p) { const dots = () => { box.querySelector('#dots').innerHTML = Array.from({ length: Math.max(4, pin.length) }, (_, i) => ``).join(''); }; dots(); box.querySelector('#no').onclick = close; box.querySelectorAll('.pad button').forEach(b => b.onclick = () => { let k = b.dataset.k; box.querySelector('#e').textContent = ''; if (k === 'โŒซ') pin = pin.slice(0, -1); else if (k !== 'โœ“' && pin.length < 8) { pin += k; if (p.pinLen && pin.length === p.pinLen) k = 'โœ“'; } if (k === 'โœ“') { if (pin) return paint(); } dots(); }); }; - if (p.kid && !p.pin) return paint(); if (!p.pin) { box.innerHTML = head + `

${esc(p.name)} has not set a PIN yet. Set one in Settings on your own device.

`; box.querySelector('#no').onclick = close; return; } askPin(); + if (p.kid && !p.pin || pin0) return paint(); if (!p.pin) { box.innerHTML = head + `

${esc(p.name)} has not set a PIN yet. Set one in Settings on your own device.

`; box.querySelector('#no').onclick = close; return; } askPin(); }