Repository navigation
refactor(ui): replace native alert and prompt with in-app dialogs - #337
Merged
Merged
Conversation
The 47 remaining alert() and prompt() calls move to showAlert(), showError() and promptDialog(), and messages that were English in every locale are translated. - One dialog shows at a time. Validation can raise several errors in a pass, and they now queue, so none is lost and an alert cannot answer a confirmation. - promptDialog() validates in place. Tag entry used to loop between prompt() and alert(); the error now appears under the field and the dialog stays open. - A dialog swallows the keypress that follows the keydown that opened it, so an Enter press cannot dismiss what it just caused. - showAlert() resolves on dismissal, so the language form can return the focus to the name afterwards.
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 #336. Moves the remaining 43
alert()and 4prompt()calls to in-app dialogs, so native dialogs now appear only as the fallback insideconfirm_dialog.ts. The browser's leave-page warning is unchanged.What changed
showAlert(),showError()andpromptDialog()joinconfirmDialog(), sharing one implementation inconfirm_dialog.ts.common.dialog.*keys across 11 locales. They replace strings likeERROR\n\n..., and the error message for an unsupported character no longer includes a Wikipedia link.Behaviour worth reviewing
check()can raise several errors in a pass. They now queue in order, so none is lost, and an alert can never answer a waiting confirmation.showAlert()runs straight away. That suits every call here, because each one only reports something. The language form waits for the promise, so it can return the focus to the name once the alert is dismissed.multiActionGo()andallActionGo()used to loop betweenprompt()andalert(). The error now appears under the field and the dialog stays open. A leading space or comma is now refused too: the oldindexOf(...) > 0check missed position 0.Tests
answerPrompts()anddismissAlerts()join the test helper and drive the real dialog.confirm_dialog.test.tscovers alerts, the queue, prompts, inline validation, Tab, the Enter keypress and the native fallback.alert()andprompt().I also tried tag entry in the real term list in the dark theme. An invalid tag kept the dialog open with the error shown and the text intact, and Escape cancelled and reset the menu. The Enter keypress is only tested with a simulated event, not a real key press from a textarea. The translations have not been reviewed by native speakers.
PHPUnit, Vitest, ESLint and TypeScript pass. Cypress passes except
24-anki-live.cy.ts, which needsnpm run anki:upand was not run.