Commit 819c11d5 by PLN (Algolia)

couple: per-questionnaire erase on the home rows

A discreet Effacer appears on each answered row (two-tap inline confirm,
same grammar as the full erase); fresh questionnaires have nothing to erase
so no affordance. engine.deleteRecord removes couple:v1:q:<qid> only:
session, carnet and guide writing survive.
parent 315294d5
......@@ -15,6 +15,7 @@ import {
allItems,
answeredCount,
deleteAllCoupleKeys,
deleteRecord,
displayTitle,
downloadExport,
firstUnanswered,
......@@ -67,6 +68,7 @@ export default function HomeView({ goIntro, goQuiz, goRecap, trackWrite, goCompa
const [journey, setJourney] = useState(null);
const [padCount, setPadCount] = useState(0);
const [confirmingDelete, setConfirmingDelete] = useState(false);
const [rowConfirmQid, setRowConfirmQid] = useState(null);
const [shareAllOpen, setShareAllOpen] = useState(false);
const [compareLink, setCompareLink] = useState('');
const [compareError, setCompareError] = useState(false);
......@@ -92,11 +94,21 @@ export default function HomeView({ goIntro, goQuiz, goRecap, trackWrite, goCompa
var handleDelete = function () {
deleteAllCoupleKeys();
setConfirmingDelete(false);
setRowConfirmQid(null);
setSession(readSession());
setJourney(computeJourney());
setPadCount(0);
};
/* Effacement d'une seule ligne : deux appuis en ligne, comme la
suppression totale. Le composant remonte à chaque rendu, l'état des
autres lignes reste frais. */
var handleRowDelete = function (qid) {
trackWrite(deleteRecord(qid));
setRowConfirmQid(null);
setJourney(computeJourney());
};
var start = function () {
var q = journey.resumeQ;
if (!q) return;
......@@ -180,9 +192,21 @@ export default function HomeView({ goIntro, goQuiz, goRecap, trackWrite, goCompa
var rowPct = total > 0 ? Math.round((n / total) * 100) : 0;
return (
<li key={q.id}>
{rowConfirmQid === q.id ? (
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1 py-3.5">
<span className="text-sm text-[#8a3d2e]">{strings.home.rowDeleteConfirm}</span>
<button type="button" className="text-sm font-bold text-[#8a3d2e] underline underline-offset-2 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b85c48]" onClick={function () { handleRowDelete(q.id); }}>
{strings.home.rowDeleteYes}
</button>
<button type="button" className="text-sm text-[#6f675c] underline underline-offset-2 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b85c48]" onClick={function () { setRowConfirmQid(null); }}>
{strings.home.rowDeleteNo}
</button>
</div>
) : (
<div className="flex items-center">
<button
type="button"
className="flex w-full items-center gap-4 py-3.5 text-left transition hover:bg-[#faf3ea] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[#b85c48]"
className="flex min-w-0 flex-1 items-center gap-4 py-3.5 text-left transition hover:bg-[#faf3ea] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[#b85c48]"
onClick={function () { cardClick(q, goIntro, goQuiz, goRecap); }}
>
<span className="min-w-0 flex-1">
......@@ -204,6 +228,18 @@ export default function HomeView({ goIntro, goQuiz, goRecap, trackWrite, goCompa
: strings.home.cardQuestions(total)}
</span>
</button>
{n > 0 && (
<button
type="button"
aria-label={displayTitle(q.title) + ' : ' + strings.home.rowDelete}
className="shrink-0 px-2 py-3 text-sm text-[#6f675c] underline-offset-2 hover:text-[#8a3d2e] hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b85c48]"
onClick={function () { setRowConfirmQid(q.id); }}
>
{strings.home.rowDelete}
</button>
)}
</div>
)}
</li>
);
})}
......
......@@ -276,6 +276,17 @@ export function writeSession(s) {
}
}
/* Suppression d'un seul questionnaire : la clé couple:v1:q:<qid> disparaît,
le reste (session, carnet, écrits du guide) reste en place. */
export function deleteRecord(qid) {
try {
window.localStorage.removeItem(LS + 'q:' + qid);
return true;
} catch (e) {
return false;
}
}
/* Suppression complète : on itère localStorage PAR INDEX DE CLÉ, on collecte
chaque clé couple:v1:*, on les efface. Les valeurs ne sont jamais lues. */
export function deleteAllCoupleKeys() {
......
......@@ -34,6 +34,10 @@ export const strings = {
cardQuestions: (total) => total + ' questions',
cardWorksheet: (total) => total + ' écrits à compléter',
cardPartial: (n, total) => 'En cours · ' + n + ' sur ' + total,
rowDelete: 'Effacer',
rowDeleteConfirm: 'Effacer les réponses de ce questionnaire seulement ?',
rowDeleteYes: 'Effacer',
rowDeleteNo: 'Garder',
togetherTitle: 'À deux, et pour la séance',
togetherIntro:
'Un lien avec toutes vos réponses, un document PDF à apporter en séance, ou la comparaison côte à côte avec la personne que vous aimez.',
......
const { chromium } = require('@playwright/test');
const BASE = 'http://localhost:4310';
const log = (...a) => console.log('[kb]', ...a);
let n = 0;
const shot = async (page, name) => { await page.screenshot({ path: `/tmp/icp-keyboard-native-${++n}-${name}.png` }); log(`shot ${n}: ${name}`); };
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const errors = [];
page.on('console', (m) => { if (m.type() === 'error') errors.push('console: ' + m.text()); });
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
page.on('download', (d) => log('DOWNLOAD fired:', d.suggestedFilename()));
const focusOf = () => page.evaluate(() => {
const el = document.activeElement;
return (!el || el === document.body) ? 'BODY' : el.tagName + ' "' + (el.textContent || '').trim().slice(0, 40) + '"';
});
const tabUntil = async (re, max = 14) => {
for (let i = 0; i < max; i++) {
const f = await focusOf();
if (re.test(f)) return { f, tabs: i };
await page.keyboard.press('Tab');
}
return { f: 'NOT FOUND', tabs: -1 };
};
const qText = () => page.evaluate(() => (document.querySelector('h2') || { innerText: '' }).innerText.trim().slice(0, 60));
await page.goto(BASE + '/tdah/', { waitUntil: 'networkidle' });
await page.waitForTimeout(700);
await page.keyboard.press('Tab'); await page.keyboard.press('Space');
await page.keyboard.press('Tab'); await page.keyboard.press('Enter');
await page.waitForTimeout(350);
await page.keyboard.press('Tab'); await page.keyboard.press('Enter');
await page.waitForTimeout(350);
// --- double-advance timing test on Q1/Q2/Q3 ---
const q0 = await qText();
await page.keyboard.press('4'); // answer Q1
await page.waitForTimeout(80); // then Enter fast (<350ms)
await page.keyboard.press('Enter');
await page.waitForTimeout(700); // let any pending auto-advance fire
const q1 = await qText();
log('DOUBLE-ADVANCE TEST: Q1=', q0.slice(0, 40), '→ after digit+fast-Enter landed on:', q1.slice(0, 40));
log(' expected next (Q2) would be priority question; landed on:', q1.slice(0, 50));
// --- slow rhythm: digit, wait 600ms, Enter ---
const before = await qText();
await page.keyboard.press('2');
await page.waitForTimeout(600);
await page.keyboard.press('Enter');
await page.waitForTimeout(500);
log('SLOW rhythm from "', before.slice(0, 40), '" landed on:', (await qText()).slice(0, 40));
// --- now finish whole quiz with safe rhythm (wait 500ms after digit) ---
for (let step = 1; step <= 160; step++) {
const s = await page.evaluate(() => {
const btns = Array.from(document.querySelectorAll('button')).filter((b) => b.getBoundingClientRect().height > 0);
const act = btns.filter((b) => /^(Continuer →|Télécharger|Recommencer|Imprimer|Répondre aux|Passer la partie|Voir mes)/.test((b.textContent || '').trim()));
const pills = btns.filter((b) => /jamais|rare|souvent|oui|non|plutôt|pas du|un peu|beaucoup|tout à fait/i.test((b.textContent || '').trim()));
return { act: act.map((b) => b.textContent.trim().slice(0, 35)), hasPills: pills.length > 0,
h1: (document.querySelector('h1,h2') || { innerText: '' }).innerText.trim().slice(0, 60) };
});
if (s.act.length && !s.hasPills) {
if (/Télécharger|Recommencer/.test(s.act.join(' '))) { log('FINAL RESULTS at step', step, '| h:', s.h1); break; }
// recap and gates: tab to a non-jump action (Voir mes résultats / Continuer / etc.)
const r = await tabUntil(/"(Continuer →|Répondre aux|Passer la partie|Voir mes|Passer les)/);
if (r.tabs < 0) { log('cannot reach action on screen:', s.h1, JSON.stringify(s.act)); await shot(page, 'stuck-' + step); break; }
await page.keyboard.press('Enter');
await page.waitForTimeout(350);
continue;
}
if (!s.hasPills) { log('unknown screen at', step, JSON.stringify(s)); break; }
const binary = await page.evaluate(() => {
const bs = Array.from(document.querySelectorAll('button')).filter((x) => /^(Oui|Non)$/.test((x.textContent || '').trim()) && x.getBoundingClientRect().height > 0);
return bs.length === 2 && !/Jamais/.test(document.body.innerText);
});
await page.keyboard.press(binary ? (step % 3 ? '1' : '2') : ['3', '2', '4', '1', '3', '5', '2', '4'][step % 8]);
await page.waitForTimeout(520); // let auto-advance fire alone when it will
const s2 = await page.evaluate(() => {
const btns = Array.from(document.querySelectorAll('button')).filter((b) => b.getBoundingClientRect().height > 0);
return btns.some((b) => /jamais|rare|souvent|oui|non|plutôt|pas du/i.test((b.textContent || '').trim()));
});
if (s2) { await page.keyboard.press('Enter'); await page.waitForTimeout(200); } // no auto-advance (block end) → Enter
}
await page.waitForTimeout(700);
const prog = await page.evaluate(() => (document.body.innerText.match(/\d+ questions? répondue?s?(?: · \S+ \d+)?/) || [null])[0]);
log('final progress:', prog);
await shot(page, 'true-final');
log('final head:', (await page.evaluate(() => document.body.innerText.slice(0, 800))).replace(/\s+\n/g, '\n'));
const dl = await tabUntil(/Télécharger/i);
log('tabs to Télécharger:', dl.tabs, dl.f);
await page.keyboard.press('Enter');
await page.waitForTimeout(2500);
await shot(page, 'after-pdf-enter');
log('CONSOLE ERRORS:', errors.length ? JSON.stringify(errors) : '(clean)');
await browser.close();
})().catch((e) => { console.error('DRIVER FAIL', e); process.exit(1); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment