255 lines
7.7 KiB
TypeScript
255 lines
7.7 KiB
TypeScript
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
|
import { Skeleton } from "@/components/ui/skeleton"
|
|
import { albumGridClassName } from "@/lib/album-grid-classes"
|
|
import { TRACK_LIST_CONTAINER } from "@/lib/selection-range-styles"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
function LoadingRegion({
|
|
className,
|
|
children,
|
|
}: {
|
|
className?: string
|
|
children: React.ReactNode
|
|
}) {
|
|
return (
|
|
<div role="status" aria-busy className={className}>
|
|
<span className="sr-only">Loading</span>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function PageHeader({ title }: { title?: string }) {
|
|
return (
|
|
<header
|
|
className={cn(
|
|
"flex shrink-0 items-center gap-2 border-b px-4 py-3",
|
|
!title && "md:hidden"
|
|
)}
|
|
>
|
|
<MobileSidebarTrigger />
|
|
{title ? <h1 className="text-lg font-semibold">{title}</h1> : null}
|
|
</header>
|
|
)
|
|
}
|
|
|
|
function CardSkeleton({ round = false }: { round?: boolean }) {
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
<Skeleton
|
|
className={cn(
|
|
"aspect-square w-full",
|
|
round ? "rounded-full" : "rounded-lg"
|
|
)}
|
|
/>
|
|
<div className={cn("flex flex-col gap-1.5", round && "items-center")}>
|
|
<Skeleton className="h-3.5 w-3/4" />
|
|
{round ? null : <Skeleton className="h-3 w-1/2" />}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CardGrid({ count }: { count: number }) {
|
|
return (
|
|
<div className={albumGridClassName}>
|
|
{Array.from({ length: count }, (_, index) => (
|
|
<CardSkeleton key={index} />
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function CardGridSkeleton({ count = 18 }: { count?: number }) {
|
|
return (
|
|
<LoadingRegion className="flex-1 overflow-hidden p-6 pb-28">
|
|
<CardGrid count={count} />
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
function CarouselRowSkeleton() {
|
|
return (
|
|
<section className="flex min-w-0 flex-col gap-4">
|
|
<Skeleton className="h-7 w-44" />
|
|
<div className="-ml-4 flex overflow-hidden">
|
|
{Array.from({ length: 6 }, (_, index) => (
|
|
<div
|
|
key={index}
|
|
className="min-w-0 shrink-0 grow-0 basis-1/2 pl-4 sm:basis-1/3 md:basis-1/4 lg:basis-1/5 xl:basis-1/6"
|
|
>
|
|
<CardSkeleton />
|
|
</div>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
export function HomeSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex flex-1 flex-col gap-10 overflow-hidden p-6 pb-28">
|
|
<CarouselRowSkeleton />
|
|
<CarouselRowSkeleton />
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
function TrackRowSkeleton({ showCover = false }: { showCover?: boolean }) {
|
|
return (
|
|
<div className="flex items-center gap-4 py-2.5 pr-10 pl-8">
|
|
{showCover ? (
|
|
<Skeleton className="size-9 shrink-0 rounded" />
|
|
) : (
|
|
<Skeleton className="h-3.5 w-5 shrink-0" />
|
|
)}
|
|
<div className="flex min-w-0 flex-1 flex-col gap-1.5">
|
|
<Skeleton className="h-3.5 w-2/5 max-w-72" />
|
|
<Skeleton className="h-3 w-1/4 max-w-40" />
|
|
</div>
|
|
<Skeleton className="h-3 w-9 shrink-0" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function TrackListSkeleton({
|
|
count = 12,
|
|
showCover = false,
|
|
}: {
|
|
count?: number
|
|
showCover?: boolean
|
|
}) {
|
|
return (
|
|
<div className="flex flex-col">
|
|
{Array.from({ length: count }, (_, index) => (
|
|
<TrackRowSkeleton key={index} showCover={showCover} />
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function SongListSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex-1 overflow-hidden pt-9 pb-28">
|
|
<TrackListSkeleton count={16} showCover />
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
/** Matches the header + track list layout of album and playlist pages. */
|
|
export function CollectionDetailSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
|
<PageHeader />
|
|
<div className="mx-auto w-full max-w-9/10 min-w-0">
|
|
<div className="flex flex-col gap-8 px-6 pt-6 pb-8 sm:flex-row sm:items-end">
|
|
<Skeleton className="mx-auto aspect-square w-full max-w-60 shrink-0 rounded-lg sm:mx-0" />
|
|
<div className="flex min-w-0 flex-1 flex-col items-center gap-4 sm:items-start">
|
|
<div className="flex w-full flex-col items-center gap-2 sm:items-start">
|
|
<Skeleton className="h-3 w-14" />
|
|
<Skeleton className="h-9 w-2/3 max-w-96" />
|
|
<Skeleton className="h-5 w-40" />
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<Skeleton className="size-9 rounded-full" />
|
|
<Skeleton className="h-10 w-28 rounded-full" />
|
|
<Skeleton className="size-9 rounded-full" />
|
|
<Skeleton className="size-9 rounded-full" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className={TRACK_LIST_CONTAINER}>
|
|
<TrackListSkeleton />
|
|
</div>
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
export function ArtistDetailSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex h-svh flex-col overflow-hidden pb-28">
|
|
<PageHeader />
|
|
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
|
<Skeleton className="size-32 shrink-0 rounded-full sm:size-40" />
|
|
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
|
<Skeleton className="h-10 w-1/2 max-w-80" />
|
|
<div className="flex items-center gap-2">
|
|
<Skeleton className="size-11 rounded-full" />
|
|
<Skeleton className="size-11 rounded-full" />
|
|
<Skeleton className="size-11 rounded-full" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-col gap-4 px-6">
|
|
<Skeleton className="h-7 w-24" />
|
|
<CardGrid count={6} />
|
|
</div>
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
function ArtistListSkeleton() {
|
|
return (
|
|
<div className="w-72 shrink-0 overflow-hidden border-r pb-28">
|
|
{Array.from({ length: 14 }, (_, index) => (
|
|
<div key={index} className="flex items-center gap-3 px-4 py-2.5">
|
|
<Skeleton className="size-8 shrink-0 rounded-full" />
|
|
<Skeleton className="h-3.5 flex-1" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function ArtistsSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex min-h-0 flex-1">
|
|
<ArtistListSkeleton />
|
|
<div className="min-w-0 flex-1 overflow-hidden">
|
|
<div className="flex items-center justify-between gap-4 border-b px-6 py-4">
|
|
<Skeleton className="h-7 w-48" />
|
|
<div className="flex items-center gap-2">
|
|
<Skeleton className="size-9 rounded-full" />
|
|
<Skeleton className="size-9 rounded-full" />
|
|
</div>
|
|
</div>
|
|
<div className="p-6">
|
|
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 lg:grid-cols-4">
|
|
{Array.from({ length: 8 }, (_, index) => (
|
|
<CardSkeleton key={index} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</LoadingRegion>
|
|
)
|
|
}
|
|
|
|
export function SearchResultsSkeleton() {
|
|
return (
|
|
<LoadingRegion className="flex-1 overflow-hidden p-6 pb-28">
|
|
<div className="mx-auto flex max-w-6xl flex-col gap-10">
|
|
<section className="flex flex-col gap-4">
|
|
<Skeleton className="h-7 w-36" />
|
|
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-3">
|
|
{Array.from({ length: 3 }, (_, index) => (
|
|
<div
|
|
key={index}
|
|
className="flex items-center gap-4 rounded-lg p-3"
|
|
>
|
|
<Skeleton className="size-16 shrink-0 rounded-md" />
|
|
<div className="flex flex-1 flex-col gap-2">
|
|
<Skeleton className="h-4 w-2/3" />
|
|
<Skeleton className="h-3 w-1/3" />
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</section>
|
|
<CarouselRowSkeleton />
|
|
</div>
|
|
</LoadingRegion>
|
|
)
|
|
}
|