diff --git a/web/src/components/layout/NowPlaying.tsx b/web/src/components/layout/NowPlaying.tsx index 35566c6..40b1cd1 100644 --- a/web/src/components/layout/NowPlaying.tsx +++ b/web/src/components/layout/NowPlaying.tsx @@ -1,7 +1,8 @@ -import { X } from 'lucide-react' -import { useEffect } from 'react' +import { ChevronDown, ListMusic, X } from 'lucide-react' +import { useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' +import { useFriends } from '@/api/friends' import { usePeaks } from '@/api/peaks' import Cover from '@/components/Cover' import FriendChip from '@/components/FriendChip' @@ -37,6 +38,14 @@ function NowPlayingSeek({ track }: { track: QueuedTrack }) { ) } +/** On a friend's track: the audio comes through this server, and the friend does not see who listens. */ +function FriendNote({ friend }: { friend: number }) { + const { t } = useTranslation() + const name = useFriends().data?.find((f) => f.id === friend)?.name + if (!name) return null + return

{t('player.friendNote', { name })}

+} + /** The full-screen player: a big cover, the controls and what comes next. */ export default function NowPlaying() { const { t } = useTranslation() @@ -45,6 +54,7 @@ export default function NowPlaying() { const queue = usePlayer((s) => s.queue) const index = usePlayer((s) => s.index) const jumpTo = usePlayer((s) => s.jumpTo) + const upNextRef = useRef(null) // Nothing left to show (the queue was emptied): close. useEffect(() => { @@ -57,26 +67,37 @@ export default function NowPlaying() { {track && ( <> -
- + {/* On a phone: close on the left, the friend in the middle, the queue on the right. Wide: the buttons at the corner. */} +
+ {track.friend !== undefined && } + +
{t('player.nowPlaying')} -
-
+
+
-
+
- + {track.title}

@@ -90,7 +111,7 @@ export default function NowPlaying() { ))} - {track.friend !== undefined && } + {track.friend !== undefined && }

{track.album && ( - + - - + + {upNext.length > 0 && ( -
+

{t('player.upNext')}

{upNext.map((next, k) => ( )} + + {track.friend !== undefined && }
diff --git a/web/src/components/layout/Player.test.tsx b/web/src/components/layout/Player.test.tsx index 0c27f2f..5801b28 100644 --- a/web/src/components/layout/Player.test.tsx +++ b/web/src/components/layout/Player.test.tsx @@ -356,6 +356,34 @@ test('the full-screen player links a friend’s track to the music of the friend expect(within(dialog).getByRole('link', { name: 'Their Band' })).toHaveAttribute('href', '/friends/3?tab=albums&artist=5&of=Their+Band') }) +test('on a phone the full-screen player has the friend on top, and says the audio passes through this server', async () => { + act(() => usePlayer.getState().playTracks([theirs(1)])) + renderBar() + await userEvent.click(screen.getByRole('button', { name: 'Open the full-screen player' })) + const dialog = screen.getByRole('dialog') + const top = dialog.querySelector('[data-phone-top]') as HTMLElement + expect(await within(top).findByLabelText('From Anna’s server')).toBeInTheDocument() + expect(within(dialog).getByText('The audio passes through your server. Anna does not see who listens.')).toBeInTheDocument() +}) + +test('a track of this server has no note about a friend in the full-screen player', async () => { + act(() => usePlayer.getState().playTracks([a])) + renderBar() + const { dialog } = await openNowPlaying() + expect(within(dialog).queryByText(/passes through your server/)).not.toBeInTheDocument() +}) + +test('on a phone the queue button takes me to what comes next', async () => { + const scroll = vi.fn() + Element.prototype.scrollIntoView = scroll + act(() => usePlayer.getState().playTracks([a, b, c])) + renderBar() + const { dialog } = await openNowPlaying() + await userEvent.click(within(dialog).getByRole('button', { name: 'Queue' })) + expect(scroll).toHaveBeenCalled() + expect(scroll.mock.contexts[0]).toBe(within(dialog).getByRole('region', { name: 'Up next' })) +}) + test('a local list does not mark a row because a friend’s track with the same id is playing', () => { act(() => usePlayer.getState().playTracks([theirs(1)])) render( diff --git a/web/src/components/layout/PlayerControls.tsx b/web/src/components/layout/PlayerControls.tsx index 876ae15..4e8c1a9 100644 --- a/web/src/components/layout/PlayerControls.tsx +++ b/web/src/components/layout/PlayerControls.tsx @@ -5,7 +5,7 @@ import { cn } from '@/lib/utils' import { currentTrack, usePlayer } from '@/player/store' /** Shuffle, previous, play/pause, next and repeat. Used by the player bar and the full-screen player. */ -export default function PlayerControls({ large = false }: { large?: boolean }) { +export default function PlayerControls({ large = false, className }: { large?: boolean; className?: string }) { const { t } = useTranslation() const none = usePlayer((s) => currentTrack(s) === null) // A friend's track has the play button of the friend colour, so that what comes from elsewhere is told apart. @@ -22,7 +22,7 @@ export default function PlayerControls({ large = false }: { large?: boolean }) { const repeatLabel = { off: 'player.repeatOff', all: 'player.repeatAll', one: 'player.repeatOne' }[repeat] return ( -
+