Commit 48490dae authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Move Upload inline into My Library instead of its own nav tab

Prod feedback: upload shouldn't be a separate destination - it belongs
inside the library view itself. Extracts the dropzone/queue UI into a
shared UploadPanel used by both the standalone dev /upload page and an
inline section at the top of My Library; /upload now redirects to
/my-library under MINIMAL_NAV_ENABLED, same as the other merged routes.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 0854f96b
Pipeline #1299 failed with stages
......@@ -4,9 +4,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { App } from './App'
import { AuthProvider } from './context/AuthContext'
import { PlayerProvider } from './context/PlayerContext'
import { UploadQueueProvider } from './context/UploadQueueContext'
import { setTokens, clearTokens } from './api/client'
import * as authApi from './api/auth'
import * as libraryApi from './api/library'
import * as musicApi from './api/music'
// Only the two flags App.tsx itself reads - see config/flags.ts for why MINIMAL_NAV_ENABLED
// exists (restricts prod's launch surface) and why it's tested as its own file rather than
......@@ -18,7 +20,9 @@ function renderAppAt(path: string) {
<MemoryRouter initialEntries={[path]}>
<AuthProvider>
<PlayerProvider>
<UploadQueueProvider>
<App />
</UploadQueueProvider>
</PlayerProvider>
</AuthProvider>
</MemoryRouter>,
......@@ -36,6 +40,9 @@ describe('App routing under MINIMAL_NAV_ENABLED', () => {
})
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [] })
vi.spyOn(libraryApi, 'getPlaylists').mockResolvedValue({ status: 'success', playlists: [] })
// My Library now embeds the upload panel inline (see MyLibrary.tsx) - its queue context
// reconciles against this on mount, same as Upload.test.tsx's own default mock.
vi.spyOn(musicApi, 'listUploadJobs').mockResolvedValue({ status: 'success', jobs: [] })
})
afterEach(() => {
......@@ -59,6 +66,11 @@ describe('App routing under MINIMAL_NAV_ENABLED', () => {
expect(await screen.findByRole('heading', { name: 'My Library' })).toBeInTheDocument()
})
it('redirects /upload to My Library - upload lives inline there, not as its own page', async () => {
renderAppAt('/upload')
expect(await screen.findByRole('heading', { name: 'My Library' })).toBeInTheDocument()
})
it('does not redirect /playlists - My Library links there for real playlist management', async () => {
renderAppAt('/playlists')
expect(await screen.findByRole('heading', { name: 'Playlists' })).toBeInTheDocument()
......
......@@ -66,7 +66,9 @@ export function App() {
without its own nav entry. Only the standalone nav tab goes away, not the page. */}
<Route path="/playlists" element={protect(<Playlists />)} />
<Route path="/telegram-link" element={MINIMAL_NAV_ENABLED ? <Navigate to="/my-library" replace /> : protect(<TelegramLink />)} />
<Route path="/upload" element={protect(<Upload />)} />
{/* Upload lives inline inside My Library under the minimal nav (see MyLibrary.tsx's
embedded UploadPanel) rather than as its own page - redirect same as /library etc. */}
<Route path="/upload" element={MINIMAL_NAV_ENABLED ? <Navigate to="/my-library" replace /> : protect(<Upload />)} />
<Route path="/discovery" element={protect(<Discovery />, { allowGuest: true })} />
<Route path="/social" element={MINIMAL_NAV_ENABLED ? <Navigate to="/my-library" replace /> : protect(<Social />)} />
<Route path="/dm/:threadId" element={protect(<DMThreadView />)} />
......
......@@ -59,14 +59,20 @@ describe('Layout nav under MINIMAL_NAV_ENABLED', () => {
expect(screen.queryByRole('link', { name: 'Telegram' })).not.toBeInTheDocument()
})
it('still shows Home, Upload, Discover, Soundmarks, and Settings', () => {
it('still shows Home, Discover, Soundmarks, and Settings', () => {
renderLayout('/my-library')
for (const name of ['Home', 'Upload', 'Discover', 'Soundmarks', 'Settings']) {
for (const name of ['Home', 'Discover', 'Soundmarks', 'Settings']) {
expect(screen.getAllByRole('link', { name }).length).toBeGreaterThan(0)
}
})
it('does not show Upload as its own nav entry - it lives inline inside My Library', () => {
renderLayout('/my-library')
expect(screen.queryByRole('link', { name: 'Upload' })).not.toBeInTheDocument()
})
it('marks My Library as the active page when on /my-library', () => {
renderLayout('/my-library')
......
......@@ -52,14 +52,15 @@ const ALL_NAV_ITEMS: { to: string; labelKey: string; icon: LucideIcon }[] = [
{ to: '/settings', labelKey: 'nav.settings', icon: SettingsIcon },
]
// Prod's minimal nav (per explicit direction to keep its launch surface to upload/tag +
// discover + one consolidated library view): /library and /playlists collapse into a single
// /my-library entry, placed where /library used to sit; /social and /telegram-link disappear
// entirely. Dev's nav is untouched - this only takes effect when MINIMAL_NAV_ENABLED is on.
// Prod's minimal nav (per explicit direction to keep its launch surface to discover + one
// consolidated library view): /library and /playlists collapse into a single /my-library
// entry, placed where /library used to sit; /social and /telegram-link disappear entirely.
// /upload isn't a nav destination here either - it lives inline inside My Library itself (see
// MyLibrary.tsx's embedded UploadPanel) per explicit direction that upload shouldn't be its
// own tab. Dev's nav is untouched - this only takes effect when MINIMAL_NAV_ENABLED is on.
const MINIMAL_NAV_ITEMS: { to: string; labelKey: string; icon: LucideIcon }[] = [
{ to: '/home', labelKey: 'nav.home', icon: Globe },
{ to: '/my-library', labelKey: 'nav.myLibrary', icon: Library },
{ to: '/upload', labelKey: 'nav.upload', icon: Upload },
{ to: '/discovery', labelKey: 'nav.discover', icon: Compass },
{ to: '/soundmarks', labelKey: 'nav.soundmarks', icon: MapPin },
{ to: '/settings', labelKey: 'nav.settings', icon: SettingsIcon },
......
This diff is collapsed.
......@@ -16,10 +16,11 @@ export const FARSI_ENABLED = import.meta.env.VITE_ENABLE_FARSI === 'true'
// Inverse polarity from the flags above on purpose: this one *restricts* scope rather than
// unlocking it. Off by default (full nav - every page built so far, same as today). Prod's
// build sets VITE_MINIMAL_NAV=true to cut the nav down to upload/tag + discover + a single
// consolidated library tab, per explicit direction to keep prod's launch surface small.
// /social, /telegram-link, and /library redirect to /my-library (see App.tsx) rather than
// 404 if this flips on with something still linking to them. /playlists is the one exception -
// it stays reachable (no nav entry, same as /library/album) since My Library's own "Your
// Playlists" section links there to actually create/open/download a playlist.
// build sets VITE_MINIMAL_NAV=true to cut the nav down to discover + a single consolidated
// library tab (which itself embeds upload/tag inline, not as a separate destination), per
// explicit direction to keep prod's launch surface small. /social, /telegram-link, /upload,
// and /library all redirect to /my-library (see App.tsx) rather than 404 if this flips on
// with something still linking to them. /playlists is the one exception - it stays reachable
// (no nav entry, same as /library/album) since My Library's own "Your Playlists" section
// links there to actually create/open/download a playlist.
export const MINIMAL_NAV_ENABLED = import.meta.env.VITE_MINIMAL_NAV === 'true'
{
"title": "My Library",
"section.upload": "Upload",
"section.latestUpload": "Latest Upload",
"section.playlists": "Your Playlists",
"section.manage": "Manage",
......
{
"title": "کتابخانه من",
"section.upload": "بارگذاری",
"section.latestUpload": "آخرین بارگذاری",
"section.playlists": "پلی‌لیست‌های شما",
"section.manage": "مدیریت",
......
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter, Route, Routes } from 'react-router-dom'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { MyLibrary } from './MyLibrary'
import { AuthProvider } from '../context/AuthContext'
import { PlayerProvider } from '../context/PlayerContext'
import { UploadQueueProvider } from '../context/UploadQueueContext'
import { ApiError } from '../api/client'
import * as libraryApi from '../api/library'
import * as streamApi from '../api/stream'
import * as musicApi from '../api/music'
const SONG = {
id: 1,
......@@ -40,12 +42,14 @@ function renderMyLibrary() {
<MemoryRouter>
<AuthProvider>
<PlayerProvider>
<UploadQueueProvider>
<Routes>
<Route path="/" element={<MyLibrary />} />
<Route path="/playlists" element={<p>Playlists route</p>} />
<Route path="/library/album" element={<p>Album route</p>} />
<Route path="/library/liked" element={<p>Liked Songs route</p>} />
</Routes>
</UploadQueueProvider>
</PlayerProvider>
</AuthProvider>
</MemoryRouter>,
......@@ -57,6 +61,9 @@ describe('MyLibrary', () => {
vi.stubEnv('VITE_DEV_ACCESS_TOKEN', '')
vi.stubEnv('VITE_DEV_REFRESH_TOKEN', '')
vi.spyOn(libraryApi, 'getPlaylists').mockResolvedValue({ status: 'success', playlists: [] })
// My Library now embeds the upload panel inline (see UploadPanel.tsx) - its queue context
// reconciles against this on mount, same default-empty mock Upload.test.tsx itself uses.
vi.spyOn(musicApi, 'listUploadJobs').mockResolvedValue({ status: 'success', jobs: [] })
})
afterEach(() => {
......@@ -72,6 +79,69 @@ describe('MyLibrary', () => {
expect(await screen.findByText(/Nothing here yet/)).toBeInTheDocument()
})
it('shows an inline Upload section with a dropzone - upload is not a separate page under minimal nav', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [] })
renderMyLibrary()
expect(await screen.findByRole('heading', { name: 'Upload' })).toBeInTheDocument()
expect(screen.getByText('Choose audio files, or drag them here')).toBeInTheDocument()
})
it('uploads a file from the inline My Library panel and shows the tagged result', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [] })
vi.spyOn(musicApi, 'uploadDirect').mockImplementation(async (_file, onProgress) => {
onProgress?.(100)
return { job_id: 1, status: 'queued' }
})
vi.spyOn(musicApi, 'listUploadJobs')
.mockResolvedValueOnce({ status: 'success', jobs: [] })
.mockResolvedValue({
status: 'success',
jobs: [
{
job_id: 1,
original_filename: 'test.mp3',
status: 'done',
error: null,
metadata: {
library_song_id: 42,
title: 'Invisible (Remastered)',
artist: 'Duran Duran',
album: 'Notorious',
genre: 'Pop',
year: '1986',
has_lyrics: false,
lyrics: null,
cover_art: null,
},
},
],
})
renderMyLibrary()
// The upload section only mounts once getLibrary's own loading state resolves (see
// MyLibrary.tsx) - wait for it rather than querying the input immediately.
await screen.findByRole('heading', { name: 'Upload' })
const file = new File([new Uint8Array([1, 2, 3])], 'test.mp3', { type: 'audio/mpeg' })
const input = document.querySelector('input[type="file"]') as HTMLInputElement
await userEvent.upload(input, file)
vi.useFakeTimers()
try {
await act(async () => {
fireEvent.click(screen.getByRole('button', { name: /Upload 1 file/ }))
})
await act(async () => {
await vi.advanceTimersByTimeAsync(3000)
})
} finally {
vi.useRealTimers()
}
expect(await screen.findByText('Invisible (Remastered)')).toBeInTheDocument()
})
it('shows the single most-recently-uploaded song as the Latest Upload', async () => {
vi.spyOn(libraryApi, 'getLibrary').mockResolvedValue({ status: 'success', library: [SONG, NEWER_SONG] })
......
......@@ -6,6 +6,7 @@ import { deleteLibrarySong, favoriteSong, getLibrary, getPlaylists, unfavoriteSo
import { ApiError } from '../api/client'
import { groupIntoAlbums, albumHref } from '../lib/albums'
import { Layout } from '../components/Layout'
import { UploadPanel } from '../components/UploadPanel'
import { AddToPlaylistModal } from '../components/AddToPlaylistModal'
import { AlbumCard, LikedSongsCard } from '../components/AlbumCard'
import { SongRow } from '../components/SongRow'
......@@ -86,6 +87,15 @@ export function MyLibrary() {
{!loading && !error && (
<div className="animate-content-enter">
{/* Upload lives inline here rather than as its own nav tab/page under the minimal
nav (per explicit direction: "upload should not be a different tab" - it's part
of the library view, not a separate destination) - reuses the exact same panel
dev's standalone /upload page renders, see UploadPanel.tsx. */}
<div className="mb-8">
<h2 className="mb-2 text-xs font-semibold uppercase tracking-[0.1em] text-primary">{t('section.upload')}</h2>
<UploadPanel />
</div>
{latestSong && (
<div className="mb-8">
<h2 className="mb-2 text-xs font-semibold uppercase tracking-[0.1em] text-primary">{t('section.latestUpload')}</h2>
......
This diff is collapsed.
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