From cc1ac91253693480b2bf2fcdb0c8dfa060abbd30 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 19 Mar 2026 20:33:42 +0100 Subject: [PATCH] Use history stack approach --- tests/e2e/integration.spec.js | 10 ++++------ web/src/js/app.js | 37 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/tests/e2e/integration.spec.js b/tests/e2e/integration.spec.js index 4a49500..1898b86 100644 --- a/tests/e2e/integration.spec.js +++ b/tests/e2e/integration.spec.js @@ -903,9 +903,9 @@ test.describe('Custom patches', () => { await expect(page.locator('#error-message')).toContainText('Build failed'); await expect(page.locator('#btn-error-back')).toBeVisible(); - // "Select different patches" should return to mode selection (auto mode) + // "Select different patches" should return to patches step await page.click('#btn-error-back'); - await expect(page.locator('#step-mode')).not.toBeHidden(); + await expect(page.locator('#step-patches')).not.toBeHidden(); }); test('with device — real patch failure with Go Back (Allow rotation)', async ({ page }) => { @@ -936,11 +936,9 @@ test.describe('Custom patches', () => { ]); if (doneOrError === 'error') { - // Build failed — "Select different patches" should return to mode selection - await expect(page.locator('#error-message')).toContainText('Build failed'); - await expect(page.locator('#btn-error-back')).toBeVisible(); + // Build failed — "Select different patches" should return to patches step await page.click('#btn-error-back'); - await expect(page.locator('#step-mode')).not.toBeHidden(); + await expect(page.locator('#step-patches')).not.toBeHidden(); } else { // Build succeeded — check if the patch was skipped const logText = await page.locator('#build-log').textContent(); diff --git a/web/src/js/app.js b/web/src/js/app.js index 71ab4ab..83e9b99 100644 --- a/web/src/js/app.js +++ b/web/src/js/app.js @@ -136,6 +136,17 @@ import JSZip from 'jszip'; let currentNavLabels = NAV_DEFAULT; + const stepHistory = [stepConnect]; + + function pushStep(step) { + stepHistory.push(step); + } + + function popStep() { + stepHistory.pop(); + return stepHistory[stepHistory.length - 1]; + } + function setNavLabels(labels) { currentNavLabels = labels; const ol = $q('ol', stepNav); @@ -147,10 +158,13 @@ import JSZip from 'jszip'; } } - function showStep(step) { + function showStep(step, updateHistory = true) { for (const s of allSteps) { s.hidden = (s !== step); } + if (updateHistory) { + stepHistory[stepHistory.length - 1] = step; + } } function setNavStep(num) { @@ -845,7 +859,7 @@ import JSZip from 'jszip'; showBuildResult(); await checkExistingTgz(); } catch (err) { - showError('Build failed: ' + err.message, buildLog.textContent, stepPatches); + showError('Build failed: ' + err.message, buildLog.textContent); } }); @@ -883,7 +897,7 @@ import JSZip from 'jszip'; }); // --- Error / Retry --- - function showError(message, log, backStep) { + function showError(message, log) { errorMessage.textContent = message; if (log) { errorLog.textContent = log; @@ -894,33 +908,30 @@ import JSZip from 'jszip'; } else { errorLog.hidden = true; } - if (backStep) { + + const hasBackStep = stepHistory[stepHistory.length - 1] === stepPatches; + if (hasBackStep) { errorTitle.textContent = 'The patch failed to apply'; errorHint.hidden = false; btnErrorBack.hidden = false; - btnErrorBack._backStep = backStep; btnRetry.classList.add('danger'); } else { errorTitle.textContent = 'Something went wrong'; errorHint.hidden = true; btnErrorBack.hidden = true; - btnErrorBack._backStep = null; btnRetry.classList.remove('danger'); } hideNav(); - showStep(stepError); + pushStep(stepError); + showStep(stepError, false); } btnErrorBack.addEventListener('click', () => { btnErrorBack.hidden = true; btnRetry.classList.remove('danger'); + const prev = popStep(); showNav(); - if (manualMode) { - setNavStep(2); - showStep(stepManualVersion); - } else { - goToModeSelection(); - } + showStep(prev); }); btnRetry.addEventListener('click', () => {