Commit 2d4c014a authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add enter/exit motion to the flat modal and page transitions

The three shared bottom-sheet modals (AddToPlaylistModal, SongPicker,
RemixSongPicker) and Layout's mobile More sheet popped in/out
instantly with zero transition. Wired into useMountTransition (same
300ms fade+rise idiom already used by FullPlayer/NowPlayingBar) so
the backdrop fades and the panel slides/rises both ways. The three
modals defer calling their real onClose prop until the exit animation
actually finishes, since the caller still owns whether they exist in
the tree at all and would otherwise unmount them mid-animation.

Also gives every page navigation a subtle fade+rise on mount (Layout
re-mounts per page already, so a plain CSS animation is enough - no
router-level transition machinery needed), and fades EmptyState in
instead of appearing flat.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent bf57f549
Pipeline #1150 failed with stage
in 26 minutes and 59 seconds
import { render, screen } from '@testing-library/react'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { AddToPlaylistModal } from './AddToPlaylistModal'
......@@ -90,7 +90,9 @@ describe('AddToPlaylistModal', () => {
render(<AddToPlaylistModal song={SONG} onClose={onClose} />)
await userEvent.click(screen.getByRole('dialog'))
expect(onClose).toHaveBeenCalled()
// onClose fires once the exit transition finishes (see useMountTransition), not
// synchronously on click - the dialog itself un-mounts a beat later.
await waitFor(() => expect(onClose).toHaveBeenCalled())
})
it('closes on Escape', async () => {
......@@ -100,6 +102,6 @@ describe('AddToPlaylistModal', () => {
render(<AddToPlaylistModal song={SONG} onClose={onClose} />)
await userEvent.keyboard('{Escape}')
expect(onClose).toHaveBeenCalled()
await waitFor(() => expect(onClose).toHaveBeenCalled())
})
})
import { useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Check, ListMusic, Plus, X } from 'lucide-react'
import { addToPlaylist, createPlaylist, getPlaylists, type LibrarySong, type Playlist } from '../api/library'
import { ApiError } from '../api/client'
import { Button } from './ui/Button'
import { Input } from './ui/Input'
import { useBackButtonClose } from '../hooks/useBackButtonClose'
import { useMountTransition } from '../hooks/useMountTransition'
const ANIMATION_MS = 300
interface AddToPlaylistModalProps {
song: LibrarySong
......@@ -24,6 +27,24 @@ export function AddToPlaylistModal({ song, onClose }: AddToPlaylistModalProps) {
const [newName, setNewName] = useState('')
const [creating, setCreating] = useState(false)
// The caller owns whether this component exists in the tree at all (conditionally rendering
// it), so calling the real onClose prop immediately would unmount it before its own exit
// transition could ever play. requestClose instead flips local `closing` state, which drives
// the exit animation via useMountTransition; the real onClose only fires once that's done
// (see the effect below) - the caller's simple ownership model never has to change.
const [closing, setClosing] = useState(false)
const { mounted, visible } = useMountTransition(!closing, ANIMATION_MS)
const closedRef = useRef(false)
const requestClose = useCallback(() => setClosing(true), [])
useEffect(() => {
if (!mounted && !closedRef.current) {
closedRef.current = true
onClose()
}
}, [mounted, onClose])
useEffect(() => {
getPlaylists()
.then((res) => setPlaylists(res.playlists))
......@@ -35,16 +56,16 @@ export function AddToPlaylistModal({ song, onClose }: AddToPlaylistModalProps) {
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Escape') onClose()
if (e.key === 'Escape') requestClose()
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [onClose])
}, [requestClose])
// Always true, not conditional on some local open state - this component only exists in the
// tree while the modal should be showing (the caller mounts/unmounts it), so "open" for the
// back button's purposes is simply "mounted".
useBackButtonClose(true, onClose)
useBackButtonClose(true, requestClose)
async function handleAdd(playlist: Playlist) {
setBusyId(playlist.id)
......@@ -76,22 +97,31 @@ export function AddToPlaylistModal({ song, onClose }: AddToPlaylistModalProps) {
}
}
if (!mounted) return null
return (
<div
role="dialog"
aria-modal="true"
aria-label={`Add "${song.title}" to a playlist`}
className="fixed inset-0 z-40 flex items-end justify-center bg-black/60 sm:items-center"
onClick={onClose}
className={`fixed inset-0 z-40 flex items-end justify-center bg-black/60 transition-opacity duration-300 ease-out motion-reduce:transition-none sm:items-center ${
visible ? 'opacity-100' : 'opacity-0'
}`}
onClick={requestClose}
>
<div
className="flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container sm:rounded-2xl"
className={`flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container transition-all duration-300 ease-out motion-reduce:transition-none sm:rounded-2xl ${
// Mobile slides up as a true bottom sheet; desktop's centered card instead does a
// gentle fade+rise (matching FullPlayer's own idiom) since a full-height slide would
// travel an oddly large distance for a card that isn't anchored to an edge there.
visible ? 'translate-y-0 opacity-100' : 'translate-y-full opacity-0 sm:translate-y-4'
}`}
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-center justify-between border-b border-outline-variant px-4 py-3">
<p className="min-w-0 truncate text-sm font-semibold text-white">Add "{song.title}" to playlist</p>
<button
onClick={onClose}
onClick={requestClose}
aria-label="Close"
className="shrink-0 rounded-full p-1.5 text-on-surface-variant transition-colors hover:bg-surface-container-high hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
......
import { render, screen } from '@testing-library/react'
import { render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Layout } from './Layout'
......@@ -60,4 +61,44 @@ describe('Layout', () => {
expect(link).not.toHaveAttribute('aria-current')
}
})
describe('mobile More sheet', () => {
it('opens to reveal overflow nav items, and closes via the backdrop', async () => {
renderLayout('/library')
expect(screen.queryByRole('dialog', { name: 'More' })).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'More' }))
const sheet = await screen.findByRole('dialog', { name: 'More' })
expect(within(sheet).getByRole('link', { name: 'Upload' })).toBeInTheDocument()
// Two "Close" buttons exist (the full-bleed backdrop and the small X) - the backdrop is
// the first in DOM order.
await userEvent.click(screen.getAllByRole('button', { name: 'Close' })[0])
// The sheet keeps rendering for its exit transition (see useMountTransition) before
// actually unmounting - a plain queryByRole right after the click would still find it.
await waitFor(() => expect(sheet).not.toBeInTheDocument())
})
it('closes via the X button', async () => {
renderLayout('/library')
await userEvent.click(screen.getByRole('button', { name: 'More' }))
await screen.findByRole('dialog', { name: 'More' })
const closeButtons = screen.getAllByRole('button', { name: 'Close' })
await userEvent.click(closeButtons[closeButtons.length - 1])
await waitFor(() => expect(screen.queryByRole('dialog', { name: 'More' })).not.toBeInTheDocument())
})
it('closes when an overflow item is clicked', async () => {
renderLayout('/library')
await userEvent.click(screen.getByRole('button', { name: 'More' }))
const sheet = await screen.findByRole('dialog', { name: 'More' })
await userEvent.click(within(sheet).getByRole('link', { name: 'Upload' }))
await waitFor(() => expect(screen.queryByRole('dialog', { name: 'More' })).not.toBeInTheDocument())
})
})
})
......@@ -26,6 +26,9 @@ import { FullPlayer } from './FullPlayer'
import { PlaybackErrorToast } from './PlaybackErrorToast'
import { InstallBanner } from './InstallBanner'
import { useBackButtonClose } from '../hooks/useBackButtonClose'
import { useMountTransition } from '../hooks/useMountTransition'
const MORE_SHEET_ANIMATION_MS = 300
// Rooms/Channels/Posts share one "Social" destination and Nearby/Drops share one
// "Soundmarks" destination (both merged 2026-08-23) - each hub page owns its own in-page
......@@ -53,6 +56,10 @@ export function Layout({ title, children }: { title: string; children: ReactNode
const { currentSong } = usePlayer()
const location = useLocation()
const [moreOpen, setMoreOpen] = useState(false)
// moreOpen itself is the "active" flag here, unlike the shared modals - there's no external
// onClose prop whose timing needs protecting, so the exit animation can hang directly off
// this same state instead of a separate closing/requestClose indirection.
const { mounted: moreSheetMounted, visible: moreSheetVisible } = useMountTransition(moreOpen, MORE_SHEET_ANIMATION_MS)
useBackButtonClose(moreOpen, () => setMoreOpen(false))
async function handleLogout() {
......@@ -145,7 +152,7 @@ export function Layout({ title, children }: { title: string; children: ReactNode
<main
className={`px-4 py-6 transition-[padding] duration-300 ease-out motion-reduce:transition-none sm:ml-64 sm:px-8 sm:py-8 ${currentSong ? 'pb-40 sm:pb-24' : 'pb-24 sm:pb-8'}`}
>
<div className="mx-auto max-w-2xl sm:max-w-3xl">
<div className="mx-auto max-w-2xl sm:max-w-3xl animate-page-enter">
<h1 className="mb-6 text-xl font-semibold tracking-tight sm:text-2xl">{title}</h1>
<InstallBanner />
{children}
......@@ -189,15 +196,19 @@ export function Layout({ title, children }: { title: string; children: ReactNode
</button>
</nav>
{moreOpen && (
{moreSheetMounted && (
<div className="fixed inset-0 z-30 sm:hidden" role="dialog" aria-label="More">
<button
aria-label="Close"
onClick={() => setMoreOpen(false)}
className="absolute inset-0 bg-black/60 backdrop-blur-sm"
className={`absolute inset-0 bg-black/60 backdrop-blur-sm transition-opacity duration-300 ease-out motion-reduce:transition-none ${
moreSheetVisible ? 'opacity-100' : 'opacity-0'
}`}
/>
<div
className="absolute inset-x-0 bottom-0 rounded-t-2xl border-t border-outline-variant bg-surface-container-low p-4"
className={`absolute inset-x-0 bottom-0 rounded-t-2xl border-t border-outline-variant bg-surface-container-low p-4 transition-transform duration-300 ease-out motion-reduce:transition-none ${
moreSheetVisible ? 'translate-y-0' : 'translate-y-full'
}`}
style={{ paddingBottom: 'calc(env(safe-area-inset-bottom) + 16px)' }}
>
<div className="mb-3 flex items-center justify-between">
......
import { useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Check, Music2, X } from 'lucide-react'
import { getLibrary, type LibrarySong } from '../api/library'
import { Button } from './ui/Button'
import { Input } from './ui/Input'
import { useBackButtonClose } from '../hooks/useBackButtonClose'
import { useMountTransition } from '../hooks/useMountTransition'
const ANIMATION_MS = 300
export const MAX_REMIX_SONGS = 5
......@@ -23,6 +26,21 @@ export function RemixSongPicker({ selected, onChange, onClose }: RemixSongPicker
const [library, setLibrary] = useState<LibrarySong[]>([])
const [query, setQuery] = useState('')
// See AddToPlaylistModal for why: the caller owns whether this exists in the tree at all, so
// requestClose defers the real onClose prop until the exit transition actually finishes.
const [closing, setClosing] = useState(false)
const { mounted, visible } = useMountTransition(!closing, ANIMATION_MS)
const closedRef = useRef(false)
const requestClose = useCallback(() => setClosing(true), [])
useEffect(() => {
if (!mounted && !closedRef.current) {
closedRef.current = true
onClose()
}
}, [mounted, onClose])
useEffect(() => {
getLibrary()
.then((res) => setLibrary(res.library))
......@@ -33,13 +51,13 @@ export function RemixSongPicker({ selected, onChange, onClose }: RemixSongPicker
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Escape') onClose()
if (e.key === 'Escape') requestClose()
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [onClose])
}, [requestClose])
useBackButtonClose(true, onClose)
useBackButtonClose(true, requestClose)
const q = query.trim().toLowerCase()
const filtered = q ? library.filter((s) => s.title.toLowerCase().includes(q) || s.artist.toLowerCase().includes(q)) : library
......@@ -53,22 +71,28 @@ export function RemixSongPicker({ selected, onChange, onClose }: RemixSongPicker
}
}
if (!mounted) return null
return (
<div
role="dialog"
aria-modal="true"
aria-label="Choose songs to remix"
className="fixed inset-0 z-40 flex items-end justify-center bg-black/60 sm:items-center"
onClick={onClose}
className={`fixed inset-0 z-40 flex items-end justify-center bg-black/60 transition-opacity duration-300 ease-out motion-reduce:transition-none sm:items-center ${
visible ? 'opacity-100' : 'opacity-0'
}`}
onClick={requestClose}
>
<div
className="flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container sm:rounded-2xl"
className={`flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container transition-all duration-300 ease-out motion-reduce:transition-none sm:rounded-2xl ${
visible ? 'translate-y-0 opacity-100' : 'translate-y-full opacity-0 sm:translate-y-4'
}`}
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-center justify-between border-b border-outline-variant px-4 py-3">
<p className="text-sm font-semibold text-white">Choose up to {MAX_REMIX_SONGS} songs</p>
<button
onClick={onClose}
onClick={requestClose}
aria-label="Close"
className="rounded-full p-1.5 text-on-surface-variant transition-colors hover:bg-surface-container-high hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
......@@ -117,7 +141,7 @@ export function RemixSongPicker({ selected, onChange, onClose }: RemixSongPicker
</ul>
<div className="border-t border-outline-variant p-3">
<Button onClick={onClose} className="w-full">
<Button onClick={requestClose} className="w-full">
Done ({selected.length}/{MAX_REMIX_SONGS})
</Button>
</div>
......
import { useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Music2, X } from 'lucide-react'
import { getLibrary, type LibrarySong } from '../api/library'
import { searchSongLibrary, type PublicLibrarySong } from '../api/soundmarks'
import { Input } from './ui/Input'
import { useBackButtonClose } from '../hooks/useBackButtonClose'
import { useMountTransition } from '../hooks/useMountTransition'
const ANIMATION_MS = 300
type Tab = 'mine' | 'public'
type PickableSong = LibrarySong | PublicLibrarySong
......@@ -25,6 +28,21 @@ export function SongPicker({ onSelect, onClose }: SongPickerProps) {
const [publicResults, setPublicResults] = useState<PublicLibrarySong[]>([])
const [loading, setLoading] = useState(false)
// See AddToPlaylistModal for why: the caller owns whether this exists in the tree at all, so
// requestClose defers the real onClose prop until the exit transition actually finishes.
const [closing, setClosing] = useState(false)
const { mounted, visible } = useMountTransition(!closing, ANIMATION_MS)
const closedRef = useRef(false)
const requestClose = useCallback(() => setClosing(true), [])
useEffect(() => {
if (!mounted && !closedRef.current) {
closedRef.current = true
onClose()
}
}, [mounted, onClose])
useEffect(() => {
getLibrary()
.then((res) => setMyLibrary(res.library))
......@@ -47,32 +65,38 @@ export function SongPicker({ onSelect, onClose }: SongPickerProps) {
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Escape') onClose()
if (e.key === 'Escape') requestClose()
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [onClose])
}, [requestClose])
useBackButtonClose(true, onClose)
useBackButtonClose(true, requestClose)
const list = tab === 'mine' ? myLibrary : publicResults
if (!mounted) return null
return (
<div
role="dialog"
aria-modal="true"
aria-label="Choose an anthem"
className="fixed inset-0 z-40 flex items-end justify-center bg-black/60 sm:items-center"
onClick={onClose}
className={`fixed inset-0 z-40 flex items-end justify-center bg-black/60 transition-opacity duration-300 ease-out motion-reduce:transition-none sm:items-center ${
visible ? 'opacity-100' : 'opacity-0'
}`}
onClick={requestClose}
>
<div
className="flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container sm:rounded-2xl"
className={`flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-t-2xl bg-surface-container transition-all duration-300 ease-out motion-reduce:transition-none sm:rounded-2xl ${
visible ? 'translate-y-0 opacity-100' : 'translate-y-full opacity-0 sm:translate-y-4'
}`}
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-center justify-between border-b border-outline-variant px-4 py-3">
<p className="text-sm font-semibold text-on-surface">Choose an anthem</p>
<button
onClick={onClose}
onClick={requestClose}
aria-label="Close"
className="rounded-full p-1.5 text-on-surface-variant transition-colors hover:bg-surface-container-high hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
......
......@@ -2,7 +2,7 @@ import type { LucideIcon } from 'lucide-react'
export function EmptyState({ icon: Icon, message }: { icon: LucideIcon; message: string }) {
return (
<div className="flex flex-col items-center gap-3 py-16 text-center text-outline">
<div className="flex flex-col items-center gap-3 py-16 text-center text-outline animate-message-enter">
<Icon size={28} strokeWidth={1.5} />
<p className="max-w-xs text-sm">{message}</p>
</div>
......
......@@ -81,6 +81,30 @@
}
}
/* Every page re-mounts Layout on navigation (each page wraps its own <Layout> rather than
sharing one via an <Outlet>), so a plain CSS animation applied on mount is enough to give
every route change a subtle entrance - no router-level transition machinery needed. */
@keyframes page-enter {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-page-enter {
animation: page-enter 300ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
.animate-page-enter {
animation: none;
}
}
/* Reskin the native range input used for the player's seek bar - kept as a real
<input type="range"> rather than a custom div-based slider so keyboard stepping, pointer
dragging, and screen reader announcements all come for free from the platform. The filled
......
......@@ -149,6 +149,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Desktop: 256px fixed sidebar with the full nav list. Mobile: 5-tab bottom bar (Library, Discover, Social, Soundmarks, Remix) + a "More" sheet for the rest - the export\'s own floating-pill nav only assumed ~4 destinations, not enough for this app\'s real feature count',
'Every page rebuilt from its matching Stitch screen where one existed (Library, Discovery, Remix, Rooms, Channels, Upload, Business/Admin panels, Now Playing); Login, Playlists, and Telegram linking - which had no Stitch mockup - were designed from scratch to match the same system',
'Spotify-inspired UX pass (2026-08-31), interaction patterns only - color identity deliberately stayed cobalt, not Spotify\'s green, per the earlier decision above: nav active state simplified to bold+accent icon/label with no background chip (both sidebar and mobile tabs now carry real aria-current="page"); Library\'s shared song row overlays play/pause on the artwork itself on hover (always visible, not just on hover, for whichever track is actually current) instead of a separate always-on circular button',
'Motion pass (2026-08-31): the three shared bottom-sheet modals (AddToPlaylistModal, SongPicker, RemixSongPicker) and Layout\'s mobile More sheet popped in/out instantly with zero transition - now wired into useMountTransition (same 300ms fade+rise idiom as FullPlayer/NowPlayingBar) so they fade the backdrop and slide/rise the panel both ways. The three modals defer calling their real onClose prop until the exit animation actually finishes (a requestClose + closing-state indirection), since the caller still owns whether they exist in the tree at all and would otherwise unmount them mid-animation. Every page navigation also gets a subtle fade+rise on mount (Layout re-mounts per page already, so a plain CSS animation is enough - no router-level transition machinery needed), and EmptyState now fades in instead of appearing flat',
],
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment