diff --git a/web/src/App.tsx b/web/src/App.tsx index 94904de..2390a0b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -6,6 +6,7 @@ * the mouse, a figure on the reader, Home Assistant - and this UI has to follow them. */ +import type { ReactNode } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { api } from "./api/client"; @@ -27,7 +28,7 @@ import { usePlayerState } from "./hooks/usePlayerState"; import { DEFAULT_MANUAL_CONTROL, DEFAULT_TUNABLES } from "./lib/ambienceTunables"; import type { AmbienceTunables, ManualControl } from "./lib/ambienceTunables"; import type { Action, UiState } from "./lib/keyboard"; -import { handleKey, initialUiState } from "./lib/keyboard"; +import { browseBackActions, handleKey, initialUiState, isRootShelf } from "./lib/keyboard"; import { playPop } from "./lib/pop"; import { targetForAlbum } from "./lib/remote"; import type { Group, Results, SongHit } from "./lib/search"; @@ -285,11 +286,6 @@ export function App() { setUi((previous) => ({ ...previous, group, category, search: "", selIndex: 0 })); }; - const onBackToRoot = () => { - playPop(380); - setUi((previous) => ({ ...previous, group: null, category: null, selIndex: 0 })); - }; - const onCategory = (key: string | null) => { if (key) playPop(440); setUi((previous) => ({ ...previous, category: key, selIndex: 0 })); @@ -307,6 +303,13 @@ export function App() { setUi((previous) => ({ ...previous, openAlbumId: album.id, selIndex: navIndex })); }; + /** Clicking the title text (as opposed to the cover) starts the album right away - + * the same thing ENTER does from the keyboard - instead of opening the track list. */ + const onPlayAlbum = (album: Album, navIndex: number) => { + setUi((previous) => ({ ...previous, selIndex: navIndex })); + play(album.id, 0); + }; + const onOpenCurrentAlbum = () => { if (!currentAlbum) return; playPop(420); @@ -320,6 +323,21 @@ export function App() { }; const onMute = () => setVolume(state && state.volume > 0 ? 0 : UNMUTE_PERCENT); + // The single top-left "back" button, shared by every level of the music page - + // search, categories, play view - so it always means "one step out" no matter what + // is on screen. Nothing to back out of on the room page (it has no sub-levels), and + // the toggle button is what moves between the two pages. + const canGoBack = ui.page === "music" && (ui.view === "play" || !isRootShelf(ui)); + const onBack = () => { + if (ui.view === "play") { + setUi((previous) => ({ ...previous, view: "browse" })); + return; + } + run(browseBackActions(ui)); + }; + const onToggleRoom = () => + setUi((previous) => ({ ...previous, page: previous.page === "room" ? "music" : "room" })); + return (