Merge pull request 'The full-screen player fits the phone' (#157) from feat/ui-phone-player into main
This commit is contained in:
commit
1736fc5a29
5 changed files with 72 additions and 19 deletions
|
|
@ -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 <p className="text-[13px] leading-snug text-muted-foreground text-pretty">{t('player.friendNote', { name })}</p>
|
||||
}
|
||||
|
||||
/** 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<HTMLElement>(null)
|
||||
|
||||
// Nothing left to show (the queue was emptied): close.
|
||||
useEffect(() => {
|
||||
|
|
@ -57,26 +67,37 @@ export default function NowPlaying() {
|
|||
<Dialog open={open && track !== null} onOpenChange={setOpen}>
|
||||
<DialogContent
|
||||
showCloseButton={false}
|
||||
className="inset-0 h-dvh w-screen max-w-none translate-x-0 translate-y-0 content-center overflow-y-auto rounded-none bg-background p-6 sm:max-w-none md:p-12 motion-reduce:data-closed:animate-none motion-reduce:data-open:animate-none"
|
||||
className="inset-0 h-dvh w-screen max-w-none translate-x-0 translate-y-0 grid-cols-[minmax(0,1fr)] content-start overflow-y-auto sm:content-center rounded-none bg-background p-6 sm:max-w-none md:p-12 motion-reduce:data-closed:animate-none motion-reduce:data-open:animate-none"
|
||||
>
|
||||
{track && (
|
||||
<>
|
||||
<div className="absolute top-4 right-4 flex gap-1">
|
||||
<FullscreenButton />
|
||||
{/* On a phone: close on the left, the friend in the middle, the queue on the right. Wide: the buttons at the corner. */}
|
||||
<div data-phone-top className="-mx-3 -mt-3 flex items-center justify-between gap-2 sm:absolute sm:top-4 sm:right-4 sm:m-0 sm:flex-row-reverse sm:justify-start sm:gap-1">
|
||||
<Button variant="ghost" className="size-11" aria-label={t('player.close')} onClick={() => setOpen(false)}>
|
||||
<X />
|
||||
<ChevronDown className="sm:hidden" />
|
||||
<X className="max-sm:hidden" />
|
||||
</Button>
|
||||
{track.friend !== undefined && <FriendChip friend={track.friend} className="px-3.5 text-sm sm:hidden" />}
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="size-11 sm:hidden"
|
||||
aria-label={t('player.queue')}
|
||||
onClick={() => upNextRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })}
|
||||
>
|
||||
<ListMusic />
|
||||
</Button>
|
||||
<FullscreenButton className="max-sm:hidden" />
|
||||
</div>
|
||||
<DialogDescription className="sr-only">{t('player.nowPlaying')}</DialogDescription>
|
||||
|
||||
<div className="mx-auto flex w-full max-w-5xl flex-wrap items-center justify-center gap-x-16 gap-y-8 pt-10">
|
||||
<div className="flex min-w-0 flex-[1_1_320px] justify-center">
|
||||
<div className="mx-auto flex w-full max-w-5xl flex-wrap items-center justify-center gap-x-16 gap-y-6 sm:gap-y-8 sm:pt-10">
|
||||
<div className="flex min-w-0 flex-[1_1_320px] justify-center max-sm:max-w-72">
|
||||
<Cover albumId={track.album?.id ?? null} friend={track.friend} size={520} fluid />
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-[1_1_380px] flex-col gap-7">
|
||||
<div className="flex min-w-0 flex-[1_1_380px] flex-col gap-5 sm:gap-7">
|
||||
<div className="flex flex-col gap-2">
|
||||
<DialogTitle className="text-4xl leading-tight font-extrabold tracking-tight md:text-6xl">
|
||||
<DialogTitle className="text-3xl leading-tight font-extrabold tracking-tight sm:text-4xl md:text-6xl">
|
||||
{track.title}
|
||||
</DialogTitle>
|
||||
<p className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xl font-semibold">
|
||||
|
|
@ -90,7 +111,7 @@ export default function NowPlaying() {
|
|||
</Link>
|
||||
</span>
|
||||
))}
|
||||
{track.friend !== undefined && <FriendChip friend={track.friend} className="text-sm font-semibold" />}
|
||||
{track.friend !== undefined && <FriendChip friend={track.friend} className="text-sm font-semibold max-sm:hidden" />}
|
||||
</p>
|
||||
{track.album && (
|
||||
<Link
|
||||
|
|
@ -103,15 +124,15 @@ export default function NowPlaying() {
|
|||
)}
|
||||
</div>
|
||||
|
||||
<Spectrogram columns={72} rows={16} friend={track.friend !== undefined} className="h-36 w-full" />
|
||||
<Spectrogram columns={72} rows={16} friend={track.friend !== undefined} className="h-20 w-full sm:h-36" />
|
||||
|
||||
<NowPlayingSeek track={track} />
|
||||
|
||||
<PlayerControls large />
|
||||
<VolumeControl className="-mt-3" />
|
||||
<PlayerControls large className="w-full justify-between sm:w-auto sm:justify-start" />
|
||||
<VolumeControl className="-mt-3 max-sm:hidden" />
|
||||
|
||||
{upNext.length > 0 && (
|
||||
<section aria-label={t('player.upNext')} className="flex flex-col gap-1 border-t pt-4">
|
||||
<section ref={upNextRef} aria-label={t('player.upNext')} className="flex scroll-mt-4 flex-col gap-1 border-t pt-4">
|
||||
<h2 className="pb-2 font-bold">{t('player.upNext')}</h2>
|
||||
{upNext.map((next, k) => (
|
||||
<TrackRow
|
||||
|
|
@ -123,6 +144,8 @@ export default function NowPlaying() {
|
|||
))}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{track.friend !== undefined && <FriendNote friend={track.friend} />}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="flex items-center gap-1 sm:gap-3">
|
||||
<div className={cn('flex items-center gap-1 sm:gap-3', className)}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className={cn(small, shuffle ? 'text-primary' : 'text-muted-foreground')}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@
|
|||
"mute": "Mute",
|
||||
"unmute": "Unmute",
|
||||
"spectrogram": "Spectrogram of what is playing",
|
||||
"fromFriend": "From {{name}}’s server"
|
||||
"fromFriend": "From {{name}}’s server",
|
||||
"friendNote": "The audio passes through your server. {{name}} does not see who listens."
|
||||
},
|
||||
"settings": {
|
||||
"account": "Account",
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@
|
|||
"mute": "Silenzia",
|
||||
"unmute": "Riattiva l'audio",
|
||||
"spectrogram": "Spettrogramma di ciò che sta suonando",
|
||||
"fromFriend": "Dal server di {{name}}"
|
||||
"fromFriend": "Dal server di {{name}}",
|
||||
"friendNote": "L’audio passa dal tuo server. {{name}} non vede chi ascolta."
|
||||
},
|
||||
"settings": {
|
||||
"account": "Account",
|
||||
|
|
|
|||
Loading…
Reference in a new issue