Android back returns from a deck to the deck list on narrow screens
Same as the deck screen's own back button. Only claimed below the 720px .deck-layout breakpoint, where the list and the builder are separate screens; side by side, flipping mobileShowList changes nothing visible.
This commit is contained in:
@@ -26,6 +26,20 @@ import {
|
|||||||
useViewMode,
|
useViewMode,
|
||||||
} from "../components";
|
} from "../components";
|
||||||
import { SuggestionsModal } from "../SuggestionsModal";
|
import { SuggestionsModal } from "../SuggestionsModal";
|
||||||
|
import { useBackButton } from "../backButton";
|
||||||
|
|
||||||
|
/** Whether a CSS media query currently matches, kept live across resizes. */
|
||||||
|
function useMediaQuery(query: string) {
|
||||||
|
const [matches, setMatches] = useState(() => window.matchMedia(query).matches);
|
||||||
|
useEffect(() => {
|
||||||
|
const mql = window.matchMedia(query);
|
||||||
|
const onChange = () => setMatches(mql.matches);
|
||||||
|
onChange();
|
||||||
|
mql.addEventListener("change", onChange);
|
||||||
|
return () => mql.removeEventListener("change", onChange);
|
||||||
|
}, [query]);
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
/** Tooltip/label + icon for the per-card mainboard/maybeboard toggle. */
|
/** Tooltip/label + icon for the per-card mainboard/maybeboard toggle. */
|
||||||
function boardToggleProps(e: DeckEntry) {
|
function boardToggleProps(e: DeckEntry) {
|
||||||
@@ -351,6 +365,12 @@ export function DeckView({ refreshSignal }: { refreshSignal?: number }) {
|
|||||||
// this only matters below the .deck-layout stacking breakpoint; CSS keeps
|
// this only matters below the .deck-layout stacking breakpoint; CSS keeps
|
||||||
// both panes visible side by side above it regardless of this flag.
|
// both panes visible side by side above it regardless of this flag.
|
||||||
const [mobileShowList, setMobileShowList] = useState(true);
|
const [mobileShowList, setMobileShowList] = useState(true);
|
||||||
|
// Android back from the deck-building screen returns to the deck list, like
|
||||||
|
// its ← button. Only while they're separate screens (the ≤720px
|
||||||
|
// `.deck-layout` breakpoint): side by side, flipping the flag changes
|
||||||
|
// nothing visible, so back would seem to do nothing.
|
||||||
|
const listIsSeparateScreen = useMediaQuery("(max-width: 720px)");
|
||||||
|
useBackButton(() => setMobileShowList(true), listIsSeparateScreen && !mobileShowList);
|
||||||
|
|
||||||
const [libQuery, setLibQuery] = useState("");
|
const [libQuery, setLibQuery] = useState("");
|
||||||
const [libResults, setLibResults] = useState<CardRef[]>([]);
|
const [libResults, setLibResults] = useState<CardRef[]>([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user