diff --git a/app/(app)/layout.tsx b/app/(app)/layout.tsx
index 36f78b3..7a972e1 100644
--- a/app/(app)/layout.tsx
+++ b/app/(app)/layout.tsx
@@ -1,8 +1,10 @@
import { AddToPlaylistProvider } from "@/components/add-to-playlist-provider"
import { FavoritesProvider } from "@/components/favorites-provider"
+import { PlaybackProvider } from "@/components/playback-provider"
+import { PlayerBar } from "@/components/player-bar"
+import { QueuePanel } from "@/components/queue-panel"
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
import { AppSidebar } from "@/components/app-sidebar"
-import { PlayerBar } from "@/components/player-bar"
export default function AppLayout({
children,
@@ -11,13 +13,18 @@ export default function AppLayout({
}>) {
return (
-
-
-
- {children}
-
-
-
+
+
+
+
+
+ {children}
+
+
+
+
+
+
)
}
diff --git a/components/album-card.tsx b/components/album-card.tsx
index 32bec2c..a3b69a9 100644
--- a/components/album-card.tsx
+++ b/components/album-card.tsx
@@ -2,19 +2,18 @@
import Image from "next/image"
import Link from "next/link"
-import {
- ListEnd,
- ListPlus,
- ListStart,
- MoreHorizontal,
- Play,
- Star,
- User,
-} from "lucide-react"
-import { toast } from "sonner"
+import { MoreHorizontal, Play } from "lucide-react"
+import { useConvex } from "convex/react"
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
import { useFavorites } from "@/components/favorites-provider"
+import {
+ MediaContextMenuItems,
+ type MediaContextAction,
+} from "@/components/media-context-menu"
+import { usePlayback } from "@/components/playback-provider"
+import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
+import { api } from "@/convex/_generated/api"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
@@ -28,8 +27,31 @@ import type { Id } from "@/convex/_generated/dataModel"
import { albumCoverUrl } from "@/lib/cover-urls"
export function AlbumCard({ album }: { album: BrowseAlbum }) {
+ const convex = useConvex()
const { openAddAlbumToPlaylist } = useAddToPlaylist()
const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites()
+ const { playAlbum } = usePlayback()
+ const { runQueueAction } = useQueueMediaActions()
+
+ async function handleCardAction(action: MediaContextAction) {
+ switch (action) {
+ case "playlist":
+ void openAddAlbumToPlaylist(album.id as Id<"albums">)
+ break
+ case "favorite":
+ void toggleAlbumFavorite(album.id as Id<"albums">)
+ break
+ case "play-next":
+ case "play-last":
+ case "shuffle": {
+ const songIds = await convex.query(api.playlists.getAlbumSongIds, {
+ albumId: album.id as Id<"albums">,
+ })
+ void runQueueAction(action, songIds)
+ break
+ }
+ }
+ }
return (
@@ -49,12 +71,15 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
-
+
@@ -72,50 +97,12 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
- {
- event.preventDefault()
- void openAddAlbumToPlaylist(album.id as Id<"albums">)
- }}
- >
- Add to Playlist
-
-
-
- event.preventDefault()}
- >
- Play Next
-
-
- event.preventDefault()}
- >
- Play Last
-
-
-
-
-
- Go to Artist
-
-
-
-
- {
- event.preventDefault()
- void toggleAlbumFavorite(album.id as Id<"albums">)
- }}
- >
- {isAlbumFavorite(album.id) ? "Unfavorite" : "Favorite"}
-
-
+ void handleCardAction(action)}
+ favorited={isAlbumFavorite(album.id)}
+ navigation={{ artist: { id: album.artist.id } }}
+ />
diff --git a/components/album-view.tsx b/components/album-view.tsx
index 8837b33..b654e35 100644
--- a/components/album-view.tsx
+++ b/components/album-view.tsx
@@ -5,9 +5,12 @@ import Image from "next/image"
import Link from "next/link"
import { Play, Share2, Shuffle, Star } from "lucide-react"
+import { TrackNumberPlayButton } from "@/components/track-number-play-button"
+
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
import { FavoriteMediaButton } from "@/components/favorite-media-button"
import { useFavorites } from "@/components/favorites-provider"
+import { usePlayback } from "@/components/playback-provider"
import { toast } from "sonner"
import {
@@ -16,6 +19,7 @@ import {
} from "@/components/media-context-menu"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
+import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
import { useTrackSelection } from "@/hooks/use-track-selection"
import { cn } from "@/lib/utils"
import type { Id } from "@/convex/_generated/dataModel"
@@ -74,6 +78,8 @@ function TrackRow({
onToggleFavorite,
onPrepareContextMenu,
onMediaAction,
+ isNowPlaying,
+ onPlay,
}: {
track: BrowseAlbumTrack
index: number
@@ -88,6 +94,8 @@ function TrackRow({
onToggleFavorite: () => void
onPrepareContextMenu: () => void
onMediaAction: (action: MediaContextAction, trackId: string) => void
+ isNowPlaying: boolean
+ onPlay: () => void
}) {
const displayTrack = track.track > 0 ? track.track : index + 1
const inRange = isInSelectionRange(selectionPosition)
@@ -98,6 +106,10 @@ function TrackRow({
tabIndex={0}
onMouseDown={onPointerDown}
onClick={onSelect}
+ onDoubleClick={(event) => {
+ event.preventDefault()
+ onPlay()
+ }}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault()
@@ -145,23 +157,14 @@ function TrackRow({
-
- {isActive ? (
-
- ) : (
-
{displayTrack}
- )}
-
+
{track.title}
@@ -199,6 +202,13 @@ export function AlbumView({ album }: { album: BrowseAlbumDetail }) {
toggleAlbumFavorite,
favoriteSongs,
} = useFavorites()
+ const { currentSong, playFromSong, playAlbum, playAlbumShuffled } =
+ usePlayback()
+ const { runQueueAction } = useQueueMediaActions()
+ const albumSongIds = React.useMemo(
+ () => album.tracks.map((track) => track.id as Id<"songs">),
+ [album.tracks]
+ )
const metadata = formatMetadata(album.genre, album.year)
const [activeTrackId, setActiveTrackId] = React.useState(
() => album.tracks[0]?.id ?? ""
@@ -231,8 +241,6 @@ export function AlbumView({ album }: { album: BrowseAlbumDetail }) {
: activeTrackId
? [activeTrackId]
: []
- const count = targetIds.length
-
switch (action) {
case "favorite":
void favoriteSongs(targetIds as Id<"songs">[])
@@ -241,34 +249,27 @@ export function AlbumView({ album }: { album: BrowseAlbumDetail }) {
openAddToPlaylist(targetIds as Id<"songs">[])
break
case "play-next":
- toast.success(
- count > 1 ? `Queued ${count} songs to play next` : "Play next"
- )
- break
case "play-last":
- toast.success(
- count > 1 ? `Queued ${count} songs to play last` : "Play last"
- )
+ case "shuffle":
+ void runQueueAction(action, targetIds as Id<"songs">[])
break
}
}
function handleAlbumMediaAction(action: MediaContextAction) {
- const targetIds = album.tracks.map((track) => track.id)
- const count = targetIds.length
+ const targetIds = album.tracks.map((track) => track.id as Id<"songs">)
switch (action) {
case "favorite":
void toggleAlbumFavorite(album.id as Id<"albums">)
break
case "playlist":
- openAddToPlaylist(targetIds as Id<"songs">[])
+ openAddToPlaylist(targetIds)
break
case "play-next":
- toast.success(`Queued ${count} songs to play next`)
- break
case "play-last":
- toast.success(`Queued ${count} songs to play last`)
+ case "shuffle":
+ void runQueueAction(action, targetIds)
break
}
}
@@ -335,12 +336,14 @@ export function AlbumView({ album }: { album: BrowseAlbumDetail }) {
size="icon"
className="rounded-full"
aria-label="Shuffle album"
+ onClick={() => void playAlbumShuffled(album.id as Id<"albums">)}
>
@@ -90,6 +101,9 @@ export function ArtistView({
size="icon"
className="size-11 rounded-full"
aria-label={`Shuffle ${artist.name}`}
+ onClick={() =>
+ void playArtistShuffled(artist.id as Id<"artists">)
+ }
>
diff --git a/components/artists-view.tsx b/components/artists-view.tsx
index b458d6d..9f45cce 100644
--- a/components/artists-view.tsx
+++ b/components/artists-view.tsx
@@ -8,6 +8,7 @@ import { ChevronRightIcon, Play, Shuffle } from "lucide-react"
import { AlbumCard } from "@/components/album-card"
import { FavoriteMediaButton } from "@/components/favorite-media-button"
import { useFavorites } from "@/components/favorites-provider"
+import { usePlayback } from "@/components/playback-provider"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
import { cn } from "@/lib/utils"
@@ -68,6 +69,7 @@ export function ArtistsView({
() => sortedArtists[0]?.id ?? ""
)
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
+ const { playArtist, playArtistShuffled } = usePlayback()
const selectedArtist = sortedArtists.find(
(artist) => artist.id === selectedId
@@ -102,7 +104,14 @@ export function ArtistsView({
-