mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
Fix: hash-based navigation from job list (#312)
## Summary
- Fix bug where clicking "Review Lyrics" or "Select Instrumental" from
the job list showed "Page not found" but reloading worked
- Changed from Next.js `Link` to regular `<a>` tags for hash-based URLs
## Root Cause
Next.js `Link` uses `history.pushState` for client-side navigation,
which doesn't trigger the `hashchange` event. The client.tsx component's
hash state wasn't updating when navigating.
## Solution
Use regular `<a>` tags for hash URLs (`/app/jobs#/{jobId}/review`). When
clicking an `<a>` tag with a hash URL on the same page, the browser:
1. Updates the hash without reloading
2. Fires the `hashchange` event
3. Our listener updates state
4. Component re-renders with correct route
## Test plan
- [x] Unit tests pass
- [ ] Manual test: Click "Review Lyrics" from job list - should navigate
correctly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
@coderabbitai ignore
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a1f9da2fb5
commit
b16bdb024b
10 files changed
+52
-23
No files matched your search
@@ -1035,8 +1035,8 @@ function AdminJobsPageContent() {
|
||||
</p>
|
||||
{[
|
||||
{ key: "theme_id", label: "Theme", value: selectedJob.theme_id || "default" },
|
||||
{ key: "brand_prefix", label: "Brand Prefix", value: (selectedJob as any).brand_prefix },
|
||||
{ key: "customer_email", label: "Customer Email", value: (selectedJob as any).customer_email },
|
||||
{ key: "brand_prefix", label: "Brand Prefix", value: selectedJob.brand_prefix },
|
||||
{ key: "customer_email", label: "Customer Email", value: selectedJob.customer_email },
|
||||
].map(({ key, label, value }) => (
|
||||
<div key={key} className="flex items-center gap-2 mb-2">
|
||||
<span className="text-sm font-medium w-28">{label}:</span>
|
||||
|
||||
@@ -69,7 +69,7 @@ const mockOverrides = {
|
||||
{
|
||||
email: "vip@example.com",
|
||||
bypass_job_limit: true,
|
||||
custom_daily_job_limit: null,
|
||||
custom_daily_job_limit: undefined,
|
||||
reason: "VIP user",
|
||||
created_by: "admin@nomadkaraoke.com",
|
||||
created_at: "2025-01-08T15:00:00Z",
|
||||
@@ -242,7 +242,7 @@ describe("AdminRateLimitsPage", () => {
|
||||
})
|
||||
|
||||
it("adds a disposable domain", async () => {
|
||||
mockAdminApi.addDisposableDomain.mockResolvedValue({ success: true })
|
||||
mockAdminApi.addDisposableDomain.mockResolvedValue({ success: true, message: "Operation successful" })
|
||||
|
||||
const user = userEvent.setup()
|
||||
render(<AdminRateLimitsPage />)
|
||||
@@ -339,7 +339,7 @@ describe("AdminRateLimitsPage", () => {
|
||||
})
|
||||
|
||||
it("creates a new override", async () => {
|
||||
mockAdminApi.setUserOverride.mockResolvedValue({ success: true })
|
||||
mockAdminApi.setUserOverride.mockResolvedValue({ success: true, message: "Operation successful" })
|
||||
|
||||
const user = userEvent.setup()
|
||||
render(<AdminRateLimitsPage />)
|
||||
|
||||
@@ -12,7 +12,7 @@ jest.mock('@/lib/auth', () => ({
|
||||
useAuth: jest.fn(),
|
||||
}))
|
||||
|
||||
const mockUseAuth = useAuth as jest.Mock
|
||||
const mockUseAuth = useAuth as unknown as jest.Mock
|
||||
|
||||
// Mock window.location.reload
|
||||
const mockReload = jest.fn()
|
||||
|
||||
@@ -100,7 +100,7 @@ describe('JobCard', () => {
|
||||
expect(reviewLink).toBeInTheDocument()
|
||||
const href = reviewLink.closest('a')?.getAttribute('href') || ''
|
||||
// Uses hash-based routing for static hosting
|
||||
// Note: Next.js Link normalizes the URL, removing trailing slash before hash
|
||||
// Uses <a> tag (not Next.js Link) to ensure hashchange event fires
|
||||
expect(href).toBe('/app/jobs#/123/review')
|
||||
})
|
||||
|
||||
@@ -123,7 +123,7 @@ describe('JobCard', () => {
|
||||
expect(instrumentalLink).toBeInTheDocument()
|
||||
const href = instrumentalLink.closest('a')?.getAttribute('href') || ''
|
||||
// Uses hash-based routing for static hosting
|
||||
// Note: Next.js Link normalizes the URL, removing trailing slash before hash
|
||||
// Uses <a> tag (not Next.js Link) to ensure hashchange event fires
|
||||
expect(href).toBe('/app/jobs#/123/instrumental')
|
||||
})
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ interface StatsCardProps {
|
||||
}
|
||||
loading?: boolean
|
||||
className?: string
|
||||
valueClassName?: string
|
||||
}
|
||||
|
||||
export function StatsCard({
|
||||
@@ -27,6 +28,7 @@ export function StatsCard({
|
||||
trend,
|
||||
loading,
|
||||
className,
|
||||
valueClassName,
|
||||
}: StatsCardProps) {
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -53,7 +55,7 @@ export function StatsCard({
|
||||
{Icon && <Icon className="h-4 w-4 text-muted-foreground" />}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{value}</div>
|
||||
<div className={cn("text-2xl font-bold", valueClassName)}>{value}</div>
|
||||
{description && (
|
||||
<p className="text-xs text-muted-foreground mt-1">{description}</p>
|
||||
)}
|
||||
@@ -73,12 +75,20 @@ export function StatsCard({
|
||||
interface StatsGridProps {
|
||||
children: React.ReactNode
|
||||
className?: string
|
||||
columns?: 2 | 3 | 4
|
||||
}
|
||||
|
||||
export function StatsGrid({ children, className }: StatsGridProps) {
|
||||
export function StatsGrid({ children, className, columns }: StatsGridProps) {
|
||||
const colsClass = columns === 2
|
||||
? "md:grid-cols-2"
|
||||
: columns === 3
|
||||
? "md:grid-cols-2 lg:grid-cols-3"
|
||||
: "md:grid-cols-2 lg:grid-cols-4"
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
"grid gap-4 md:grid-cols-2 lg:grid-cols-4",
|
||||
"grid gap-4",
|
||||
colsClass,
|
||||
className
|
||||
)}>
|
||||
{children}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import Link from "next/link"
|
||||
import { Job } from "@/lib/api"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Zap } from "lucide-react"
|
||||
@@ -102,13 +101,14 @@ export function JobCard({ job, onRefresh }: JobCardProps) {
|
||||
}
|
||||
|
||||
if (job.status === "awaiting_review" || job.status === "in_review") {
|
||||
// Use <a> instead of Link for hash-based URLs to ensure hashchange event fires
|
||||
return (
|
||||
<Link
|
||||
<a
|
||||
href={`/app/jobs#/${job.job_id}/review`}
|
||||
className="inline-flex items-center gap-1 text-xs px-3 py-1.5 rounded bg-primary-500 hover:bg-primary-600 text-white"
|
||||
>
|
||||
Review Lyrics
|
||||
</Link>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -125,13 +125,14 @@ export function JobCard({ job, onRefresh }: JobCardProps) {
|
||||
}
|
||||
|
||||
if (job.status === "awaiting_instrumental_selection") {
|
||||
// Use <a> instead of Link for hash-based URLs to ensure hashchange event fires
|
||||
return (
|
||||
<Link
|
||||
<a
|
||||
href={`/app/jobs#/${job.job_id}/instrumental`}
|
||||
className="inline-flex items-center gap-1 text-xs px-3 py-1.5 rounded bg-primary-500 hover:bg-primary-600 text-white"
|
||||
>
|
||||
Select Instrumental
|
||||
</Link>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,14 @@ const DialogOverlay = React.forwardRef<
|
||||
))
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
||||
|
||||
interface DialogContentProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
||||
showCloseButton?: boolean
|
||||
}
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
DialogContentProps
|
||||
>(({ className, children, showCloseButton = true, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
@@ -40,10 +44,12 @@ const DialogContent = React.forwardRef<
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-3 top-2.5 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close className="absolute right-3 top-2.5 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
))
|
||||
|
||||
@@ -243,7 +243,7 @@ async function testLyricsReview(page: any, context: any, jobId: string) {
|
||||
console.log(` WARNING: Preview error: ${errorText}`);
|
||||
} else if (await videoElement.isVisible({ timeout: 10000 }).catch(() => false)) {
|
||||
console.log(' Video element visible');
|
||||
const videoState = await videoElement.first().evaluate((el) => {
|
||||
const videoState = await videoElement.first().evaluate((el: Element) => {
|
||||
const video = el as HTMLVideoElement;
|
||||
return {
|
||||
src: video.src?.substring(0, 50),
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="@testing-library/jest-dom" />
|
||||
@@ -55,6 +55,7 @@ export interface Job {
|
||||
title?: string;
|
||||
filename?: string;
|
||||
error_message?: string;
|
||||
error_details?: Record<string, any>;
|
||||
file_urls?: Record<string, any>;
|
||||
state_data?: Record<string, any>;
|
||||
timeline?: Array<{
|
||||
@@ -70,6 +71,16 @@ export interface Job {
|
||||
user_email?: string;
|
||||
outputs_deleted_at?: string;
|
||||
outputs_deleted_by?: string;
|
||||
// Audio search fields
|
||||
audio_search_artist?: string;
|
||||
audio_search_title?: string;
|
||||
// Theme and branding
|
||||
theme_id?: string;
|
||||
brand_prefix?: string;
|
||||
// Customer order fields
|
||||
customer_email?: string;
|
||||
// Request tracking metadata
|
||||
request_metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface UploadJobResponse {
|
||||
|
||||
Reference in new issue
Block a user