Android back button closes modals and leaves the News set browser

Adds useBackButton, a stack of back-button claimants (last claimed wins)
backed by Tauri's app-plugin back-button event. The listener is only
registered while something has claimed the button, so at the root back
keeps its native leave-the-app behavior.

Claimed by: the click-to-preview modal, DialogFrame (so Suggest cards,
Sample hand and every other dialog), and NewsView while a set's card
list is open. A preview opened from inside a dialog closes first.
This commit is contained in:
2026-10-14 21:12:30 -05:00
parent 5888e07586
commit b39b89be20
3 changed files with 77 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ import {
maskToLetters,
PreviewCard,
} from "./api";
import { useBackButton } from "./backButton";
// --- Icons ------------------------------------------------------------
@@ -148,9 +149,10 @@ export const Icons = {
/**
* A centered modal dialog (backdrop + card) shared by [`ConfirmDialog`],
* [`PromptDialog`], and other dialogs built outside this module (e.g. the
* command palette). Dismisses on Escape, backdrop click, or the title-bar
* close button — the explicit button matters most on mobile, where there's
* no Escape key and a `wide` dialog can leave little to no backdrop to tap.
* command palette). Dismisses on Escape, Android back, backdrop click, or the
* title-bar close button — the explicit button matters most on mobile, where
* there's no Escape key and a `wide` dialog can leave little to no backdrop
* to tap.
*/
export function DialogFrame({
title,
@@ -169,6 +171,7 @@ export function DialogFrame({
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [onCancel]);
useBackButton(onCancel);
return (
<div className="dialog-backdrop" onClick={onCancel}>
@@ -732,6 +735,7 @@ export function HoverPreviewProvider({ children }: { children: ReactNode }) {
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [clicked, close]);
useBackButton(close, !!clicked);
return (
<HoverCtx.Provider value={{ enter, move, leave }}>