Repository navigation
refactor(ui): replace every native confirmation with the in-app dialog - #336
Merged
Merged
Conversation
The remaining 35 confirm() calls move to confirmAction() and confirmDeletion(), and prompts that were English in every locale are translated. The answer now arrives later, which changes three things: - A handler can no longer wait and then cancel a form submission, so confirmBeforeSubmit() cancels first and resubmits with the same button once confirmed. Clicks with data-confirm replay the same way. - data-confirm-submit asks in the capture phase, before the form's own handlers. The backup page set `restoring` before the question, so cancelling a restore left the page stuck. - `!confirmDelete()` on a promise is always false and tsc does not flag it, which would have deleted without asking. A test now rejects that shape and any new native confirm(). The tests answer the real dialog rather than a stub.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #335. Moves the remaining 35
confirm()calls to the in-app dialog, so a native confirmation now appears only as the fallback insideconfirm_dialog.ts. The browser's leave-page warning is unchanged.What changed
confirmAction()andconfirmDeletion()replaceconfirm()across texts, terms, feeds, tags, books, dictionaries, the admin pages and offline data.common.dialog.*keys across 11 locales. Bulk action prompts use the action's own label as the heading.The parts worth reviewing
The answer now arrives later, and that is where this could go wrong.
confirmBeforeSubmit()cancels first, then resubmits withrequestSubmit(submitter)once confirmed. The marker is cleared after the replay, so a submission refused by validation asks again.data-confirm. These cancel and replay the same way. My first version cleared the marker in the first listener, which looped forever when the handler was registered twice. A test run hung on it, and it is fixed.data-confirm-submitnow asks before the form's own handlers. The backup page's@submit="restoring = true"ran first, so cancelling a restore left the page stuck on "restoring". That bug existed before this change.!confirmDelete()is always false, andtsconly flagged one of the two cases, so bulk-deleting texts would have skipped the question. Both are fixed, and a test now rejects that shape.Tests
tests/frontend/helpers/confirm_answers.tslets tests click the real dialog rather than mock it.trackSubmissions()counts the submissions that go ahead.confirm_dialog.test.tscovers holding a submission until the answer, never submitting when declined, keeping the pressed button, and asking again. jsdom has nosubmitterand does not validate inrequestSubmit, so those two cases use a stubbedrequestSubmit.confirm()and on an unawaited confirmation in a condition.13-booksand14-dictionariesused to rely on Cypress auto-accepting. They now click the dialog, and the dictionary spec also checks that Cancel leaves the row.I also tried the Restore form on the backup page in Chrome: the dialog appeared, and Cancel left
restoringfalse. I did not confirm a restore or empty the database, and that path is covered only by the unit tests.Vitest, ESLint and TypeScript pass. Cypress passes except
24-anki-live.cy.ts, which needsnpm run anki:upand was not run. The new translations have not been reviewed by native speakers.prompt()andalert()are not part of this change.