Compare commits
1
Commits
No files matched your search
@@ -149,6 +149,7 @@ export default function AlbumScreen() {
|
|||||||
headerTintColor: palette.foreground,
|
headerTintColor: palette.foreground,
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<MediaActionMenu
|
<MediaActionMenu
|
||||||
|
stationArtistId={album.artist.id}
|
||||||
selectedCount={album.tracks.length}
|
selectedCount={album.tracks.length}
|
||||||
favorited={isAlbumFav(album.id)}
|
favorited={isAlbumFav(album.id)}
|
||||||
share={{ type: "album", albumId: album.id }}
|
share={{ type: "album", albumId: album.id }}
|
||||||
@@ -156,7 +157,8 @@ export default function AlbumScreen() {
|
|||||||
void handleAlbumDetailAction(
|
void handleAlbumDetailAction(
|
||||||
album.id as Id<"albums">,
|
album.id as Id<"albums">,
|
||||||
songIds,
|
songIds,
|
||||||
action
|
action,
|
||||||
|
album.artist.id as Id<"artists">
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -321,6 +323,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
|
stationArtistId={album.artist.id}
|
||||||
favorited={favorited}
|
favorited={favorited}
|
||||||
navigation={{
|
navigation={{
|
||||||
artist: { id: album.artist.id },
|
artist: { id: album.artist.id },
|
||||||
|
|||||||
@@ -533,6 +533,7 @@ function SongMeta({
|
|||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<MediaActionMenu
|
<MediaActionMenu
|
||||||
|
stationArtistId={song.artist.id}
|
||||||
favorited={favorited}
|
favorited={favorited}
|
||||||
navigation={{
|
navigation={{
|
||||||
artist: { id: song.artist.id },
|
artist: { id: song.artist.id },
|
||||||
@@ -542,6 +543,7 @@ function SongMeta({
|
|||||||
"play-next",
|
"play-next",
|
||||||
"play-last",
|
"play-last",
|
||||||
"shuffle",
|
"shuffle",
|
||||||
|
"create-station",
|
||||||
"favorite",
|
"favorite",
|
||||||
"go-artist",
|
"go-artist",
|
||||||
"go-album",
|
"go-album",
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ export const AlbumCard = memo(function AlbumCard({
|
|||||||
return (
|
return (
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
favorited={isAlbumFavorite(album.id)}
|
favorited={isAlbumFavorite(album.id)}
|
||||||
|
stationArtistId={album.artist.id}
|
||||||
navigation={{ artist: { id: album.artist.id } }}
|
navigation={{ artist: { id: album.artist.id } }}
|
||||||
share={{ type: "album", albumId: album.id }}
|
share={{ type: "album", albumId: album.id }}
|
||||||
onAction={(action) => void handleAlbumAction(album, action)}
|
onAction={(action) => void handleAlbumAction(album, action)}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export type MediaAction =
|
|||||||
| "play-next"
|
| "play-next"
|
||||||
| "play-last"
|
| "play-last"
|
||||||
| "shuffle"
|
| "shuffle"
|
||||||
|
| "create-station"
|
||||||
| "favorite"
|
| "favorite"
|
||||||
| "go-artist"
|
| "go-artist"
|
||||||
| "go-album"
|
| "go-album"
|
||||||
@@ -35,6 +36,7 @@ export type MediaMenuConfig = {
|
|||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
showFavorite?: boolean
|
showFavorite?: boolean
|
||||||
|
stationArtistId?: string
|
||||||
navigation?: MediaNavigation
|
navigation?: MediaNavigation
|
||||||
share?: MediaShareContext
|
share?: MediaShareContext
|
||||||
includeActions?: MediaAction[]
|
includeActions?: MediaAction[]
|
||||||
@@ -78,6 +80,11 @@ const MEDIA_ACTION_ITEMS: {
|
|||||||
label: (countSuffix) => `Shuffle${countSuffix}`,
|
label: (countSuffix) => `Shuffle${countSuffix}`,
|
||||||
image: "shuffle",
|
image: "shuffle",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
action: "create-station",
|
||||||
|
label: () => "Create Station",
|
||||||
|
image: "shuffle",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
action: "go-artist",
|
action: "go-artist",
|
||||||
label: () => "Go to Artist",
|
label: () => "Go to Artist",
|
||||||
@@ -105,6 +112,10 @@ function isActionIncluded(
|
|||||||
action: MediaAction,
|
action: MediaAction,
|
||||||
config: Omit<MediaMenuConfig, "onAction">
|
config: Omit<MediaMenuConfig, "onAction">
|
||||||
): boolean {
|
): boolean {
|
||||||
|
if (action === "create-station" && !config.stationArtistId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (config.includeActions) {
|
if (config.includeActions) {
|
||||||
return config.includeActions.includes(action)
|
return config.includeActions.includes(action)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ export const SongListRow = memo(function SongListRow({
|
|||||||
inset={inset}
|
inset={inset}
|
||||||
onPress={handlePress}
|
onPress={handlePress}
|
||||||
contextMenu={{
|
contextMenu={{
|
||||||
|
stationArtistId: song.artist.id,
|
||||||
favorited,
|
favorited,
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
navigation: {
|
navigation: {
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ export function useMediaMenuActions() {
|
|||||||
toggleSongFavorite,
|
toggleSongFavorite,
|
||||||
favoriteSongs,
|
favoriteSongs,
|
||||||
} = useFavorites()
|
} = useFavorites()
|
||||||
const { addToQueueNext, addToQueueLast, playShuffled } = usePlaybackActions()
|
const { addToQueueNext, addToQueueLast, playShuffled, playArtistShuffled } =
|
||||||
|
usePlaybackActions()
|
||||||
|
|
||||||
const runQueueAction = useCallback(
|
const runQueueAction = useCallback(
|
||||||
async (action: MediaAction, songIds: Id<"songs">[]) => {
|
async (action: MediaAction, songIds: Id<"songs">[]) => {
|
||||||
@@ -74,6 +75,11 @@ export function useMediaMenuActions() {
|
|||||||
async (song: BrowseSong, action: MediaAction) => {
|
async (song: BrowseSong, action: MediaAction) => {
|
||||||
const songIds = [song.id as Id<"songs">]
|
const songIds = [song.id as Id<"songs">]
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
await runMediaAction(() =>
|
||||||
|
playArtistShuffled(song.artist.id as Id<"artists">)
|
||||||
|
)
|
||||||
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
openAddToPlaylist(songIds)
|
openAddToPlaylist(songIds)
|
||||||
break
|
break
|
||||||
@@ -95,13 +101,22 @@ export function useMediaMenuActions() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[openAddToPlaylist, push, runQueueAction, toggleSongFavorite]
|
[
|
||||||
|
openAddToPlaylist,
|
||||||
|
push,
|
||||||
|
runQueueAction,
|
||||||
|
toggleSongFavorite,
|
||||||
|
playArtistShuffled,
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleAlbumAction = useCallback(
|
const handleAlbumAction = useCallback(
|
||||||
async (album: BrowseAlbum, action: MediaAction) => {
|
async (album: BrowseAlbum, action: MediaAction) => {
|
||||||
await runMediaAction(async () => {
|
await runMediaAction(async () => {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
await playArtistShuffled(album.artist.id as Id<"artists">)
|
||||||
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
await openAddAlbumToPlaylist(album.id as Id<"albums">)
|
await openAddAlbumToPlaylist(album.id as Id<"albums">)
|
||||||
break
|
break
|
||||||
@@ -132,6 +147,7 @@ export function useMediaMenuActions() {
|
|||||||
convex,
|
convex,
|
||||||
cacheScope,
|
cacheScope,
|
||||||
openAddAlbumToPlaylist,
|
openAddAlbumToPlaylist,
|
||||||
|
playArtistShuffled,
|
||||||
push,
|
push,
|
||||||
runQueueAction,
|
runQueueAction,
|
||||||
toggleAlbumFavorite,
|
toggleAlbumFavorite,
|
||||||
@@ -207,9 +223,13 @@ export function useMediaMenuActions() {
|
|||||||
async (
|
async (
|
||||||
albumId: Id<"albums">,
|
albumId: Id<"albums">,
|
||||||
songIds: Id<"songs">[],
|
songIds: Id<"songs">[],
|
||||||
action: MediaAction
|
action: MediaAction,
|
||||||
|
artistId: Id<"artists">
|
||||||
) => {
|
) => {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
await runMediaAction(() => playArtistShuffled(artistId))
|
||||||
|
break
|
||||||
case "favorite":
|
case "favorite":
|
||||||
await toggleAlbumFavorite(albumId)
|
await toggleAlbumFavorite(albumId)
|
||||||
break
|
break
|
||||||
@@ -225,7 +245,7 @@ export function useMediaMenuActions() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[openAddToPlaylist, runQueueAction, toggleAlbumFavorite]
|
[openAddToPlaylist, runQueueAction, toggleAlbumFavorite, playArtistShuffled]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleAlbumTrackAction = useCallback(
|
const handleAlbumTrackAction = useCallback(
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
|||||||
const { openAddAlbumToPlaylist } = useAddToPlaylist()
|
const { openAddAlbumToPlaylist } = useAddToPlaylist()
|
||||||
const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites()
|
const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites()
|
||||||
const { playAlbum } = usePlayback()
|
const { playAlbum } = usePlayback()
|
||||||
const { runQueueAction } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const [menuOpen, setMenuOpen] = React.useState(false)
|
const [menuOpen, setMenuOpen] = React.useState(false)
|
||||||
const [hovered, setHovered] = React.useState(false)
|
const [hovered, setHovered] = React.useState(false)
|
||||||
const showActions = hovered || menuOpen
|
const showActions = hovered || menuOpen
|
||||||
@@ -71,6 +71,9 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
|||||||
|
|
||||||
async function handleCardAction(action: MediaContextAction) {
|
async function handleCardAction(action: MediaContextAction) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
void createStation(album.artist.id)
|
||||||
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
void openAddAlbumToPlaylist(album.id as Id<"albums">)
|
void openAddAlbumToPlaylist(album.id as Id<"albums">)
|
||||||
break
|
break
|
||||||
@@ -153,6 +156,7 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
|||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end" className="w-48">
|
<DropdownMenuContent align="end" className="w-48">
|
||||||
<MediaContextMenuItems
|
<MediaContextMenuItems
|
||||||
|
stationArtistId={album.artist.id}
|
||||||
selectedCount={1}
|
selectedCount={1}
|
||||||
onAction={(action) => void handleCardAction(action)}
|
onAction={(action) => void handleCardAction(action)}
|
||||||
favorited={isAlbumFavorite(album.id)}
|
favorited={isAlbumFavorite(album.id)}
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ function TrackRow({
|
|||||||
|
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
label={`More options for ${track.title}`}
|
label={`More options for ${track.title}`}
|
||||||
|
stationArtistId={artist.id}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
inSelectionRange={inRange}
|
inSelectionRange={inRange}
|
||||||
onOpenMenu={onPrepareContextMenu}
|
onOpenMenu={onPrepareContextMenu}
|
||||||
@@ -265,7 +266,7 @@ export function AlbumView({
|
|||||||
} = useFavorites()
|
} = useFavorites()
|
||||||
const { currentSong, playFromSong, playAlbum, playAlbumShuffled } =
|
const { currentSong, playFromSong, playAlbum, playAlbumShuffled } =
|
||||||
usePlayback()
|
usePlayback()
|
||||||
const { runQueueAction } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const albumSongIds = React.useMemo(
|
const albumSongIds = React.useMemo(
|
||||||
() => album.tracks.map((track) => track.id as Id<"songs">),
|
() => album.tracks.map((track) => track.id as Id<"songs">),
|
||||||
[album.tracks]
|
[album.tracks]
|
||||||
@@ -330,6 +331,9 @@ export function AlbumView({
|
|||||||
? [activeTrackId]
|
? [activeTrackId]
|
||||||
: []
|
: []
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
void createStation(album.artist.id)
|
||||||
|
break
|
||||||
case "favorite":
|
case "favorite":
|
||||||
void favoriteSongs(targetIds as Id<"songs">[])
|
void favoriteSongs(targetIds as Id<"songs">[])
|
||||||
break
|
break
|
||||||
@@ -348,6 +352,9 @@ export function AlbumView({
|
|||||||
const targetIds = album.tracks.map((track) => track.id as Id<"songs">)
|
const targetIds = album.tracks.map((track) => track.id as Id<"songs">)
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
void createStation(album.artist.id)
|
||||||
|
break
|
||||||
case "favorite":
|
case "favorite":
|
||||||
void toggleAlbumFavorite(album.id as Id<"albums">)
|
void toggleAlbumFavorite(album.id as Id<"albums">)
|
||||||
break
|
break
|
||||||
@@ -442,6 +449,7 @@ export function AlbumView({
|
|||||||
</Button>
|
</Button>
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
label="More album options"
|
label="More album options"
|
||||||
|
stationArtistId={album.artist.id}
|
||||||
selectedCount={album.tracks.length}
|
selectedCount={album.tracks.length}
|
||||||
onOpenMenu={() => {}}
|
onOpenMenu={() => {}}
|
||||||
onAction={handleAlbumMediaAction}
|
onAction={handleAlbumMediaAction}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export type MediaContextAction =
|
|||||||
| "play-next"
|
| "play-next"
|
||||||
| "play-last"
|
| "play-last"
|
||||||
| "shuffle"
|
| "shuffle"
|
||||||
|
| "create-station"
|
||||||
| "favorite"
|
| "favorite"
|
||||||
|
|
||||||
export type MediaContextNavigation = {
|
export type MediaContextNavigation = {
|
||||||
@@ -65,6 +66,7 @@ export function MediaContextMenuItems({
|
|||||||
playlistLabel = "Add to Playlist",
|
playlistLabel = "Add to Playlist",
|
||||||
showFavorite = true,
|
showFavorite = true,
|
||||||
favorited = false,
|
favorited = false,
|
||||||
|
stationArtistId,
|
||||||
navigation,
|
navigation,
|
||||||
share,
|
share,
|
||||||
}: {
|
}: {
|
||||||
@@ -73,6 +75,7 @@ export function MediaContextMenuItems({
|
|||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
showFavorite?: boolean
|
showFavorite?: boolean
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
|
stationArtistId?: string
|
||||||
navigation?: MediaContextNavigation
|
navigation?: MediaContextNavigation
|
||||||
share?: MediaShareContext
|
share?: MediaShareContext
|
||||||
}) {
|
}) {
|
||||||
@@ -122,6 +125,15 @@ export function MediaContextMenuItems({
|
|||||||
{actionLabel("Shuffle", selectedCount)}
|
{actionLabel("Shuffle", selectedCount)}
|
||||||
<Shuffle />
|
<Shuffle />
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
{stationArtistId ? (
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="justify-between"
|
||||||
|
onClick={() => onAction("create-station")}
|
||||||
|
>
|
||||||
|
Create Station
|
||||||
|
<Shuffle />
|
||||||
|
</DropdownMenuItem>
|
||||||
|
) : null}
|
||||||
{artist || album ? (
|
{artist || album ? (
|
||||||
<>
|
<>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
@@ -193,6 +205,7 @@ export function MediaContextMenu({
|
|||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite = true,
|
showFavorite = true,
|
||||||
favorited = false,
|
favorited = false,
|
||||||
|
stationArtistId,
|
||||||
navigation,
|
navigation,
|
||||||
share,
|
share,
|
||||||
inSelectionRange = false,
|
inSelectionRange = false,
|
||||||
@@ -210,6 +223,7 @@ export function MediaContextMenu({
|
|||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
showFavorite?: boolean
|
showFavorite?: boolean
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
|
stationArtistId?: string
|
||||||
navigation?: MediaContextNavigation
|
navigation?: MediaContextNavigation
|
||||||
share?: MediaShareContext
|
share?: MediaShareContext
|
||||||
inSelectionRange?: boolean
|
inSelectionRange?: boolean
|
||||||
@@ -251,6 +265,7 @@ export function MediaContextMenu({
|
|||||||
playlistLabel={playlistLabel}
|
playlistLabel={playlistLabel}
|
||||||
showFavorite={showFavorite}
|
showFavorite={showFavorite}
|
||||||
favorited={favorited}
|
favorited={favorited}
|
||||||
|
stationArtistId={stationArtistId}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
share={share}
|
share={share}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { stationArtistId } from "@/lib/station-artist"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import Image from "next/image"
|
import Image from "next/image"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
@@ -124,6 +125,7 @@ function PlaylistSongRow({
|
|||||||
selectionPosition,
|
selectionPosition,
|
||||||
isFavorite,
|
isFavorite,
|
||||||
selectedCount,
|
selectedCount,
|
||||||
|
stationArtist,
|
||||||
isDragging,
|
isDragging,
|
||||||
onSelect,
|
onSelect,
|
||||||
onPointerDown,
|
onPointerDown,
|
||||||
@@ -147,6 +149,7 @@ function PlaylistSongRow({
|
|||||||
selectionPosition: SelectionRangePosition
|
selectionPosition: SelectionRangePosition
|
||||||
isFavorite: boolean
|
isFavorite: boolean
|
||||||
selectedCount: number
|
selectedCount: number
|
||||||
|
stationArtist?: string
|
||||||
isDragging: boolean
|
isDragging: boolean
|
||||||
onSelect: (event: React.MouseEvent) => void
|
onSelect: (event: React.MouseEvent) => void
|
||||||
onPointerDown: (event: React.MouseEvent) => void
|
onPointerDown: (event: React.MouseEvent) => void
|
||||||
@@ -226,6 +229,7 @@ function PlaylistSongRow({
|
|||||||
|
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
label={`More options for ${song.title}`}
|
label={`More options for ${song.title}`}
|
||||||
|
stationArtistId={stationArtist}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
inSelectionRange={inRange}
|
inSelectionRange={inRange}
|
||||||
onOpenMenu={onPrepareContextMenu}
|
onOpenMenu={onPrepareContextMenu}
|
||||||
@@ -285,7 +289,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
playPlaylistShuffled,
|
playPlaylistShuffled,
|
||||||
playFromSong,
|
playFromSong,
|
||||||
} = usePlayback()
|
} = usePlayback()
|
||||||
const { runQueueAction } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const removeSongs = useMutation(api.playlists.removeSongsFromPlaylist)
|
const removeSongs = useMutation(api.playlists.removeSongsFromPlaylist)
|
||||||
const reorderSongs = useMutation(api.playlists.reorderPlaylistSongs)
|
const reorderSongs = useMutation(api.playlists.reorderPlaylistSongs)
|
||||||
const deletePlaylist = useMutation(api.playlists.deletePlaylist)
|
const deletePlaylist = useMutation(api.playlists.deletePlaylist)
|
||||||
@@ -324,6 +328,11 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
prepareContextMenu,
|
prepareContextMenu,
|
||||||
} = useTrackSelection(songs)
|
} = useTrackSelection(songs)
|
||||||
|
|
||||||
|
const selectedStationArtistId = React.useMemo(
|
||||||
|
() => stationArtistId(songs, selectedIds),
|
||||||
|
[songs, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
const selectionPositions = React.useMemo(
|
const selectionPositions = React.useMemo(
|
||||||
() => getSelectionRangePositions(songs.map((song) => song.id), selectedIds),
|
() => getSelectionRangePositions(songs.map((song) => song.id), selectedIds),
|
||||||
[songs, selectedIds]
|
[songs, selectedIds]
|
||||||
@@ -363,6 +372,11 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
const targetIds = resolveTargetIds(fallbackSongId)
|
const targetIds = resolveTargetIds(fallbackSongId)
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station": {
|
||||||
|
const artistId = stationArtistId(songs, new Set(targetIds))
|
||||||
|
if (artistId) void createStation(artistId)
|
||||||
|
break
|
||||||
|
}
|
||||||
case "favorite":
|
case "favorite":
|
||||||
void addFavoriteSongs(targetIds as Id<"songs">[])
|
void addFavoriteSongs(targetIds as Id<"songs">[])
|
||||||
break
|
break
|
||||||
@@ -637,6 +651,11 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
? selectedCount
|
? selectedCount
|
||||||
: 1
|
: 1
|
||||||
}
|
}
|
||||||
|
stationArtist={
|
||||||
|
isSelected(song.id)
|
||||||
|
? selectedStationArtistId
|
||||||
|
: song.artist.id
|
||||||
|
}
|
||||||
isDragging={dragIndex === index}
|
isDragging={dragIndex === index}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
onSelect={(event) => {
|
onSelect={(event) => {
|
||||||
|
|||||||
@@ -16,11 +16,14 @@ import { albumCoverUrl } from "@/lib/cover-urls"
|
|||||||
export function SearchSongItem({ song }: { song: BrowseSong }) {
|
export function SearchSongItem({ song }: { song: BrowseSong }) {
|
||||||
const { openAddToPlaylist } = useAddToPlaylist()
|
const { openAddToPlaylist } = useAddToPlaylist()
|
||||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||||
const { runQueueAction } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const songIds = [song.id as Id<"songs">]
|
const songIds = [song.id as Id<"songs">]
|
||||||
|
|
||||||
function handleAction(action: MediaContextAction) {
|
function handleAction(action: MediaContextAction) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station":
|
||||||
|
void createStation(song.artist.id)
|
||||||
|
break
|
||||||
case "playlist":
|
case "playlist":
|
||||||
openAddToPlaylist(songIds)
|
openAddToPlaylist(songIds)
|
||||||
break
|
break
|
||||||
@@ -64,6 +67,7 @@ export function SearchSongItem({ song }: { song: BrowseSong }) {
|
|||||||
|
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
label={`More options for ${song.title}`}
|
label={`More options for ${song.title}`}
|
||||||
|
stationArtistId={song.artist.id}
|
||||||
selectedCount={1}
|
selectedCount={1}
|
||||||
onOpenMenu={() => {}}
|
onOpenMenu={() => {}}
|
||||||
onAction={handleAction}
|
onAction={handleAction}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { stationArtistId } from "@/lib/station-artist"
|
||||||
import { useEffect, useMemo, useState, useRef, MouseEvent } from "react"
|
import { useEffect, useMemo, useState, useRef, MouseEvent } from "react"
|
||||||
import Image from "next/image"
|
import Image from "next/image"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
@@ -115,6 +116,7 @@ function SongRow({
|
|||||||
selectionPosition,
|
selectionPosition,
|
||||||
isFavorite,
|
isFavorite,
|
||||||
selectedCount,
|
selectedCount,
|
||||||
|
stationArtist,
|
||||||
onSelect,
|
onSelect,
|
||||||
onPointerDown,
|
onPointerDown,
|
||||||
onToggleFavorite,
|
onToggleFavorite,
|
||||||
@@ -127,6 +129,7 @@ function SongRow({
|
|||||||
selectionPosition: SelectionRangePosition
|
selectionPosition: SelectionRangePosition
|
||||||
isFavorite: boolean
|
isFavorite: boolean
|
||||||
selectedCount: number
|
selectedCount: number
|
||||||
|
stationArtist?: string
|
||||||
onSelect: (event: MouseEvent) => void
|
onSelect: (event: MouseEvent) => void
|
||||||
onPointerDown: (event: MouseEvent) => void
|
onPointerDown: (event: MouseEvent) => void
|
||||||
onToggleFavorite: () => void
|
onToggleFavorite: () => void
|
||||||
@@ -238,6 +241,7 @@ function SongRow({
|
|||||||
</span>
|
</span>
|
||||||
<MediaContextMenu
|
<MediaContextMenu
|
||||||
label={`More options for ${song.title}`}
|
label={`More options for ${song.title}`}
|
||||||
|
stationArtistId={stationArtist}
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
align="end"
|
align="end"
|
||||||
inSelectionRange={inRange}
|
inSelectionRange={inRange}
|
||||||
@@ -265,7 +269,7 @@ export function SongsView() {
|
|||||||
const { openAddToPlaylist } = useAddToPlaylist()
|
const { openAddToPlaylist } = useAddToPlaylist()
|
||||||
const { isSongFavorite, toggleSongFavorite, favoriteSongs } = useFavorites()
|
const { isSongFavorite, toggleSongFavorite, favoriteSongs } = useFavorites()
|
||||||
const { playFromLibrarySong } = usePlayback()
|
const { playFromLibrarySong } = usePlayback()
|
||||||
const { runQueueAction } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
const [sortKey, setSortKey] = useState<SortKey>("title")
|
const [sortKey, setSortKey] = useState<SortKey>("title")
|
||||||
const [sortDirection, setSortDirection] =
|
const [sortDirection, setSortDirection] =
|
||||||
useState<SortDirection>("asc")
|
useState<SortDirection>("asc")
|
||||||
@@ -313,6 +317,11 @@ export function SongsView() {
|
|||||||
clearSelection,
|
clearSelection,
|
||||||
} = useTrackSelection(songs)
|
} = useTrackSelection(songs)
|
||||||
|
|
||||||
|
const selectedStationArtistId = useMemo(
|
||||||
|
() => stationArtistId(songs, selectedIds),
|
||||||
|
[songs, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
const selectionPositions = useMemo(
|
const selectionPositions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
getSelectionRangePositions(
|
getSelectionRangePositions(
|
||||||
@@ -330,6 +339,11 @@ export function SongsView() {
|
|||||||
? [fallbackSongId]
|
? [fallbackSongId]
|
||||||
: []
|
: []
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "create-station": {
|
||||||
|
const artistId = stationArtistId(songs, new Set(targetIds))
|
||||||
|
if (artistId) void createStation(artistId)
|
||||||
|
break
|
||||||
|
}
|
||||||
case "favorite":
|
case "favorite":
|
||||||
void favoriteSongs(targetIds as Id<"songs">[])
|
void favoriteSongs(targetIds as Id<"songs">[])
|
||||||
break
|
break
|
||||||
@@ -449,6 +463,11 @@ export function SongsView() {
|
|||||||
isSelected={isSelected(song.id)}
|
isSelected={isSelected(song.id)}
|
||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
isFavorite={isSongFavorite(song.id)}
|
isFavorite={isSongFavorite(song.id)}
|
||||||
|
stationArtist={
|
||||||
|
isSelected(song.id)
|
||||||
|
? selectedStationArtistId
|
||||||
|
: song.artist.id
|
||||||
|
}
|
||||||
selectedCount={
|
selectedCount={
|
||||||
isSelected(song.id) && selectedCount > 0
|
isSelected(song.id) && selectedCount > 0
|
||||||
? selectedCount
|
? selectedCount
|
||||||
|
|||||||
@@ -23,14 +23,13 @@ function queueActionMessage(action: QueueMediaAction, count: number) {
|
|||||||
? `Queued ${count} songs to play last`
|
? `Queued ${count} songs to play last`
|
||||||
: "Queued to play last"
|
: "Queued to play last"
|
||||||
case "shuffle":
|
case "shuffle":
|
||||||
return count > 1
|
return count > 1 ? `Playing ${count} songs shuffled` : "Playing shuffled"
|
||||||
? `Playing ${count} songs shuffled`
|
|
||||||
: "Playing shuffled"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useQueueMediaActions() {
|
export function useQueueMediaActions() {
|
||||||
const { addToQueueNext, addToQueueLast, playShuffled } = usePlayback()
|
const { addToQueueNext, addToQueueLast, playShuffled, playArtistShuffled } =
|
||||||
|
usePlayback()
|
||||||
|
|
||||||
const runQueueAction = React.useCallback(
|
const runQueueAction = React.useCallback(
|
||||||
async (action: QueueMediaAction, songIds: Id<"songs">[]) => {
|
async (action: QueueMediaAction, songIds: Id<"songs">[]) => {
|
||||||
@@ -60,5 +59,18 @@ export function useQueueMediaActions() {
|
|||||||
[addToQueueNext, addToQueueLast, playShuffled]
|
[addToQueueNext, addToQueueLast, playShuffled]
|
||||||
)
|
)
|
||||||
|
|
||||||
return { runQueueAction }
|
const createStation = React.useCallback(
|
||||||
|
async (artistId: string) => {
|
||||||
|
try {
|
||||||
|
await playArtistShuffled(artistId as Id<"artists">)
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
error instanceof Error ? error.message : "Failed to create station"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[playArtistShuffled]
|
||||||
|
)
|
||||||
|
|
||||||
|
return { runQueueAction, createStation }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import assert from "node:assert/strict"
|
||||||
|
import test from "node:test"
|
||||||
|
|
||||||
|
import { stationArtistId } from "./station-artist.ts"
|
||||||
|
|
||||||
|
const songs = [
|
||||||
|
{ id: "song-a", artist: { id: "artist-a" } },
|
||||||
|
{ id: "song-b", artist: { id: "artist-a" } },
|
||||||
|
{ id: "song-c", artist: { id: "artist-b" } },
|
||||||
|
]
|
||||||
|
|
||||||
|
test("a single song or a selection sharing one artist can create a station", () => {
|
||||||
|
assert.equal(stationArtistId(songs, new Set(["song-c"])), "artist-b")
|
||||||
|
assert.equal(
|
||||||
|
stationArtistId(songs, new Set(["song-a", "song-b"])),
|
||||||
|
"artist-a"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("mixed artists cannot create a station", () => {
|
||||||
|
assert.equal(stationArtistId(songs, new Set(["song-a", "song-c"])), undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("empty or partially missing selections cannot create a station", () => {
|
||||||
|
assert.equal(stationArtistId(songs, new Set()), undefined)
|
||||||
|
assert.equal(
|
||||||
|
stationArtistId(songs, new Set(["song-a", "missing"])),
|
||||||
|
undefined
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
type ArtistItem = { id: string; artist: { id: string } }
|
||||||
|
|
||||||
|
/** Returns an artist only when every target item is present and shares it. */
|
||||||
|
export function stationArtistId(
|
||||||
|
items: ArtistItem[],
|
||||||
|
targetIds: ReadonlySet<string>
|
||||||
|
) {
|
||||||
|
const targets = items.filter((item) => targetIds.has(item.id))
|
||||||
|
const artistId = targets[0]?.artist.id
|
||||||
|
return targets.length === targetIds.size &&
|
||||||
|
targets.every((item) => item.artist.id === artistId)
|
||||||
|
? artistId
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
Reference in new issue
Block a user