From 075e000fd85f8cefd449924992d1d44e01de361c Mon Sep 17 00:00:00 2001 From: tgiachi Date: Thu, 12 Nov 2026 12:28:15 +0100 Subject: [PATCH] feat(web): a button for browser full screen - one button in the player bar and one in the full-screen player puts the whole page in full screen and takes it out - it follows the browser: Esc and F11 flip it back, a refused request leaves the page as it was - left out where the browser has no Fullscreen API (for example iPhone Safari) - English and Italian labels --- web/src/components/FullscreenButton.tsx | 22 +++++ web/src/components/layout/NowPlaying.tsx | 15 ++-- web/src/components/layout/Player.test.tsx | 22 +++++ web/src/components/layout/PlayerBar.tsx | 2 + web/src/i18n/locales/en.json | 4 + web/src/i18n/locales/it.json | 4 + web/src/lib/fullscreen.test.tsx | 97 +++++++++++++++++++++++ web/src/lib/fullscreen.ts | 27 +++++++ web/src/test/fullscreen.ts | 43 ++++++++++ 9 files changed, 228 insertions(+), 8 deletions(-) create mode 100644 web/src/components/FullscreenButton.tsx create mode 100644 web/src/lib/fullscreen.test.tsx create mode 100644 web/src/lib/fullscreen.ts create mode 100644 web/src/test/fullscreen.ts diff --git a/web/src/components/FullscreenButton.tsx b/web/src/components/FullscreenButton.tsx new file mode 100644 index 0000000..d76b1c2 --- /dev/null +++ b/web/src/components/FullscreenButton.tsx @@ -0,0 +1,22 @@ +import { Maximize, Minimize } from 'lucide-react' +import { useTranslation } from 'react-i18next' +import { Button } from '@/components/ui/button' +import { useFullscreen } from '@/lib/fullscreen' +import { cn } from '@/lib/utils' + +/** Puts the browser in full screen, or takes it out. Not shown where the browser has no full screen. */ +export default function FullscreenButton({ className }: { className?: string }) { + const { t } = useTranslation() + const { supported, active, toggle } = useFullscreen() + if (!supported) return null + return ( + + ) +} diff --git a/web/src/components/layout/NowPlaying.tsx b/web/src/components/layout/NowPlaying.tsx index f925765..8376960 100644 --- a/web/src/components/layout/NowPlaying.tsx +++ b/web/src/components/layout/NowPlaying.tsx @@ -3,6 +3,7 @@ import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import Cover from '@/components/Cover' +import FullscreenButton from '@/components/FullscreenButton' import Scrubber from '@/components/Scrubber' import TrackRow from '@/components/TrackRow' import { Button } from '@/components/ui/button' @@ -36,14 +37,12 @@ export default function NowPlaying() { > {track && ( <> - +
+ + +
{t('player.nowPlaying')}
diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx index ff4fb48..16c2fc2 100644 --- a/web/src/components/layout/Player.test.tsx +++ b/web/src/components/layout/Player.test.tsx @@ -9,6 +9,7 @@ import TrackRow from '@/components/TrackRow' import { initI18n } from '@/i18n' import { usePlayer } from '@/player/store' import { useNowPlayingUi } from '@/player/ui' +import { fakeFullscreen } from '@/test/fullscreen' import PlayerBar from './PlayerBar' function track(n: number, over: Partial = {}): Track { @@ -249,6 +250,27 @@ test('Up next shows the next three tracks and a click plays one of them', async expect(usePlayer.getState().index).toBe(2) }) +test('the bar and the full-screen player both have a button for browser full screen, where the browser has one', async () => { + const env = fakeFullscreen() + try { + act(() => usePlayer.getState().playTracks([a])) + renderBar() + expect(screen.getByRole('button', { name: 'Enter full screen' })).toBeInTheDocument() + const { dialog } = await openNowPlaying() + expect(within(dialog).getByRole('button', { name: 'Enter full screen' })).toBeInTheDocument() + } finally { + env.restore() + } +}) + +test('without the Fullscreen API neither the bar nor the full-screen player shows the button', async () => { + act(() => usePlayer.getState().playTracks([a])) + renderBar() + const { dialog } = await openNowPlaying() + expect(screen.queryByRole('button', { name: 'Enter full screen' })).not.toBeInTheDocument() + expect(within(dialog).queryByRole('button', { name: 'Enter full screen' })).not.toBeInTheDocument() +}) + test('a track with no album and no artists opens in the full-screen player', async () => { act(() => usePlayer.getState().playTracks([track(9, { album: null, artists: [] })])) renderBar() diff --git a/web/src/components/layout/PlayerBar.tsx b/web/src/components/layout/PlayerBar.tsx index e28c493..7e30540 100644 --- a/web/src/components/layout/PlayerBar.tsx +++ b/web/src/components/layout/PlayerBar.tsx @@ -3,6 +3,7 @@ import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import Cover from '@/components/Cover' +import FullscreenButton from '@/components/FullscreenButton' import Scrubber from '@/components/Scrubber' import { Button } from '@/components/ui/button' import { formatTime } from '@/lib/time' @@ -85,6 +86,7 @@ export default function PlayerBar() {
+