feat: recently played & link metadata
This commit is contained in:
10 files changed
+313
-125
No files matched your search
@@ -7,7 +7,6 @@ import { AlbumView } from "@/components/album-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { BrowseAlbumDetail } from "@/convex/library"
|
||||
|
||||
export default function Page() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
@@ -33,5 +32,13 @@ export default function Page() {
|
||||
)
|
||||
}
|
||||
|
||||
return <AlbumView album={album} />
|
||||
return (
|
||||
<>
|
||||
<title>{`${album.title} - oTunes`}</title>
|
||||
<meta property="og:title" content={`${album.title}`} />
|
||||
<meta property="og:description" content={`${album.artist.name}`} />
|
||||
<meta property="og:image" content={`/api/album/${album.id}/cover`} />
|
||||
<AlbumView album={album} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -33,11 +33,17 @@ export default function Page() {
|
||||
}
|
||||
|
||||
return (
|
||||
<ArtistView
|
||||
artist={data.artist}
|
||||
albums={data.albums}
|
||||
recentlyAdded={data.recentlyAdded}
|
||||
recentlyPlayed={data.recentlyPlayed}
|
||||
/>
|
||||
<>
|
||||
<title>{`${data.artist.name} - oTunes`}</title>
|
||||
<meta property="og:title" content={`${data.artist.name}`} />
|
||||
{/*<meta property="og:description" content={`${playlist.owner.name}`} />*/}
|
||||
<meta property="og:image" content={`/api/artist/${data.artist.id}/cover`} />
|
||||
<ArtistView
|
||||
artist={data.artist}
|
||||
albums={data.albums}
|
||||
recentlyAdded={data.recentlyAdded}
|
||||
recentlyPlayed={data.recentlyPlayed}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
+8
-6
@@ -8,7 +8,7 @@ import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
const recentlyPlayed = useQuery(api.library.browseAlbums)
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
if (recentlyAdded === undefined || recentlyPlayed === undefined) {
|
||||
return (
|
||||
@@ -29,11 +29,13 @@ export default function Page() {
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="flex flex-col gap-10">
|
||||
<ContentCarousel
|
||||
title="Recently Played"
|
||||
href="/recently-played"
|
||||
content={recentlyPlayed.slice(0, 9)}
|
||||
/>
|
||||
{recentlyPlayed.length > 0 ? (
|
||||
<ContentCarousel
|
||||
title="Recently Played"
|
||||
href="/recently-played"
|
||||
content={recentlyPlayed.slice(0, 9)}
|
||||
/>
|
||||
) : null}
|
||||
<ContentCarousel
|
||||
title="Recently Added"
|
||||
href="/recently-added"
|
||||
|
||||
@@ -33,5 +33,13 @@ export default function Page() {
|
||||
)
|
||||
}
|
||||
|
||||
return <PlaylistView playlist={playlist} />
|
||||
return (
|
||||
<>
|
||||
<title>{`${playlist.title} - oTunes`}</title>
|
||||
<meta property="og:title" content={`${playlist.title}`} />
|
||||
<meta property="og:description" content={`${playlist.owner.name}`} />
|
||||
<meta property="og:image" content={`/api/playlist/${playlist.id}/cover`} />
|
||||
<PlaylistView playlist={playlist} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -4,10 +4,23 @@ import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { PlaylistCard } from "@/components/playlist-card"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { BrowseAlbum, PlaylistSummary } from "@/convex/library"
|
||||
|
||||
function RecentlyPlayedCard({
|
||||
item,
|
||||
}: {
|
||||
item: BrowseAlbum | PlaylistSummary
|
||||
}) {
|
||||
if ("owner" in item) {
|
||||
return <PlaylistCard playlist={item} />
|
||||
}
|
||||
return <AlbumCard album={item} />
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed)
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
@@ -15,13 +28,19 @@ export default function Page() {
|
||||
<h1 className="text-lg font-semibold">Recently Played</h1>
|
||||
</header>
|
||||
|
||||
{albums === undefined ? (
|
||||
{recentlyPlayed === undefined ? (
|
||||
<LibraryLoading />
|
||||
) : recentlyPlayed.length === 0 ? (
|
||||
<div className="flex flex-1 items-center justify-center p-6 pb-28">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Your recently played albums and playlists will appear here.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
{recentlyPlayed.map((item) => (
|
||||
<RecentlyPlayedCard key={item.id} item={item} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+114
-94
@@ -69,7 +69,9 @@ function ArtistListItem({
|
||||
)}
|
||||
>
|
||||
<ArtistAvatar artist={artist} />
|
||||
<span className="min-w-0 flex-1 truncate font-medium">{artist.name}</span>
|
||||
<span className="min-w-0 flex-1 truncate font-medium">
|
||||
{artist.name}
|
||||
</span>
|
||||
</button>
|
||||
<MediaContextMenu
|
||||
label={`More options for ${artist.name}`}
|
||||
@@ -99,10 +101,7 @@ export function ArtistsView({
|
||||
)
|
||||
|
||||
const selectedId = React.useMemo(() => {
|
||||
if (
|
||||
artistId &&
|
||||
sortedArtists.some((artist) => artist.id === artistId)
|
||||
) {
|
||||
if (artistId && sortedArtists.some((artist) => artist.id === artistId)) {
|
||||
return artistId
|
||||
}
|
||||
return sortedArtists[0]?.id ?? ""
|
||||
@@ -151,98 +150,119 @@ export function ArtistsView({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1">
|
||||
<ScrollArea className="w-72 shrink-0 border-r">
|
||||
<div className="w-full pb-28">
|
||||
{sortedArtists.map((artist) => (
|
||||
<ArtistListItem
|
||||
key={artist.id}
|
||||
artist={artist}
|
||||
albumCount={albumCountByArtistId.get(artist.id) ?? 0}
|
||||
isSelected={artist.id === selectedId}
|
||||
isFavorite={isArtistFavorite(artist.id)}
|
||||
onSelect={() => router.push(`/library/artists/${artist.id}`)}
|
||||
onMediaAction={(action) =>
|
||||
void handleMediaAction(artist.id, action)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
<>
|
||||
<title>{`${selectedArtist && artistId ? `${selectedArtist.name} - oTunes` : "oTunes"}`}</title>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={`${selectedArtist && artistId ? selectedArtist?.name : "oTunes"}`}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={`${selectedArtist && artistId ? "oTunes" : null}`}
|
||||
/>
|
||||
<meta
|
||||
property="og:image"
|
||||
content={`${selectedArtist && artistId ? "/api/artist/${selectedArtist?.id}/cover" : null}`}
|
||||
/>
|
||||
<div className="flex min-h-0 flex-1">
|
||||
<ScrollArea className="w-72 shrink-0 border-r">
|
||||
<div className="w-full pb-28">
|
||||
{sortedArtists.map((artist) => (
|
||||
<ArtistListItem
|
||||
key={artist.id}
|
||||
artist={artist}
|
||||
albumCount={albumCountByArtistId.get(artist.id) ?? 0}
|
||||
isSelected={artist.id === selectedId}
|
||||
isFavorite={isArtistFavorite(artist.id)}
|
||||
onSelect={() => router.push(`/library/artists/${artist.id}`)}
|
||||
onMediaAction={(action) =>
|
||||
void handleMediaAction(artist.id, action)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<ScrollArea className="min-w-0 flex-1">
|
||||
{selectedArtist ? (
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center justify-between gap-4 border-b px-6 py-4">
|
||||
<Link
|
||||
href={`/artist/${selectedArtist.id}`}
|
||||
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight hover:underline"
|
||||
>
|
||||
<span className="min-w-0 truncate">{selectedArtist.name}</span>
|
||||
<ChevronRightIcon className="size-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
<ScrollArea className="min-w-0 flex-1">
|
||||
{selectedArtist ? (
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center justify-between gap-4 border-b px-6 py-4">
|
||||
<Link
|
||||
href={`/artist/${selectedArtist.id}`}
|
||||
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight hover:underline"
|
||||
>
|
||||
<span className="min-w-0 truncate">
|
||||
{selectedArtist.name}
|
||||
</span>
|
||||
<ChevronRightIcon className="size-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<Button
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Play"
|
||||
onClick={() =>
|
||||
void playArtist(selectedArtist.id as Id<"artists">)
|
||||
}
|
||||
>
|
||||
<Play className="fill-current" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Shuffle"
|
||||
onClick={() =>
|
||||
void playArtistShuffled(selectedArtist.id as Id<"artists">)
|
||||
}
|
||||
>
|
||||
<Shuffle />
|
||||
</Button>
|
||||
<FavoriteMediaButton
|
||||
isFavorite={isArtistFavorite(selectedArtist.id)}
|
||||
onToggle={() =>
|
||||
void toggleArtistFavorite(selectedArtist.id as Id<"artists">)
|
||||
}
|
||||
favoritedLabel={`Remove ${selectedArtist.name} from favorites`}
|
||||
unfavoritedLabel={`Favorite ${selectedArtist.name}`}
|
||||
/>
|
||||
<MediaContextMenu
|
||||
label={`More options for ${selectedArtist.name}`}
|
||||
selectedCount={artistAlbums.length}
|
||||
onOpenMenu={() => {}}
|
||||
onAction={(action) =>
|
||||
void handleMediaAction(selectedArtist.id, action)
|
||||
}
|
||||
favorited={isArtistFavorite(selectedArtist.id)}
|
||||
trackRowTrigger={false}
|
||||
triggerVariant="secondary"
|
||||
triggerClassName="rounded-full"
|
||||
/>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<Button
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Play"
|
||||
onClick={() =>
|
||||
void playArtist(selectedArtist.id as Id<"artists">)
|
||||
}
|
||||
>
|
||||
<Play className="fill-current" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Shuffle"
|
||||
onClick={() =>
|
||||
void playArtistShuffled(
|
||||
selectedArtist.id as Id<"artists">
|
||||
)
|
||||
}
|
||||
>
|
||||
<Shuffle />
|
||||
</Button>
|
||||
<FavoriteMediaButton
|
||||
isFavorite={isArtistFavorite(selectedArtist.id)}
|
||||
onToggle={() =>
|
||||
void toggleArtistFavorite(
|
||||
selectedArtist.id as Id<"artists">
|
||||
)
|
||||
}
|
||||
favoritedLabel={`Remove ${selectedArtist.name} from favorites`}
|
||||
unfavoritedLabel={`Favorite ${selectedArtist.name}`}
|
||||
/>
|
||||
<MediaContextMenu
|
||||
label={`More options for ${selectedArtist.name}`}
|
||||
selectedCount={artistAlbums.length}
|
||||
onOpenMenu={() => {}}
|
||||
onAction={(action) =>
|
||||
void handleMediaAction(selectedArtist.id, action)
|
||||
}
|
||||
favorited={isArtistFavorite(selectedArtist.id)}
|
||||
trackRowTrigger={false}
|
||||
triggerVariant="secondary"
|
||||
triggerClassName="rounded-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6">
|
||||
{artistAlbums.length > 0 ? (
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{artistAlbums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No albums for this artist.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6">
|
||||
{artistAlbums.length > 0 ? (
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{artistAlbums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No albums for this artist.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
) : null}
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -971,9 +971,10 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
||||
playlistId,
|
||||
})
|
||||
await playInOrder(songIds)
|
||||
await playInOrderMutation({ songIds, playlistId })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[convex, playInOrder]
|
||||
[convex, playInOrderMutation]
|
||||
)
|
||||
|
||||
const playPlaylistShuffled = useCallback(
|
||||
@@ -981,9 +982,10 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
||||
playlistId,
|
||||
})
|
||||
await playShuffled(songIds)
|
||||
await playShuffledMutation({ songIds, playlistId })
|
||||
setIsPlaying(true)
|
||||
},
|
||||
[convex, playShuffled]
|
||||
[convex, playShuffledMutation]
|
||||
)
|
||||
|
||||
const toggleQueueOpen = useCallback(() => {
|
||||
|
||||
@@ -291,8 +291,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
} = useFavorites()
|
||||
const {
|
||||
currentSong,
|
||||
playInOrder,
|
||||
playShuffled,
|
||||
playPlaylist,
|
||||
playPlaylistShuffled,
|
||||
playFromSong,
|
||||
} = usePlayback()
|
||||
const { runQueueAction } = useQueueMediaActions()
|
||||
@@ -563,7 +563,9 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Shuffle playlist"
|
||||
onClick={() => void playShuffled(playlistSongIds)}
|
||||
onClick={() =>
|
||||
void playPlaylistShuffled(playlist.id as Id<"playlists">)
|
||||
}
|
||||
disabled={playlistSongIds.length === 0}
|
||||
>
|
||||
<Shuffle />
|
||||
@@ -571,7 +573,9 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
<Button
|
||||
className="h-10 gap-2 rounded-full bg-foreground px-6 text-background hover:bg-foreground/90"
|
||||
aria-label={`Play ${playlist.title}`}
|
||||
onClick={() => void playInOrder(playlistSongIds)}
|
||||
onClick={() =>
|
||||
void playPlaylist(playlist.id as Id<"playlists">)
|
||||
}
|
||||
disabled={playlistSongIds.length === 0}
|
||||
>
|
||||
<Play className="fill-current" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { paginationOptsValidator } from "convex/server"
|
||||
import { getAuthUserId } from "@convex-dev/auth/server"
|
||||
import { mutation, query } from "./_generated/server"
|
||||
import { v } from "convex/values"
|
||||
import type { Doc, Id } from "./_generated/dataModel"
|
||||
@@ -687,6 +688,53 @@ export const browseRecentlyAdded = query({
|
||||
},
|
||||
})
|
||||
|
||||
export const browseRecentlyPlayed = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const userId = await getAuthUserId(ctx)
|
||||
if (userId === null) {
|
||||
return []
|
||||
}
|
||||
|
||||
const user = await ctx.db.get(userId)
|
||||
if (!user) {
|
||||
return []
|
||||
}
|
||||
|
||||
const recentlyPlayed = user.recentlyPlayed ?? []
|
||||
if (recentlyPlayed.length === 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const artistMap = await loadArtistMap(ctx)
|
||||
const items: (BrowseAlbum | PlaylistSummary)[] = []
|
||||
|
||||
for (const id of recentlyPlayed) {
|
||||
const album = await ctx.db.get("albums", id as Id<"albums">)
|
||||
if (album) {
|
||||
const artist = artistMap.get(album.artist)
|
||||
if (artist) {
|
||||
items.push(toBrowseAlbum(album, artist))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const playlist = await ctx.db.get("playlists", id as Id<"playlists">)
|
||||
if (playlist) {
|
||||
const owner = await ctx.db.get(playlist.owner)
|
||||
items.push({
|
||||
id: playlist._id,
|
||||
title: playlist.name,
|
||||
owner: owner?.name ?? "Unknown",
|
||||
cover: playlist.cover,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
},
|
||||
})
|
||||
|
||||
export const getArtists = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
|
||||
+76
-4
@@ -16,6 +16,68 @@ export type QueueSong = BrowseSong & { queueIndex: number }
|
||||
export type HistorySong = BrowseSong & { historyIndex: number }
|
||||
|
||||
const MAX_QUEUE_HISTORY = 30
|
||||
const MAX_RECENTLY_PLAYED = 30
|
||||
|
||||
type RecentlyPlayedItem = Id<"albums"> | Id<"playlists">
|
||||
|
||||
function pushRecentlyPlayed(
|
||||
history: RecentlyPlayedItem[],
|
||||
item: RecentlyPlayedItem
|
||||
): RecentlyPlayedItem[] {
|
||||
const next = [item, ...history.filter((id) => id !== item)]
|
||||
if (next.length <= MAX_RECENTLY_PLAYED) {
|
||||
return next
|
||||
}
|
||||
return next.slice(0, MAX_RECENTLY_PLAYED)
|
||||
}
|
||||
|
||||
async function recordRecentlyPlayed(
|
||||
ctx: MutationCtx,
|
||||
userId: Id<"users">,
|
||||
item: RecentlyPlayedItem
|
||||
) {
|
||||
const user = await ctx.db.get(userId)
|
||||
if (!user) {
|
||||
return
|
||||
}
|
||||
|
||||
await ctx.db.patch(userId, {
|
||||
recentlyPlayed: pushRecentlyPlayed(user.recentlyPlayed ?? [], item),
|
||||
})
|
||||
}
|
||||
|
||||
async function recordRecentlyPlayedFromSong(
|
||||
ctx: MutationCtx,
|
||||
userId: Id<"users">,
|
||||
songId: Id<"songs">
|
||||
) {
|
||||
const song = await ctx.db.get(songId)
|
||||
if (!song) {
|
||||
return
|
||||
}
|
||||
|
||||
await recordRecentlyPlayed(ctx, userId, song.album)
|
||||
}
|
||||
|
||||
async function recordPlaybackStart(
|
||||
ctx: MutationCtx,
|
||||
userId: Id<"users">,
|
||||
options: {
|
||||
songIds: Id<"songs">[]
|
||||
playlistId?: Id<"playlists">
|
||||
}
|
||||
) {
|
||||
if (options.songIds.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (options.playlistId) {
|
||||
await recordRecentlyPlayed(ctx, userId, options.playlistId)
|
||||
return
|
||||
}
|
||||
|
||||
await recordRecentlyPlayedFromSong(ctx, userId, options.songIds[0])
|
||||
}
|
||||
|
||||
function shuffleArray<T>(items: T[]): T[] {
|
||||
const next = [...items]
|
||||
@@ -176,8 +238,11 @@ export const getQueuePaginated = query({
|
||||
})
|
||||
|
||||
export const playInOrder = mutation({
|
||||
args: { songIds: v.array(v.id("songs")) },
|
||||
handler: async (ctx, { songIds }) => {
|
||||
args: {
|
||||
songIds: v.array(v.id("songs")),
|
||||
playlistId: v.optional(v.id("playlists")),
|
||||
},
|
||||
handler: async (ctx, { songIds, playlistId }) => {
|
||||
const userId = await requireAuth(ctx)
|
||||
const queue = uniqueSongIds(songIds)
|
||||
await setQueueState(ctx, userId, {
|
||||
@@ -185,18 +250,23 @@ export const playInOrder = mutation({
|
||||
shuffleEnabled: false,
|
||||
resetHistory: true,
|
||||
})
|
||||
await recordPlaybackStart(ctx, userId, { songIds: queue, playlistId })
|
||||
},
|
||||
})
|
||||
|
||||
export const playShuffled = mutation({
|
||||
args: { songIds: v.array(v.id("songs")) },
|
||||
handler: async (ctx, { songIds }) => {
|
||||
args: {
|
||||
songIds: v.array(v.id("songs")),
|
||||
playlistId: v.optional(v.id("playlists")),
|
||||
},
|
||||
handler: async (ctx, { songIds, playlistId }) => {
|
||||
const userId = await requireAuth(ctx)
|
||||
const queue = shuffleArray(uniqueSongIds(songIds))
|
||||
await setQueueState(ctx, userId, {
|
||||
songQueue: queue,
|
||||
resetHistory: true,
|
||||
})
|
||||
await recordPlaybackStart(ctx, userId, { songIds: queue, playlistId })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -277,6 +347,7 @@ export const playFromSong = mutation({
|
||||
songQueue: [songId, ...queueRest],
|
||||
resetHistory: true,
|
||||
})
|
||||
await recordRecentlyPlayedFromSong(ctx, userId, songId)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -302,6 +373,7 @@ export const playFromLibrarySong = mutation({
|
||||
songQueue: [songId, ...queueRest],
|
||||
resetHistory: true,
|
||||
})
|
||||
await recordRecentlyPlayedFromSong(ctx, userId, songId)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user