Compare commits
1
Commits
No files matched your search
@@ -9,13 +9,15 @@
|
||||
"APP_VARIANT": "development"
|
||||
},
|
||||
"developmentClient": true,
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"preview": {
|
||||
"env": {
|
||||
"APP_VARIANT": "preview"
|
||||
},
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"production": {
|
||||
"env": {
|
||||
|
||||
@@ -114,7 +114,6 @@ export function AlbumView({
|
||||
}) {
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
isAlbumFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleAlbumFavorite,
|
||||
@@ -155,7 +154,6 @@ export function AlbumView({
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -415,7 +413,6 @@ export function AlbumView({
|
||||
isFavorite={isSongFavorite(track.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={album.artist.id}
|
||||
selectionFavorited={selectionFavorited}
|
||||
isNowPlaying={currentSongId === track.id}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
|
||||
@@ -37,8 +37,7 @@ type FavoritesContextValue = {
|
||||
) => Promise<boolean>
|
||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||
/** True when `songIds` is non-empty and every song is favorited. */
|
||||
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
||||
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
||||
}
|
||||
|
||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||
@@ -131,16 +130,26 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
[songIds, favoriteSong, unfavoriteSong]
|
||||
)
|
||||
|
||||
const areSongsFavorite = React.useCallback(
|
||||
(ids: Iterable<string>) => {
|
||||
let any = false
|
||||
for (const id of ids) {
|
||||
if (!songIds.has(id)) return false
|
||||
any = true
|
||||
const favoriteSongs = React.useCallback(
|
||||
async (ids: Id<"songs">[]) => {
|
||||
const unique = [...new Set(ids)]
|
||||
if (unique.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await favoriteSongsMutation({ songIds: unique })
|
||||
toast.success(
|
||||
unique.length > 1
|
||||
? `Favorited ${unique.length} songs`
|
||||
: "Added to favorites"
|
||||
)
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : "Failed to update favorites"
|
||||
)
|
||||
}
|
||||
return any
|
||||
},
|
||||
[songIds]
|
||||
[favoriteSongsMutation]
|
||||
)
|
||||
|
||||
const toggleSongsFavorite = React.useCallback(
|
||||
@@ -223,7 +232,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
}),
|
||||
[
|
||||
isSongFavorite,
|
||||
@@ -233,7 +242,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ export function OtherDownloadsView() {
|
||||
[songs]
|
||||
)
|
||||
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||
const {
|
||||
selectedIds,
|
||||
@@ -63,7 +62,6 @@ export function OtherDownloadsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
@@ -142,7 +140,6 @@ export function OtherDownloadsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -74,12 +74,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
currentUser === undefined
|
||||
? playlist.isOwner
|
||||
: currentUser?._id === playlist.owner.id
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleSongsFavorite,
|
||||
} = useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
|
||||
useFavorites()
|
||||
const currentSongId = useCurrentSongId()
|
||||
const {
|
||||
playInOrder,
|
||||
@@ -147,7 +143,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -470,7 +465,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
onAction={handlePlaylistMediaAction}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
showFavorite={!isFavorites}
|
||||
favorited={areSongsFavorite(playlistSongIds)}
|
||||
downloaded={playlistDownloaded}
|
||||
trackRowTrigger={false}
|
||||
triggerVariant="secondary"
|
||||
@@ -528,7 +522,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
selectionPosition={selectionPositions[index]}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
downloadCollection={downloadRef}
|
||||
showFavoriteInMenu={!isFavorites}
|
||||
|
||||
@@ -3,16 +3,12 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { useFavorites } from "@/components/favorites-provider"
|
||||
import {
|
||||
MediaContextMenuArea,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import type { MediaContextAction } from "@/components/media-context-menu"
|
||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
import { useSongDownloadState } from "@/hooks/use-downloads"
|
||||
import { useMediaActions } from "@/hooks/use-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
@@ -54,51 +50,6 @@ function toSelectableQueue(
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the song's right-click menu over `children`, for the queue rows that
|
||||
* stand alone (history and the current song) rather than in the selection.
|
||||
*/
|
||||
function SongMenuArea({
|
||||
song,
|
||||
children,
|
||||
}: {
|
||||
song: BrowseSong
|
||||
children: React.ReactElement
|
||||
}) {
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { runSongsAction } = useMediaActions()
|
||||
const downloaded = useSongDownloadState(song.id) === "here"
|
||||
|
||||
function handleAction(action: MediaContextAction) {
|
||||
if (action === "favorite") {
|
||||
void toggleSongFavorite(song.id)
|
||||
return
|
||||
}
|
||||
runSongsAction(action, [song.id], song.artist.id)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaContextMenuArea
|
||||
menu={{
|
||||
label: `More options for ${song.title}`,
|
||||
stationArtistId: song.artist.id,
|
||||
selectedCount: 1,
|
||||
onOpenMenu: () => {},
|
||||
onAction: handleAction,
|
||||
favorited: isSongFavorite(song.id),
|
||||
downloaded,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
},
|
||||
share: { type: "song", albumId: song.album.id, songId: song.id },
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</MediaContextMenuArea>
|
||||
)
|
||||
}
|
||||
|
||||
/** A played song; clicking it plays it again from that point in history. */
|
||||
function HistorySongRow({
|
||||
song,
|
||||
@@ -114,27 +65,25 @@ function HistorySongRow({
|
||||
}
|
||||
|
||||
return (
|
||||
<SongMenuArea song={song}>
|
||||
<li
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
|
||||
onClick={() => onPlay(historyIndex)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault()
|
||||
onPlay(historyIndex)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TrackCover
|
||||
albumId={song.album.id}
|
||||
alt={song.album.title}
|
||||
inRange={false}
|
||||
/>
|
||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||
</li>
|
||||
</SongMenuArea>
|
||||
<li
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
||||
onClick={() => onPlay(historyIndex)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault()
|
||||
onPlay(historyIndex)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TrackCover
|
||||
albumId={song.album.id}
|
||||
alt={song.album.title}
|
||||
inRange={false}
|
||||
/>
|
||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -244,7 +193,7 @@ export function QueuePanel() {
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(selectionItems)
|
||||
const { isSongFavorite, areSongsFavorite } = useFavorites()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { runSongsAction } = useMediaActions()
|
||||
|
||||
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||
@@ -268,11 +217,6 @@ export function QueuePanel() {
|
||||
),
|
||||
[selectableQueue, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(
|
||||
selectableQueue.flatMap((item) =>
|
||||
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
|
||||
)
|
||||
)
|
||||
|
||||
const handleMediaAction = React.useCallback(
|
||||
(action: MediaContextAction, selectionId: string) => {
|
||||
@@ -410,25 +354,25 @@ export function QueuePanel() {
|
||||
|
||||
{/* Fills the viewport so the current song can always scroll to the top. */}
|
||||
<div ref={currentRef} className="flex min-h-full flex-col">
|
||||
{currentSong ? (
|
||||
<SongMenuArea song={currentSong}>
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<TrackCover
|
||||
albumId={currentSong.album.id}
|
||||
alt={currentSong.album.title}
|
||||
inRange={false}
|
||||
size="lg"
|
||||
/>
|
||||
<PlaybackSongMeta
|
||||
song={currentSong}
|
||||
align="start"
|
||||
showAlbum={false}
|
||||
/>
|
||||
</div>
|
||||
</SongMenuArea>
|
||||
) : currentQueueSongId ? (
|
||||
<div className="px-4 py-3">
|
||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||
{currentQueueSongId ? (
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
{currentSong ? (
|
||||
<>
|
||||
<TrackCover
|
||||
albumId={currentSong.album.id}
|
||||
alt={currentSong.album.title}
|
||||
inRange={false}
|
||||
size="lg"
|
||||
/>
|
||||
<PlaybackSongMeta
|
||||
song={currentSong}
|
||||
align="start"
|
||||
showAlbum={false}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -458,7 +402,6 @@ export function QueuePanel() {
|
||||
isFavorite={isSongFavorite(item.song.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
removeLabel="Remove from Queue"
|
||||
selectionPosition={selectionPositions[index]}
|
||||
isDragging={draggingIndices.has(index)}
|
||||
|
||||
@@ -47,8 +47,7 @@ const SONGS_PAGE_SIZE = 50
|
||||
const estimateSongRowSize = () => 56
|
||||
|
||||
export function SongsView() {
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromLibrarySong } = usePlaybackActions()
|
||||
const [sortKey, setSortKey] = useState<SortKey>("title")
|
||||
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
|
||||
@@ -99,7 +98,6 @@ export function SongsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
@@ -224,7 +222,6 @@ export function SongsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -68,8 +68,6 @@ export type TrackRowProps = {
|
||||
selectedCount?: number
|
||||
/** Station artist for the selection when this row is selected. */
|
||||
selectionStationArtistId?: string
|
||||
/** Whether every selected song is favorited, when this row is selected. */
|
||||
selectionFavorited?: boolean
|
||||
playlistLabel?: string
|
||||
showFavoriteInMenu?: boolean
|
||||
/** Adds a destructive menu item calling `onRemove`. */
|
||||
@@ -270,7 +268,6 @@ function TrackRowComponent({
|
||||
isDragging = false,
|
||||
selectedCount = 0,
|
||||
selectionStationArtistId,
|
||||
selectionFavorited,
|
||||
playlistLabel,
|
||||
showFavoriteInMenu = true,
|
||||
removeLabel,
|
||||
@@ -348,10 +345,7 @@ function TrackRowComponent({
|
||||
onAction: (action) => onMediaAction(action, rowId),
|
||||
playlistLabel,
|
||||
showFavorite: showFavoriteInMenu,
|
||||
favorited:
|
||||
inRange && selectedCount > 0
|
||||
? (selectionFavorited ?? isFavorite)
|
||||
: isFavorite,
|
||||
favorited: isFavorite,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
|
||||
@@ -26,8 +26,7 @@ function songsTitle(songIds: readonly string[]) {
|
||||
|
||||
export function useMediaActions() {
|
||||
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
||||
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
|
||||
useFavorites()
|
||||
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
|
||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||
const convex = useConvex()
|
||||
const cacheScope = useCacheScope()
|
||||
@@ -45,8 +44,7 @@ export function useMediaActions() {
|
||||
if (stationArtist) void createStation(stationArtist)
|
||||
break
|
||||
case "favorite":
|
||||
// Unfavorite only when every song already is, matching the menu label.
|
||||
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
|
||||
void favoriteSongs(songIds)
|
||||
break
|
||||
case "playlist":
|
||||
openAddToPlaylist(songIds)
|
||||
@@ -75,8 +73,7 @@ export function useMediaActions() {
|
||||
},
|
||||
[
|
||||
createStation,
|
||||
areSongsFavorite,
|
||||
toggleSongsFavorite,
|
||||
favoriteSongs,
|
||||
openAddToPlaylist,
|
||||
runQueueAction,
|
||||
requestDownload,
|
||||
|
||||
Reference in new issue
Block a user