Compare commits
13
Commits
No files matched your search
+6
-1
@@ -41,4 +41,9 @@ apps/web/next-env.d.ts
|
|||||||
/.convex
|
/.convex
|
||||||
/.cursor
|
/.cursor
|
||||||
/database
|
/database
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
|
|
||||||
|
**/credentials.json
|
||||||
|
**/credentials/
|
||||||
|
**/*.ipa
|
||||||
|
**/*.apk
|
||||||
+6
-1
@@ -1,7 +1,11 @@
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||||
import { useStackScreenOptions, tabStackScreenTitles } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
import { tabletSections, TabletSectionContext } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||||
@@ -14,6 +18,7 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
|
|||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...options,
|
...options,
|
||||||
|
...inlineTitleOptions,
|
||||||
title:
|
title:
|
||||||
route.name === "index"
|
route.name === "index"
|
||||||
? section?.title
|
? section?.title
|
||||||
|
|||||||
@@ -193,6 +193,14 @@ function TabsContent() {
|
|||||||
<NativeTabs.Trigger.Icon sf="music.note" />
|
<NativeTabs.Trigger.Icon sf="music.note" />
|
||||||
<NativeTabs.Trigger.Label>Songs</NativeTabs.Trigger.Label>
|
<NativeTabs.Trigger.Label>Songs</NativeTabs.Trigger.Label>
|
||||||
</NativeTabs.Trigger>
|
</NativeTabs.Trigger>
|
||||||
|
<NativeTabs.Trigger
|
||||||
|
name="(downloads)"
|
||||||
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
||||||
|
disableTransparentOnScrollEdge
|
||||||
|
>
|
||||||
|
<NativeTabs.Trigger.Icon sf="arrow.down.circle" />
|
||||||
|
<NativeTabs.Trigger.Label>Downloads</NativeTabs.Trigger.Label>
|
||||||
|
</NativeTabs.Trigger>
|
||||||
<NativeTabs.Trigger
|
<NativeTabs.Trigger
|
||||||
name="(playlists)"
|
name="(playlists)"
|
||||||
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
||||||
@@ -217,14 +225,6 @@ function TabsContent() {
|
|||||||
<NativeTabs.Trigger.Icon sf="clock" />
|
<NativeTabs.Trigger.Icon sf="clock" />
|
||||||
<NativeTabs.Trigger.Label>Recently Played</NativeTabs.Trigger.Label>
|
<NativeTabs.Trigger.Label>Recently Played</NativeTabs.Trigger.Label>
|
||||||
</NativeTabs.Trigger>
|
</NativeTabs.Trigger>
|
||||||
<NativeTabs.Trigger
|
|
||||||
name="(downloads)"
|
|
||||||
hidden={!(Platform.OS === "ios" && Platform.isPad)}
|
|
||||||
disableTransparentOnScrollEdge
|
|
||||||
>
|
|
||||||
<NativeTabs.Trigger.Icon sf="arrow.down.circle" />
|
|
||||||
<NativeTabs.Trigger.Label>Downloads</NativeTabs.Trigger.Label>
|
|
||||||
</NativeTabs.Trigger>
|
|
||||||
</NativeTabs>
|
</NativeTabs>
|
||||||
{!keyboardVisible ? <AndroidMiniPlayer /> : null}
|
{!keyboardVisible ? <AndroidMiniPlayer /> : null}
|
||||||
{tabletLayout ? <TabletMiniPlayer /> : null}
|
{tabletLayout ? <TabletMiniPlayer /> : null}
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -16,6 +20,7 @@ export default function HomeLayout() {
|
|||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||||
headerRight:
|
headerRight:
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import {
|
|||||||
} from "@/components/collection-list"
|
} from "@/components/collection-list"
|
||||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||||
import {
|
import {
|
||||||
DownloadHeaderButton,
|
CollectionDownloadButton,
|
||||||
DownloadedQuality,
|
DownloadedQuality,
|
||||||
} from "@/components/download-header-button"
|
} from "@/components/collection-download-button"
|
||||||
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
||||||
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
||||||
import {
|
import {
|
||||||
@@ -81,8 +81,7 @@ export default function AlbumScreen() {
|
|||||||
const playOrigin = fromDownloads
|
const playOrigin = fromDownloads
|
||||||
? downloadsQueueOrigin(`album:${id}`)
|
? downloadsQueueOrigin(`album:${id}`)
|
||||||
: `album:${id}`
|
: `album:${id}`
|
||||||
const { isAlbumFavorite, toggleAlbumFavorite, isSongFavorite } =
|
const { isSongFavorite } = useFavorites()
|
||||||
useFavorites()
|
|
||||||
const {
|
const {
|
||||||
handleAlbumDetailAction,
|
handleAlbumDetailAction,
|
||||||
handleAlbumTrackAction,
|
handleAlbumTrackAction,
|
||||||
@@ -205,7 +204,6 @@ export default function AlbumScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const metadata = formatMetadata(album.genre, album.year)
|
const metadata = formatMetadata(album.genre, album.year)
|
||||||
const favorited = isAlbumFavorite(album.id)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -226,41 +224,35 @@ export default function AlbumScreen() {
|
|||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<View style={styles.headerActions}>
|
<MediaActionMenu
|
||||||
<DownloadHeaderButton
|
stationArtistId={album.artist.id}
|
||||||
target={downloadTarget}
|
selectedCount={album.tracks.length}
|
||||||
color={colors.foreground}
|
favorited={isAlbumFav(album.id)}
|
||||||
/>
|
downloaded={albumDownloaded}
|
||||||
<MediaActionMenu
|
share={{ type: "album", albumId: album.id, title: album.title }}
|
||||||
stationArtistId={album.artist.id}
|
onAction={(action) => {
|
||||||
selectedCount={album.tracks.length}
|
if (action === "download") {
|
||||||
favorited={isAlbumFav(album.id)}
|
void requestDownload(downloadTarget)
|
||||||
downloaded={albumDownloaded}
|
} else if (action === "remove-download") {
|
||||||
share={{ type: "album", albumId: album.id, title: album.title }}
|
void removeDownload(downloadTarget)
|
||||||
onAction={(action) => {
|
} else {
|
||||||
if (action === "download") {
|
void handleAlbumDetailAction(
|
||||||
void requestDownload(downloadTarget)
|
album.id as Id<"albums">,
|
||||||
} else if (action === "remove-download") {
|
songIds,
|
||||||
void removeDownload(downloadTarget)
|
action,
|
||||||
} else {
|
album.artist.id as Id<"artists">
|
||||||
void handleAlbumDetailAction(
|
)
|
||||||
album.id as Id<"albums">,
|
}
|
||||||
songIds,
|
}}
|
||||||
action,
|
>
|
||||||
album.artist.id as Id<"artists">
|
<Pressable hitSlop={8}>
|
||||||
)
|
<Ionicons
|
||||||
}
|
name="ellipsis-horizontal"
|
||||||
}}
|
size={22}
|
||||||
>
|
color={colors.foreground}
|
||||||
<Pressable hitSlop={8}>
|
/>
|
||||||
<Ionicons
|
</Pressable>
|
||||||
name="ellipsis-horizontal"
|
</MediaActionMenu>
|
||||||
size={22}
|
|
||||||
color={colors.foreground}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
</MediaActionMenu>
|
|
||||||
</View>
|
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -307,34 +299,6 @@ export default function AlbumScreen() {
|
|||||||
heroLayout.landscape && { flexDirection: "row-reverse" },
|
heroLayout.landscape && { flexDirection: "row-reverse" },
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Pressable
|
|
||||||
onPress={() => void toggleAlbumFavorite(album.id)}
|
|
||||||
hitSlop={8}
|
|
||||||
style={[
|
|
||||||
styles.iconAction,
|
|
||||||
{ backgroundColor: palette.surface },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Ionicons
|
|
||||||
name={favorited ? "star" : "star-outline"}
|
|
||||||
size={24}
|
|
||||||
color={favorited ? palette.accent : palette.foreground}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
<Button
|
|
||||||
title="Play"
|
|
||||||
icon="play"
|
|
||||||
onPress={() =>
|
|
||||||
void (fromDownloads
|
|
||||||
? playInOrder(songIds, playOrigin)
|
|
||||||
: playAlbum(album.id, songIds))
|
|
||||||
}
|
|
||||||
style={styles.playButton}
|
|
||||||
tint={{
|
|
||||||
background: palette.accent,
|
|
||||||
foreground: palette.accentForeground,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Pressable
|
<Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Shuffle"
|
accessibilityLabel="Shuffle"
|
||||||
@@ -355,6 +319,28 @@ export default function AlbumScreen() {
|
|||||||
color={palette.foreground}
|
color={palette.foreground}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
<Button
|
||||||
|
title="Play"
|
||||||
|
icon="play"
|
||||||
|
onPress={() =>
|
||||||
|
void (fromDownloads
|
||||||
|
? playInOrder(songIds, playOrigin)
|
||||||
|
: playAlbum(album.id, songIds))
|
||||||
|
}
|
||||||
|
style={styles.playButton}
|
||||||
|
tint={{
|
||||||
|
background: palette.accent,
|
||||||
|
foreground: palette.accentForeground,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<CollectionDownloadButton
|
||||||
|
target={downloadTarget}
|
||||||
|
color={palette.foreground}
|
||||||
|
style={[
|
||||||
|
styles.iconAction,
|
||||||
|
{ backgroundColor: palette.surface },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -604,7 +590,6 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||||
headerActions: { flexDirection: "row", alignItems: "center", gap: 16 },
|
|
||||||
cover: {
|
cover: {
|
||||||
width: 220,
|
width: 220,
|
||||||
height: 220,
|
height: 220,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export default function AlbumsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<MediaGridSkeleton />
|
<MediaGridSkeleton title="Albums" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,7 @@ export default function AlbumsScreen() {
|
|||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Albums"
|
||||||
content={albums}
|
content={albums}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { Ionicons } from "@expo/vector-icons"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { memo, useCallback } from "react"
|
import { memo, useCallback } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MediaContextMenu,
|
MediaContextMenu,
|
||||||
@@ -15,6 +16,7 @@ import {
|
|||||||
} from "@/components/media-context-menu"
|
} from "@/components/media-context-menu"
|
||||||
import { CoverImage } from "@/components/cover-image"
|
import { CoverImage } from "@/components/cover-image"
|
||||||
import { ArtistListSkeleton } from "@/components/skeletons"
|
import { ArtistListSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { contentBottomInset } from "@/components/player"
|
import { contentBottomInset } from "@/components/player"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import {
|
import {
|
||||||
@@ -33,6 +35,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
|||||||
const PAGE_SIZE = 50
|
const PAGE_SIZE = 50
|
||||||
|
|
||||||
export default function ArtistsScreen() {
|
export default function ArtistsScreen() {
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseArtist>>()
|
||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const { config } = useServerConfig()
|
const { config } = useServerConfig()
|
||||||
@@ -94,7 +97,7 @@ export default function ArtistsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<ArtistListSkeleton />
|
<ArtistListSkeleton title="Artists" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -103,8 +106,11 @@ export default function ArtistsScreen() {
|
|||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
ListHeaderComponent={<ScreenTitle title="Artists" scrollY={scrollY} />}
|
||||||
data={artists}
|
data={artists}
|
||||||
keyExtractor={artistKey}
|
keyExtractor={artistKey}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useContext } from "react"
|
||||||
import { Pressable } from "react-native"
|
import { Pressable } from "react-native"
|
||||||
|
|
||||||
import { MediaGridList } from "@/components/media-cards"
|
import { MediaGridList } from "@/components/media-cards"
|
||||||
@@ -10,19 +11,20 @@ import { Ionicons } from "@expo/vector-icons"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { SymbolView } from "expo-symbols"
|
import { SymbolView } from "expo-symbols"
|
||||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||||
|
import { TabletSectionContext } from "@/lib/tablet-navigation"
|
||||||
|
|
||||||
export default function PlaylistsTabScreen() {
|
export default function PlaylistsTabScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
||||||
const { openCreatePlaylist } = useAddToPlaylist()
|
const { openCreatePlaylist } = useAddToPlaylist()
|
||||||
|
const title = useContext(TabletSectionContext)?.title ?? "Playlists"
|
||||||
|
|
||||||
if (playlists === undefined) {
|
if (playlists === undefined) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Playlists",
|
title,
|
||||||
headerLargeTitle: true,
|
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={openCreatePlaylist}
|
onPress={openCreatePlaylist}
|
||||||
@@ -38,7 +40,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MediaGridSkeleton />
|
<MediaGridSkeleton title={title} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -47,8 +49,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Playlists",
|
title,
|
||||||
headerLargeTitle: true,
|
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={openCreatePlaylist}
|
onPress={openCreatePlaylist}
|
||||||
@@ -61,6 +62,7 @@ export default function PlaylistsTabScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title={title}
|
||||||
content={playlists}
|
content={playlists}
|
||||||
paddingBottom={tabContentBottomInset}
|
paddingBottom={tabContentBottomInset}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { useCallback, useState } from "react"
|
import { useCallback, useState } from "react"
|
||||||
import { FlatList, StyleSheet, type ListRenderItemInfo } from "react-native"
|
import {
|
||||||
|
type FlatList,
|
||||||
|
StyleSheet,
|
||||||
|
type ListRenderItemInfo,
|
||||||
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
import { SongListSkeleton } from "@/components/skeletons"
|
import { SongListSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions } from "@/contexts/playback"
|
import { usePlaybackActions } from "@/contexts/playback"
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +26,7 @@ import { longListProps } from "@/lib/list"
|
|||||||
const PAGE_SIZE = 50
|
const PAGE_SIZE = 50
|
||||||
|
|
||||||
export default function SongsScreen() {
|
export default function SongsScreen() {
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
const { playFromLibrarySong } = usePlaybackActions()
|
const { playFromLibrarySong } = usePlaybackActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
@@ -87,7 +94,7 @@ export default function SongsScreen() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
<SongListSkeleton />
|
<SongListSkeleton title="Songs" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -96,8 +103,11 @@ export default function SongsScreen() {
|
|||||||
<>
|
<>
|
||||||
{searchBar}
|
{searchBar}
|
||||||
|
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
ListHeaderComponent={<ScreenTitle title="Songs" scrollY={scrollY} />}
|
||||||
data={songs}
|
data={songs}
|
||||||
keyExtractor={songKey}
|
keyExtractor={songKey}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
@@ -8,8 +8,10 @@ import {
|
|||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { CoverImage } from "@/components/cover-image"
|
import { CoverImage } from "@/components/cover-image"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { tabContentBottomInset } from "@/components/player"
|
import { tabContentBottomInset } from "@/components/player"
|
||||||
import {
|
import {
|
||||||
FAVORITES_DOWNLOAD_ID,
|
FAVORITES_DOWNLOAD_ID,
|
||||||
@@ -53,6 +55,7 @@ export default function DownloadsScreen() {
|
|||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<Card>>()
|
||||||
|
|
||||||
const cards = useMemo<Card[]>(() => {
|
const cards = useMemo<Card[]>(() => {
|
||||||
if (!queue) return []
|
if (!queue) return []
|
||||||
@@ -135,8 +138,10 @@ export default function DownloadsScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={{ title: "Downloads", headerLargeTitle: true }} />
|
<Stack.Screen options={{ title: "Downloads" }} />
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
key={columns}
|
key={columns}
|
||||||
onLayout={onLayout}
|
onLayout={onLayout}
|
||||||
data={cards}
|
data={cards}
|
||||||
@@ -149,13 +154,20 @@ export default function DownloadsScreen() {
|
|||||||
numColumns={columns}
|
numColumns={columns}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
paddingTop: spacing.lg,
|
|
||||||
paddingHorizontal: horizontalPadding,
|
paddingHorizontal: horizontalPadding,
|
||||||
paddingBottom: tabContentBottomInset,
|
paddingBottom: tabContentBottomInset,
|
||||||
gap,
|
gap,
|
||||||
}}
|
}}
|
||||||
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
|
ListHeaderComponent={
|
||||||
|
<ScreenTitle
|
||||||
|
title="Downloads"
|
||||||
|
scrollY={scrollY}
|
||||||
|
// The list padding already insets the title.
|
||||||
|
style={{ paddingHorizontal: 0 }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
<Text style={{ color: colors.mutedForeground }}>
|
<Text style={{ color: colors.mutedForeground }}>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { useCallback, useMemo } from "react"
|
import { useCallback, useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
Pressable,
|
Pressable,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
@@ -52,6 +54,7 @@ export default function OtherDownloadsScreen() {
|
|||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
const swipeGroup = useSwipeRowGroup()
|
const swipeGroup = useSwipeRowGroup()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
|
|
||||||
const handlePlaySong = useCallback(
|
const handlePlaySong = useCallback(
|
||||||
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
||||||
@@ -90,11 +93,11 @@ export default function OtherDownloadsScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen options={{ title: OTHER_DOWNLOADS_TITLE }} />
|
||||||
options={{ title: OTHER_DOWNLOADS_TITLE, headerLargeTitle: false }}
|
<Animated.FlatList
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
{...longListProps}
|
{...longListProps}
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
data={songs}
|
data={songs}
|
||||||
keyExtractor={(song) => song.id}
|
keyExtractor={(song) => song.id}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
@@ -103,25 +106,32 @@ export default function OtherDownloadsScreen() {
|
|||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
songs.length > 0 ? (
|
<>
|
||||||
<View style={styles.actions}>
|
<ScreenTitle title={OTHER_DOWNLOADS_TITLE} scrollY={scrollY} />
|
||||||
<Button
|
{songs.length > 0 ? (
|
||||||
title="Play"
|
<View style={styles.actions}>
|
||||||
icon="play"
|
<Button
|
||||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
title="Play"
|
||||||
style={styles.play}
|
icon="play"
|
||||||
/>
|
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||||
<Pressable
|
style={styles.play}
|
||||||
accessibilityRole="button"
|
/>
|
||||||
accessibilityLabel="Shuffle"
|
<Pressable
|
||||||
hitSlop={8}
|
accessibilityRole="button"
|
||||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
accessibilityLabel="Shuffle"
|
||||||
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
hitSlop={8}
|
||||||
>
|
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
||||||
</Pressable>
|
>
|
||||||
</View>
|
<Ionicons
|
||||||
) : undefined
|
name="shuffle"
|
||||||
|
size={24}
|
||||||
|
color={colors.foreground}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { memo } from "react"
|
import { memo } from "react"
|
||||||
import { ScrollView, StyleSheet } from "react-native"
|
import { type ScrollViewInstance, StyleSheet } from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { ContentCarousel } from "@/components/media-cards"
|
import { ContentCarousel } from "@/components/media-cards"
|
||||||
import { HomeSkeleton } from "@/components/skeletons"
|
import { HomeSkeleton } from "@/components/skeletons"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { tabContentBottomInset } from "@/components/player"
|
import { tabContentBottomInset } from "@/components/player"
|
||||||
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
@@ -38,6 +40,7 @@ const HomeCarousels = memo(function HomeCarousels({
|
|||||||
|
|
||||||
export default function HomeScreen() {
|
export default function HomeScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<ScrollViewInstance>()
|
||||||
const recentlyAdded = useCachedPaginatedQuery(
|
const recentlyAdded = useCachedPaginatedQuery(
|
||||||
api.library.browseRecentlyAddedPaginated,
|
api.library.browseRecentlyAddedPaginated,
|
||||||
{},
|
{},
|
||||||
@@ -53,14 +56,16 @@ export default function HomeScreen() {
|
|||||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||||
)
|
)
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <HomeSkeleton />
|
return <HomeSkeleton title="Home" />
|
||||||
}
|
}
|
||||||
|
|
||||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||||
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<Animated.ScrollView
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={[
|
contentContainerStyle={[
|
||||||
styles.content,
|
styles.content,
|
||||||
@@ -68,8 +73,9 @@ export default function HomeScreen() {
|
|||||||
]}
|
]}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
>
|
>
|
||||||
|
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} />
|
||||||
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||||
</ScrollView>
|
</Animated.ScrollView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +84,10 @@ const styles = StyleSheet.create({
|
|||||||
padding: spacing.lg,
|
padding: spacing.lg,
|
||||||
gap: spacing.xl,
|
gap: spacing.xl,
|
||||||
},
|
},
|
||||||
|
// The content padding already insets the title.
|
||||||
|
title: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
marginTop: -spacing.lg,
|
||||||
|
marginBottom: -spacing.md,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
@@ -45,9 +45,10 @@ import { CollectionDetailSkeleton } from "@/components/skeletons"
|
|||||||
import { Button } from "@/components/ui/primitives"
|
import { Button } from "@/components/ui/primitives"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
import {
|
import {
|
||||||
DownloadHeaderButton,
|
CollectionDownloadButton,
|
||||||
|
type CollectionDownloadTarget,
|
||||||
DownloadedQuality,
|
DownloadedQuality,
|
||||||
} from "@/components/download-header-button"
|
} from "@/components/collection-download-button"
|
||||||
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
||||||
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
||||||
import type { CollectionRef } from "@otunes/convex/client/download-queue"
|
import type { CollectionRef } from "@otunes/convex/client/download-queue"
|
||||||
@@ -349,32 +350,26 @@ function PlaylistContent({
|
|||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<View style={styles.headerActions}>
|
<MediaActionMenu
|
||||||
<DownloadHeaderButton
|
selectedCount={songIds.length}
|
||||||
target={downloadTarget}
|
playlistLabel={PLAYLIST_LABEL}
|
||||||
color={colors.foreground}
|
downloaded={playlistDownloaded}
|
||||||
/>
|
share={{
|
||||||
<MediaActionMenu
|
type: "playlist",
|
||||||
selectedCount={songIds.length}
|
playlistId: playlistId ?? "favorites",
|
||||||
playlistLabel={PLAYLIST_LABEL}
|
title: playlist?.title ?? "oTunes",
|
||||||
downloaded={playlistDownloaded}
|
}}
|
||||||
share={{
|
includeActions={canEdit ? OWNER_MENU_ACTIONS : undefined}
|
||||||
type: "playlist",
|
onAction={handlePlaylistMenuAction}
|
||||||
playlistId: playlistId ?? "favorites",
|
>
|
||||||
title: playlist?.title ?? "oTunes",
|
<Pressable hitSlop={8}>
|
||||||
}}
|
<Ionicons
|
||||||
includeActions={canEdit ? OWNER_MENU_ACTIONS : undefined}
|
name="ellipsis-horizontal"
|
||||||
onAction={handlePlaylistMenuAction}
|
size={22}
|
||||||
>
|
color={colors.foreground}
|
||||||
<Pressable hitSlop={8}>
|
/>
|
||||||
<Ionicons
|
</Pressable>
|
||||||
name="ellipsis-horizontal"
|
</MediaActionMenu>
|
||||||
size={22}
|
|
||||||
color={colors.foreground}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
</MediaActionMenu>
|
|
||||||
</View>
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
@@ -465,7 +460,7 @@ function PlaylistContent({
|
|||||||
isSubscribed={isSubscribed}
|
isSubscribed={isSubscribed}
|
||||||
showSubscribe={!playlist.isOwner && playlistId !== null}
|
showSubscribe={!playlist.isOwner && playlistId !== null}
|
||||||
onSubscribeToggle={handleSubscribeToggle}
|
onSubscribeToggle={handleSubscribeToggle}
|
||||||
downloadRef={downloadRef}
|
downloadTarget={downloadTarget}
|
||||||
onPlay={handlePlay}
|
onPlay={handlePlay}
|
||||||
onShuffle={handleShuffle}
|
onShuffle={handleShuffle}
|
||||||
/>
|
/>
|
||||||
@@ -576,11 +571,11 @@ const PlaylistHero = memo(function PlaylistHero({
|
|||||||
isSubscribed,
|
isSubscribed,
|
||||||
showSubscribe = false,
|
showSubscribe = false,
|
||||||
onSubscribeToggle,
|
onSubscribeToggle,
|
||||||
downloadRef,
|
downloadTarget,
|
||||||
onPlay,
|
onPlay,
|
||||||
onShuffle,
|
onShuffle,
|
||||||
}: {
|
}: {
|
||||||
downloadRef: CollectionRef
|
downloadTarget: CollectionDownloadTarget
|
||||||
entityId: string
|
entityId: string
|
||||||
coverUri: string
|
coverUri: string
|
||||||
hasCover: boolean
|
hasCover: boolean
|
||||||
@@ -648,6 +643,15 @@ const PlaylistHero = memo(function PlaylistHero({
|
|||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : null}
|
) : null}
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Shuffle"
|
||||||
|
hitSlop={8}
|
||||||
|
onPress={onShuffle}
|
||||||
|
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||||
|
>
|
||||||
|
<Ionicons name="shuffle" size={24} color={palette.foreground} />
|
||||||
|
</Pressable>
|
||||||
<Button
|
<Button
|
||||||
title="Play"
|
title="Play"
|
||||||
icon="play"
|
icon="play"
|
||||||
@@ -658,15 +662,11 @@ const PlaylistHero = memo(function PlaylistHero({
|
|||||||
foreground: palette.accentForeground,
|
foreground: palette.accentForeground,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Pressable
|
<CollectionDownloadButton
|
||||||
accessibilityRole="button"
|
target={downloadTarget}
|
||||||
accessibilityLabel="Shuffle"
|
color={palette.foreground}
|
||||||
hitSlop={8}
|
|
||||||
onPress={onShuffle}
|
|
||||||
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||||
>
|
/>
|
||||||
<Ionicons name="shuffle" size={24} color={palette.foreground} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -688,7 +688,7 @@ const PlaylistHero = memo(function PlaylistHero({
|
|||||||
{ownerName}
|
{ownerName}
|
||||||
</Text>
|
</Text>
|
||||||
<DownloadedQuality
|
<DownloadedQuality
|
||||||
collection={downloadRef}
|
collection={downloadTarget}
|
||||||
color={palette.secondaryForeground}
|
color={palette.secondaryForeground}
|
||||||
backgroundColor={palette.background}
|
backgroundColor={palette.background}
|
||||||
/>
|
/>
|
||||||
@@ -701,7 +701,6 @@ const PlaylistHero = memo(function PlaylistHero({
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
emptyResults: { padding: spacing.lg, textAlign: "center" },
|
emptyResults: { padding: spacing.lg, textAlign: "center" },
|
||||||
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||||
headerActions: { flexDirection: "row", alignItems: "center", gap: 16 },
|
|
||||||
listContent: { paddingBottom: contentBottomInset },
|
listContent: { paddingBottom: contentBottomInset },
|
||||||
cover: {
|
cover: {
|
||||||
width: 200,
|
width: 200,
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ import { CollectionDetailSkeleton } from "@/components/skeletons"
|
|||||||
import { Button } from "@/components/ui/primitives"
|
import { Button } from "@/components/ui/primitives"
|
||||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||||
import {
|
import {
|
||||||
DownloadHeaderButton,
|
CollectionDownloadButton,
|
||||||
|
type CollectionDownloadTarget,
|
||||||
DownloadedQuality,
|
DownloadedQuality,
|
||||||
} from "@/components/download-header-button"
|
} from "@/components/collection-download-button"
|
||||||
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
import { useOpenedFromDownloads } from "@/lib/downloads-navigation"
|
||||||
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
import { downloadsQueueOrigin } from "@otunes/convex/download-quality"
|
||||||
import { FAVORITES_DOWNLOAD_ID } from "@/contexts/downloads"
|
import { FAVORITES_DOWNLOAD_ID } from "@/contexts/downloads"
|
||||||
@@ -53,22 +54,13 @@ export default function FavoritesScreen() {
|
|||||||
const playOrigin = fromDownloads
|
const playOrigin = fromDownloads
|
||||||
? downloadsQueueOrigin("playlist:favorites")
|
? downloadsQueueOrigin("playlist:favorites")
|
||||||
: undefined
|
: undefined
|
||||||
const screenOptions = useMemo(
|
const downloadTarget = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...SCREEN_OPTIONS,
|
...DOWNLOAD_REF,
|
||||||
headerRight: () => (
|
title: favorites?.title ?? "Favorites",
|
||||||
<DownloadHeaderButton
|
songIds,
|
||||||
target={{
|
|
||||||
kind: "playlist",
|
|
||||||
id: FAVORITES_DOWNLOAD_ID,
|
|
||||||
title: favorites?.title ?? "Favorites",
|
|
||||||
songIds,
|
|
||||||
}}
|
|
||||||
color={colors.foreground}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
[colors.foreground, favorites?.title, songIds]
|
[favorites?.title, songIds]
|
||||||
)
|
)
|
||||||
const { filteredSongs, onQueryChange, onSearchSubmit } =
|
const { filteredSongs, onQueryChange, onSearchSubmit } =
|
||||||
usePlaylistSearch(songs)
|
usePlaylistSearch(songs)
|
||||||
@@ -134,7 +126,7 @@ export default function FavoritesScreen() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={screenOptions} />
|
<Stack.Screen options={SCREEN_OPTIONS} />
|
||||||
<PlaylistSearchBar
|
<PlaylistSearchBar
|
||||||
onQueryChange={onQueryChange}
|
onQueryChange={onQueryChange}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
@@ -157,6 +149,7 @@ export default function FavoritesScreen() {
|
|||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<FavoritesHero
|
<FavoritesHero
|
||||||
title={favorites.title}
|
title={favorites.title}
|
||||||
|
downloadTarget={downloadTarget}
|
||||||
onPlay={handlePlay}
|
onPlay={handlePlay}
|
||||||
onShuffle={handleShuffle}
|
onShuffle={handleShuffle}
|
||||||
/>
|
/>
|
||||||
@@ -172,10 +165,12 @@ function songKey(song: BrowseSong) {
|
|||||||
|
|
||||||
const FavoritesHero = memo(function FavoritesHero({
|
const FavoritesHero = memo(function FavoritesHero({
|
||||||
title,
|
title,
|
||||||
|
downloadTarget,
|
||||||
onPlay,
|
onPlay,
|
||||||
onShuffle,
|
onShuffle,
|
||||||
}: {
|
}: {
|
||||||
title: string
|
title: string
|
||||||
|
downloadTarget: CollectionDownloadTarget
|
||||||
onPlay: () => void
|
onPlay: () => void
|
||||||
onShuffle: () => void
|
onShuffle: () => void
|
||||||
}) {
|
}) {
|
||||||
@@ -202,12 +197,6 @@ const FavoritesHero = memo(function FavoritesHero({
|
|||||||
backgroundColor={colors.background}
|
backgroundColor={colors.background}
|
||||||
/>
|
/>
|
||||||
<View style={styles.actions}>
|
<View style={styles.actions}>
|
||||||
<Button
|
|
||||||
title="Play"
|
|
||||||
icon="play"
|
|
||||||
onPress={onPlay}
|
|
||||||
style={styles.playButton}
|
|
||||||
/>
|
|
||||||
<Pressable
|
<Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Shuffle"
|
accessibilityLabel="Shuffle"
|
||||||
@@ -217,6 +206,17 @@ const FavoritesHero = memo(function FavoritesHero({
|
|||||||
>
|
>
|
||||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
<Button
|
||||||
|
title="Play"
|
||||||
|
icon="play"
|
||||||
|
onPress={onPlay}
|
||||||
|
style={styles.playButton}
|
||||||
|
/>
|
||||||
|
<CollectionDownloadButton
|
||||||
|
target={downloadTarget}
|
||||||
|
color={colors.foreground}
|
||||||
|
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<CollectionDivider />
|
<CollectionDivider />
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ export default function RecentlyAddedScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton />
|
return <MediaGridSkeleton title="Recently Added" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Recently Added"
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ export default function RecentlyPlayedScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton />
|
return <MediaGridSkeleton title="Recently Played" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title="Recently Played"
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={contentBottomInset}
|
paddingBottom={contentBottomInset}
|
||||||
onEndReached={() => {
|
onEndReached={() => {
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -18,6 +22,7 @@ export default function LibraryLayout() {
|
|||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title:
|
title:
|
||||||
tabStackScreenTitles[route.name] ??
|
tabStackScreenTitles[route.name] ??
|
||||||
(tabletLayout ? "Recently Added" : "Library"),
|
(tabletLayout ? "Recently Added" : "Library"),
|
||||||
|
|||||||
@@ -24,17 +24,17 @@ const links = [
|
|||||||
{ title: "Artists", href: "/browse/artists", icon: "mic.fill" as const },
|
{ title: "Artists", href: "/browse/artists", icon: "mic.fill" as const },
|
||||||
{ title: "Albums", href: "/browse/albums", icon: "square.stack" as const },
|
{ title: "Albums", href: "/browse/albums", icon: "square.stack" as const },
|
||||||
{ title: "Songs", href: "/browse/songs", icon: "music.note" as const },
|
{ title: "Songs", href: "/browse/songs", icon: "music.note" as const },
|
||||||
|
{
|
||||||
|
title: "Downloads",
|
||||||
|
href: "/downloads",
|
||||||
|
icon: "arrow.down.circle" as const,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Recently Played",
|
title: "Recently Played",
|
||||||
href: "/recently-played",
|
href: "/recently-played",
|
||||||
icon: "clock" as const,
|
icon: "clock" as const,
|
||||||
},
|
},
|
||||||
{ title: "Favorites", href: "/playlist/favorites", icon: "star" as const },
|
{ title: "Favorites", href: "/playlist/favorites", icon: "star" as const },
|
||||||
{
|
|
||||||
title: "Downloads",
|
|
||||||
href: "/downloads",
|
|
||||||
icon: "arrow.down.circle" as const,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
function LibraryIcon({ name }: { name: (typeof links)[number]["icon"] }) {
|
function LibraryIcon({ name }: { name: (typeof links)[number]["icon"] }) {
|
||||||
@@ -72,6 +72,7 @@ export default function LibraryScreen() {
|
|||||||
const { push } = useAppNavigation()
|
const { push } = useAppNavigation()
|
||||||
const isTablet = tabletLayout
|
const isTablet = tabletLayout
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const title = isTablet ? "Recently Added" : "Library"
|
||||||
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
||||||
api.library.browseRecentlyAddedPaginated,
|
api.library.browseRecentlyAddedPaginated,
|
||||||
{},
|
{},
|
||||||
@@ -124,11 +125,18 @@ export default function LibraryScreen() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (status === "LoadingFirstPage" && !isCached) {
|
if (status === "LoadingFirstPage" && !isCached) {
|
||||||
return <MediaGridSkeleton contentInset={false} header={listHeader} />
|
return (
|
||||||
|
<MediaGridSkeleton
|
||||||
|
title={title}
|
||||||
|
contentInset={false}
|
||||||
|
header={listHeader}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaGridList
|
<MediaGridList
|
||||||
|
title={title}
|
||||||
content={results}
|
content={results}
|
||||||
paddingBottom={tabContentBottomInset}
|
paddingBottom={tabContentBottomInset}
|
||||||
contentInset={false}
|
contentInset={false}
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
|||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
import {
|
||||||
|
inlineTitleOptions,
|
||||||
|
tabStackScreenTitles,
|
||||||
|
useStackScreenOptions,
|
||||||
|
} from "@/lib/navigation"
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
anchor: "index",
|
anchor: "index",
|
||||||
@@ -16,6 +20,7 @@ export default function SearchLayout() {
|
|||||||
screenLayout={renderTabScreenContent}
|
screenLayout={renderTabScreenContent}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
...baseOptions,
|
...baseOptions,
|
||||||
|
...inlineTitleOptions,
|
||||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||||
headerRight:
|
headerRight:
|
||||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export default function SearchScreen() {
|
|||||||
: {})}
|
: {})}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SearchResults searchQuery={searchQuery} />
|
<SearchResults searchQuery={searchQuery} title="Search" />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
import { useTabletLayout } from "@/hooks/use-tablet-layout"
|
import { useTabletLayout } from "@/hooks/use-tablet-layout"
|
||||||
import { TabletNowPlaying } from "@/components/tablet-now-playing"
|
import {
|
||||||
|
TabletNowPlaying,
|
||||||
|
type PlayerPanel,
|
||||||
|
} from "@/components/tablet-now-playing"
|
||||||
import { atmosEnabled } from "@/lib/playback-capabilities"
|
import { atmosEnabled } from "@/lib/playback-capabilities"
|
||||||
import { NavigationBar } from "expo-navigation-bar"
|
import { NavigationBar } from "expo-navigation-bar"
|
||||||
import { MusicEntityView } from "@/components/music-entity-view"
|
import { MusicEntityView } from "@/components/music-entity-view"
|
||||||
@@ -51,7 +54,9 @@ import { PlayerSymbol } from "@/components/player-symbol"
|
|||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions, usePlaybackQueue } from "@/contexts/playback"
|
import { usePlaybackActions, usePlaybackQueue } from "@/contexts/playback"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
|
import { LyricsView } from "@/components/lyrics-view"
|
||||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
|
import { useLyrics } from "@/hooks/use-lyrics"
|
||||||
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
import { useCoverPalette } from "@/hooks/use-cover-palette"
|
||||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||||
import { useSystemVolume } from "@/hooks/use-system-volume"
|
import { useSystemVolume } from "@/hooks/use-system-volume"
|
||||||
@@ -93,8 +98,14 @@ export default function PlayerScreen() {
|
|||||||
queueSongIds,
|
queueSongIds,
|
||||||
} = usePlaybackQueue()
|
} = usePlaybackQueue()
|
||||||
const { setIsPlaying, skipNext, skipPrevious } = usePlaybackActions()
|
const { setIsPlaying, skipNext, skipPrevious } = usePlaybackActions()
|
||||||
const { queue } = useLocalSearchParams<{ queue?: string }>()
|
const params = useLocalSearchParams<{ queue?: string; lyrics?: string }>()
|
||||||
const [showQueue, setShowQueue] = useState(queue === "1")
|
// The queue or lyrics, shown in place of the artwork.
|
||||||
|
const [panel, setPanel] = useState<PlayerPanel | null>(
|
||||||
|
params.queue === "1" ? "queue" : params.lyrics === "1" ? "lyrics" : null
|
||||||
|
)
|
||||||
|
const showQueue = panel === "queue"
|
||||||
|
const showLyrics = panel === "lyrics"
|
||||||
|
const lyrics = useLyrics(currentSong?.id ?? null)
|
||||||
const [isDismissing, setIsDismissing] = useState(false)
|
const [isDismissing, setIsDismissing] = useState(false)
|
||||||
const [stageHeight, setStageHeight] = useState(0)
|
const [stageHeight, setStageHeight] = useState(0)
|
||||||
const user = useCachedQuery(api.auth.currentUser)
|
const user = useCachedQuery(api.auth.currentUser)
|
||||||
@@ -187,8 +198,8 @@ export default function PlayerScreen() {
|
|||||||
const handleGesture = useMemo(makeDismissGesture, [makeDismissGesture])
|
const handleGesture = useMemo(makeDismissGesture, [makeDismissGesture])
|
||||||
const controlsGesture = useMemo(makeDismissGesture, [makeDismissGesture])
|
const controlsGesture = useMemo(makeDismissGesture, [makeDismissGesture])
|
||||||
const stageGesture = useMemo(
|
const stageGesture = useMemo(
|
||||||
() => makeDismissGesture().enabled(!showQueue),
|
() => makeDismissGesture().enabled(panel === null),
|
||||||
[makeDismissGesture, showQueue]
|
[makeDismissGesture, panel]
|
||||||
)
|
)
|
||||||
|
|
||||||
const hasCover = currentSong ? currentSong.album.cover != null : false
|
const hasCover = currentSong ? currentSong.album.cover != null : false
|
||||||
@@ -243,9 +254,9 @@ export default function PlayerScreen() {
|
|||||||
setIsPlaying(!isPlaying)
|
setIsPlaying(!isPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleQueue() {
|
function togglePanel(next: PlayerPanel) {
|
||||||
void Haptics.selectionAsync()
|
void Haptics.selectionAsync()
|
||||||
setShowQueue((value) => !value)
|
setPanel((value) => (value === next ? null : next))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTablet) {
|
if (isTablet) {
|
||||||
@@ -256,8 +267,9 @@ export default function PlayerScreen() {
|
|||||||
backgroundStyle={backgroundStyle}
|
backgroundStyle={backgroundStyle}
|
||||||
dismissStyle={dismissStyle}
|
dismissStyle={dismissStyle}
|
||||||
dismissGestures={{ handle: handleGesture, artwork: controlsGesture }}
|
dismissGestures={{ handle: handleGesture, artwork: controlsGesture }}
|
||||||
showQueue={showQueue}
|
panel={panel}
|
||||||
toggleQueue={toggleQueue}
|
togglePanel={togglePanel}
|
||||||
|
lyrics={lyrics}
|
||||||
metadata={songMeta}
|
metadata={songMeta}
|
||||||
/>
|
/>
|
||||||
</MusicEntityView>
|
</MusicEntityView>
|
||||||
@@ -322,6 +334,20 @@ export default function PlayerScreen() {
|
|||||||
/>
|
/>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
) : null
|
) : null
|
||||||
|
) : showLyrics ? (
|
||||||
|
<Animated.View
|
||||||
|
key="lyrics"
|
||||||
|
entering={MODE_FADE_IN}
|
||||||
|
exiting={MODE_FADE_OUT}
|
||||||
|
style={[styles.fill, styles.artworkMode]}
|
||||||
|
>
|
||||||
|
{queueHeader}
|
||||||
|
<LyricsView
|
||||||
|
key={currentSong.id}
|
||||||
|
lyrics={lyrics}
|
||||||
|
colors={colors}
|
||||||
|
/>
|
||||||
|
</Animated.View>
|
||||||
) : (
|
) : (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
key="artwork"
|
key="artwork"
|
||||||
@@ -409,18 +435,29 @@ export default function PlayerScreen() {
|
|||||||
|
|
||||||
<View style={styles.footer}>
|
<View style={styles.footer}>
|
||||||
<Pressable
|
<Pressable
|
||||||
disabled
|
onPress={() => togglePanel("lyrics")}
|
||||||
|
disabled={!lyrics && !showLyrics}
|
||||||
|
hitSlop={8}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Lyrics"
|
accessibilityLabel={showLyrics ? "Hide lyrics" : "Show lyrics"}
|
||||||
accessibilityState={{ disabled: true }}
|
accessibilityState={{
|
||||||
style={[styles.queueButton, styles.unavailable]}
|
selected: showLyrics,
|
||||||
|
disabled: !lyrics && !showLyrics,
|
||||||
|
}}
|
||||||
|
style={[
|
||||||
|
styles.queueButton,
|
||||||
|
!lyrics && !showLyrics && styles.unavailable,
|
||||||
|
showLyrics && { backgroundColor: colors.selected },
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<PlayerSymbol
|
<PlayerSymbol
|
||||||
name="quote.bubble"
|
name="quote.bubble"
|
||||||
fallback={{ material: "lyrics" }}
|
fallback={{ material: "lyrics" }}
|
||||||
size={27}
|
size={27}
|
||||||
weight="semibold"
|
weight="semibold"
|
||||||
color={colors.foreground}
|
color={
|
||||||
|
showLyrics ? colors.selectedForeground : colors.foreground
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<AudioOutputButton
|
<AudioOutputButton
|
||||||
@@ -428,7 +465,7 @@ export default function PlayerScreen() {
|
|||||||
style={styles.queueButton}
|
style={styles.queueButton}
|
||||||
/>
|
/>
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={toggleQueue}
|
onPress={() => togglePanel("queue")}
|
||||||
hitSlop={8}
|
hitSlop={8}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={showQueue ? "Hide queue" : "Show queue"}
|
accessibilityLabel={showQueue ? "Hide queue" : "Show queue"}
|
||||||
|
|||||||
+22
-6
@@ -1,5 +1,13 @@
|
|||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { Alert, Pressable, StyleSheet, Text, View } from "react-native"
|
import {
|
||||||
|
Alert,
|
||||||
|
Pressable,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
type StyleProp,
|
||||||
|
type ViewStyle,
|
||||||
|
} from "react-native"
|
||||||
import Svg, { Circle, Rect } from "react-native-svg"
|
import Svg, { Circle, Rect } from "react-native-svg"
|
||||||
|
|
||||||
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
import { AudioFormatBadge } from "@/components/audio-format-badge"
|
||||||
@@ -51,13 +59,20 @@ function ProgressRing({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Download, progress, and downloaded states for an album or playlist header. */
|
export type CollectionDownloadTarget = Exclude<
|
||||||
export function DownloadHeaderButton({
|
DownloadTarget,
|
||||||
|
{ kind: "songs" }
|
||||||
|
>
|
||||||
|
|
||||||
|
/** Download, progress, and downloaded states for an album or playlist hero, beside Play. */
|
||||||
|
export function CollectionDownloadButton({
|
||||||
target,
|
target,
|
||||||
color,
|
color,
|
||||||
|
style,
|
||||||
}: {
|
}: {
|
||||||
target: Exclude<DownloadTarget, { kind: "songs" }>
|
target: CollectionDownloadTarget
|
||||||
color: string
|
color: string
|
||||||
|
style?: StyleProp<ViewStyle>
|
||||||
}) {
|
}) {
|
||||||
const { queue, requestDownload, removeDownload } = useDownloads()
|
const { queue, requestDownload, removeDownload } = useDownloads()
|
||||||
useDownloadsVersion()
|
useDownloadsVersion()
|
||||||
@@ -96,6 +111,7 @@ export function DownloadHeaderButton({
|
|||||||
}
|
}
|
||||||
disabled={target.songIds.length === 0}
|
disabled={target.songIds.length === 0}
|
||||||
onPress={handlePress}
|
onPress={handlePress}
|
||||||
|
style={style}
|
||||||
>
|
>
|
||||||
{inProgress && status ? (
|
{inProgress && status ? (
|
||||||
<ProgressRing
|
<ProgressRing
|
||||||
@@ -104,8 +120,8 @@ export function DownloadHeaderButton({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name={done ? "checkmark-circle" : "arrow-down-circle-outline"}
|
name={done ? "checkmark" : "arrow-down"}
|
||||||
size={SIZE + 2}
|
size={24}
|
||||||
color={color}
|
color={color}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -0,0 +1,370 @@
|
|||||||
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
|
import {
|
||||||
|
Pressable,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
type ScrollViewInstance,
|
||||||
|
} from "react-native"
|
||||||
|
import Animated, {
|
||||||
|
cancelAnimation,
|
||||||
|
Easing,
|
||||||
|
useAnimatedStyle,
|
||||||
|
useSharedValue,
|
||||||
|
withTiming,
|
||||||
|
type SharedValue,
|
||||||
|
} from "react-native-reanimated"
|
||||||
|
|
||||||
|
import {
|
||||||
|
usePlaybackActions,
|
||||||
|
usePlaybackProgress,
|
||||||
|
usePlaybackQueue,
|
||||||
|
} from "@/contexts/playback"
|
||||||
|
import { useLyricsTime } from "@/hooks/use-lyrics"
|
||||||
|
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||||
|
import {
|
||||||
|
activeLineIndex,
|
||||||
|
type LyricLine,
|
||||||
|
type LyricWord,
|
||||||
|
type Lyrics,
|
||||||
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
|
/** How long a manual scroll keeps the view from following the song. */
|
||||||
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
|
/** Where the playing line sits, as a share of the view's height from the top. */
|
||||||
|
const ACTIVE_LINE_POSITION = 0.12
|
||||||
|
/** Blur radius by distance from the playing line; farther lines share the last. */
|
||||||
|
const LINE_BLUR = [0, 1, 2, 3]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lyrics in the player's own colors. Synced lines follow playback and seek
|
||||||
|
* when tapped; `null` lyrics show a short note instead.
|
||||||
|
*/
|
||||||
|
export function LyricsView({
|
||||||
|
lyrics,
|
||||||
|
colors,
|
||||||
|
fontSize = 30,
|
||||||
|
}: {
|
||||||
|
lyrics: Lyrics | null | undefined
|
||||||
|
colors: NowPlayingColors
|
||||||
|
fontSize?: number
|
||||||
|
}) {
|
||||||
|
if (lyrics === undefined) return null
|
||||||
|
if (lyrics === null) {
|
||||||
|
return (
|
||||||
|
<View style={styles.empty}>
|
||||||
|
<Text style={[styles.emptyText, { color: colors.secondaryForeground }]}>
|
||||||
|
No lyrics
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return <LyricsLines lyrics={lyrics} colors={colors} fontSize={fontSize} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function LyricsLines({
|
||||||
|
lyrics,
|
||||||
|
colors,
|
||||||
|
fontSize,
|
||||||
|
}: {
|
||||||
|
lyrics: Lyrics
|
||||||
|
colors: NowPlayingColors
|
||||||
|
fontSize: number
|
||||||
|
}) {
|
||||||
|
const { currentTime } = usePlaybackProgress()
|
||||||
|
const { isPlaying } = usePlaybackQueue()
|
||||||
|
const { seekTo, setIsPlaying } = usePlaybackActions()
|
||||||
|
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||||
|
const active = activeLineIndex(lyrics, time)
|
||||||
|
const synced = lyrics.synced !== "none"
|
||||||
|
const scrollRef = useRef<ScrollViewInstance>(null)
|
||||||
|
const lineOffsets = useRef<number[]>([])
|
||||||
|
const [height, setHeight] = useState(0)
|
||||||
|
// While the listener scrolls, lines stay sharp and the view stays put.
|
||||||
|
const [browsing, setBrowsing] = useState(false)
|
||||||
|
const browseTimer = useRef<ReturnType<typeof setTimeout>>(undefined)
|
||||||
|
|
||||||
|
useEffect(() => () => clearTimeout(browseTimer.current), [])
|
||||||
|
|
||||||
|
const scrollToLine = useCallback(
|
||||||
|
(index: number) => {
|
||||||
|
const y = lineOffsets.current[Math.max(index, 0)]
|
||||||
|
if (y === undefined || !synced || height === 0 || browsing) return
|
||||||
|
scrollRef.current?.scrollTo({
|
||||||
|
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
||||||
|
animated: true,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[height, synced, browsing]
|
||||||
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
scrollToLine(active)
|
||||||
|
}, [active, scrollToLine])
|
||||||
|
|
||||||
|
const activeRef = useRef(active)
|
||||||
|
useEffect(() => {
|
||||||
|
activeRef.current = active
|
||||||
|
}, [active])
|
||||||
|
const handleLineLayout = useCallback(
|
||||||
|
(index: number, y: number) => {
|
||||||
|
lineOffsets.current[index] = y
|
||||||
|
// Opening mid-song: jump once the playing line has been measured.
|
||||||
|
if (index === Math.max(activeRef.current, 0)) scrollToLine(index)
|
||||||
|
},
|
||||||
|
[scrollToLine]
|
||||||
|
)
|
||||||
|
|
||||||
|
const playFrom = useCallback(
|
||||||
|
(seconds: number) => {
|
||||||
|
seekTo(seconds)
|
||||||
|
setIsPlaying(true)
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
setBrowsing(false)
|
||||||
|
},
|
||||||
|
[seekTo, setIsPlaying]
|
||||||
|
)
|
||||||
|
|
||||||
|
const releaseScroll = () => {
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
browseTimer.current = setTimeout(
|
||||||
|
() => setBrowsing(false),
|
||||||
|
MANUAL_SCROLL_HOLD_MS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineStyle = useMemo(
|
||||||
|
() => ({ fontSize, lineHeight: Math.round(fontSize * 1.18) }),
|
||||||
|
[fontSize]
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
ref={scrollRef}
|
||||||
|
style={styles.fill}
|
||||||
|
contentContainerStyle={{
|
||||||
|
paddingTop: height * ACTIVE_LINE_POSITION,
|
||||||
|
paddingBottom: height * 0.7,
|
||||||
|
}}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
||||||
|
onScrollBeginDrag={() => {
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
setBrowsing(true)
|
||||||
|
}}
|
||||||
|
// Hold from when the scroll settles, not when the finger lifted.
|
||||||
|
onScrollEndDrag={releaseScroll}
|
||||||
|
onMomentumScrollEnd={releaseScroll}
|
||||||
|
>
|
||||||
|
{lyrics.lines.map((line, index) =>
|
||||||
|
synced ? (
|
||||||
|
<SyncedLine
|
||||||
|
key={index}
|
||||||
|
index={index}
|
||||||
|
line={line}
|
||||||
|
distance={
|
||||||
|
browsing
|
||||||
|
? 0
|
||||||
|
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||||
|
}
|
||||||
|
active={index === active}
|
||||||
|
time={index === active ? time : null}
|
||||||
|
isPlaying={isPlaying}
|
||||||
|
colors={colors}
|
||||||
|
textStyle={lineStyle}
|
||||||
|
onSelect={playFrom}
|
||||||
|
onLayoutY={handleLineLayout}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
key={index}
|
||||||
|
style={[
|
||||||
|
styles.plainLine,
|
||||||
|
{
|
||||||
|
color: colors.foreground,
|
||||||
|
fontSize: fontSize * 0.75,
|
||||||
|
lineHeight: Math.round(fontSize * 0.75 * 1.25),
|
||||||
|
},
|
||||||
|
line.text === "" && styles.stanzaGap,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{line.text}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||||
|
* playing line gets the time, so the others skip re-rendering as the song
|
||||||
|
* plays.
|
||||||
|
*/
|
||||||
|
const SyncedLine = memo(function SyncedLine({
|
||||||
|
index,
|
||||||
|
line,
|
||||||
|
distance,
|
||||||
|
active,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
colors,
|
||||||
|
textStyle,
|
||||||
|
onSelect,
|
||||||
|
onLayoutY,
|
||||||
|
}: {
|
||||||
|
index: number
|
||||||
|
line: LyricLine
|
||||||
|
distance: number
|
||||||
|
active: boolean
|
||||||
|
time: number | null
|
||||||
|
isPlaying: boolean
|
||||||
|
colors: NowPlayingColors
|
||||||
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
|
onSelect: (seconds: number) => void
|
||||||
|
onLayoutY: (index: number, y: number) => void
|
||||||
|
}) {
|
||||||
|
const blur = LINE_BLUR[distance]
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => onSelect(line.start ?? 0)}
|
||||||
|
onLayout={(event) => onLayoutY(index, event.nativeEvent.layout.y)}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityHint="Plays from this line"
|
||||||
|
style={[styles.line, blur > 0 && { filter: [{ blur }] }]}
|
||||||
|
>
|
||||||
|
{active && line.words && time !== null ? (
|
||||||
|
<FilledWords
|
||||||
|
words={line.words}
|
||||||
|
time={time}
|
||||||
|
isPlaying={isPlaying}
|
||||||
|
colors={colors}
|
||||||
|
textStyle={textStyle}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
styles.lineText,
|
||||||
|
textStyle,
|
||||||
|
{
|
||||||
|
color:
|
||||||
|
active && !line.words
|
||||||
|
? colors.foreground
|
||||||
|
: colors.lyricsInactive,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{line.text}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The playing line's words, each wiping from dim to bright as it is sung.
|
||||||
|
* Reanimated runs the wipe; playback updates only re-anchor it.
|
||||||
|
*/
|
||||||
|
function FilledWords({
|
||||||
|
words,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
colors,
|
||||||
|
textStyle,
|
||||||
|
}: {
|
||||||
|
words: LyricWord[]
|
||||||
|
time: number
|
||||||
|
isPlaying: boolean
|
||||||
|
colors: NowPlayingColors
|
||||||
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
|
}) {
|
||||||
|
const sung = useSharedValue(time)
|
||||||
|
const end = words.at(-1)?.end ?? time
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
cancelAnimation(sung)
|
||||||
|
sung.value = time
|
||||||
|
if (isPlaying && end > time) {
|
||||||
|
sung.value = withTiming(end, {
|
||||||
|
duration: (end - time) * 1000,
|
||||||
|
easing: Easing.linear,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [sung, time, isPlaying, end])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.words, { columnGap: textStyle.fontSize * 0.25 }]}>
|
||||||
|
{words.map((word, index) => (
|
||||||
|
<FilledWord
|
||||||
|
key={index}
|
||||||
|
word={word}
|
||||||
|
sung={sung}
|
||||||
|
colors={colors}
|
||||||
|
textStyle={textStyle}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FilledWord({
|
||||||
|
word,
|
||||||
|
sung,
|
||||||
|
colors,
|
||||||
|
textStyle,
|
||||||
|
}: {
|
||||||
|
word: LyricWord
|
||||||
|
sung: SharedValue<number>
|
||||||
|
colors: NowPlayingColors
|
||||||
|
textStyle: { fontSize: number; lineHeight: number }
|
||||||
|
}) {
|
||||||
|
const [width, setWidth] = useState(0)
|
||||||
|
const text = word.text.trim()
|
||||||
|
const wipe = useAnimatedStyle(() => {
|
||||||
|
const progress =
|
||||||
|
(sung.value - word.start) / Math.max(word.end - word.start, 0.05)
|
||||||
|
return { width: width * Math.min(Math.max(progress, 0), 1) }
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text
|
||||||
|
style={[styles.lineText, textStyle, { color: colors.lyricsUnsung }]}
|
||||||
|
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</Text>
|
||||||
|
<Animated.View style={[styles.wipe, wipe]}>
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={[
|
||||||
|
styles.lineText,
|
||||||
|
textStyle,
|
||||||
|
{ color: colors.foreground, width },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</Text>
|
||||||
|
</Animated.View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
fill: { flex: 1 },
|
||||||
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
||||||
|
emptyText: { fontSize: 17, fontWeight: "600" },
|
||||||
|
line: { paddingVertical: 9 },
|
||||||
|
lineText: { fontWeight: "800" },
|
||||||
|
words: { flexDirection: "row", flexWrap: "wrap" },
|
||||||
|
wipe: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
plainLine: { fontWeight: "700", paddingVertical: 2 },
|
||||||
|
stanzaGap: { height: 18 },
|
||||||
|
})
|
||||||
@@ -4,6 +4,7 @@ import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
|||||||
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
||||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||||
import { MusicEntityView } from "@/components/music-entity-view"
|
import { MusicEntityView } from "@/components/music-entity-view"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { Link } from "expo-router"
|
import { Link } from "expo-router"
|
||||||
import { Ionicons } from "@expo/vector-icons"
|
import { Ionicons } from "@expo/vector-icons"
|
||||||
import { memo, useCallback, type ReactElement } from "react"
|
import { memo, useCallback, type ReactElement } from "react"
|
||||||
@@ -300,17 +301,21 @@ export function MediaGridList({
|
|||||||
onEndReached,
|
onEndReached,
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
|
title,
|
||||||
}: {
|
}: {
|
||||||
content: MediaItem[]
|
content: MediaItem[]
|
||||||
paddingBottom: number
|
paddingBottom: number
|
||||||
onEndReached?: () => void
|
onEndReached?: () => void
|
||||||
ListHeaderComponent?: ReactElement
|
ListHeaderComponent?: ReactElement
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
|
title?: string
|
||||||
}) {
|
}) {
|
||||||
const tabletLayout = useTabletLayout()
|
const tabletLayout = useTabletLayout()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<MediaItem>>()
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
({ item }: ListRenderItemInfo<MediaItem>) => (
|
({ item }: ListRenderItemInfo<MediaItem>) => (
|
||||||
<View style={{ width: cardWidth }}>
|
<View style={{ width: cardWidth }}>
|
||||||
@@ -328,13 +333,30 @@ export function MediaGridList({
|
|||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
ListHeaderComponent={ListHeaderComponent}
|
ListHeaderComponent={ListHeaderComponent}
|
||||||
contentInset={contentInset}
|
contentInset={contentInset}
|
||||||
|
title={title}
|
||||||
renderCard={renderTabletCard}
|
renderCard={renderTabletCard}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const header = title ? (
|
||||||
|
<View>
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
scrollY={scrollY}
|
||||||
|
// Inset grids already pad the whole list horizontally.
|
||||||
|
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||||
|
/>
|
||||||
|
{ListHeaderComponent}
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
ListHeaderComponent
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
key={columns}
|
key={columns}
|
||||||
onLayout={onLayout}
|
onLayout={onLayout}
|
||||||
data={content}
|
data={content}
|
||||||
@@ -351,6 +373,7 @@ export function MediaGridList({
|
|||||||
paddingBottom,
|
paddingBottom,
|
||||||
gap,
|
gap,
|
||||||
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
||||||
|
...(title ? { paddingTop: 0 } : {}),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
columnWrapperStyle={[
|
columnWrapperStyle={[
|
||||||
@@ -359,7 +382,7 @@ export function MediaGridList({
|
|||||||
{ gap },
|
{ gap },
|
||||||
]}
|
]}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
ListHeaderComponent={ListHeaderComponent}
|
ListHeaderComponent={header}
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -77,44 +77,39 @@ const QUEUE_ACTIONS: MediaAction[] = ["play-next", "play-last", "shuffle"]
|
|||||||
|
|
||||||
const MEDIA_ACTION_ITEMS: {
|
const MEDIA_ACTION_ITEMS: {
|
||||||
action: MediaAction
|
action: MediaAction
|
||||||
label: (
|
label: (favorited: boolean | undefined, playlistLabel: string) => string
|
||||||
countSuffix: string,
|
|
||||||
favorited: boolean | undefined,
|
|
||||||
playlistLabel: string
|
|
||||||
) => string
|
|
||||||
image: NonNullable<MenuAction["image"]> & string
|
image: NonNullable<MenuAction["image"]> & string
|
||||||
destructive?: boolean
|
destructive?: boolean
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
action: "playlist",
|
action: "playlist",
|
||||||
label: (countSuffix, _favorited, playlistLabel) =>
|
label: (_favorited, playlistLabel) => playlistLabel,
|
||||||
`${playlistLabel}${countSuffix}`,
|
|
||||||
image: "text.badge.plus",
|
image: "text.badge.plus",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "download",
|
action: "download",
|
||||||
label: (countSuffix) => `Download${countSuffix}`,
|
label: () => "Download",
|
||||||
image: "arrow.down.circle",
|
image: "arrow.down.circle",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "remove-download",
|
action: "remove-download",
|
||||||
label: (countSuffix) => `Remove Download${countSuffix}`,
|
label: () => "Remove Download",
|
||||||
image: "xmark.circle",
|
image: "xmark.circle",
|
||||||
destructive: true,
|
destructive: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "play-next",
|
action: "play-next",
|
||||||
label: (countSuffix) => `Play Next${countSuffix}`,
|
label: () => "Play Next",
|
||||||
image: "text.line.first.and.arrowtriangle.forward",
|
image: "text.line.first.and.arrowtriangle.forward",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "play-last",
|
action: "play-last",
|
||||||
label: (countSuffix) => `Play Last${countSuffix}`,
|
label: () => "Play Last",
|
||||||
image: "text.line.last.and.arrowtriangle.forward",
|
image: "text.line.last.and.arrowtriangle.forward",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "shuffle",
|
action: "shuffle",
|
||||||
label: (countSuffix) => `Shuffle${countSuffix}`,
|
label: () => "Shuffle",
|
||||||
image: "shuffle",
|
image: "shuffle",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -134,8 +129,7 @@ const MEDIA_ACTION_ITEMS: {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "favorite",
|
action: "favorite",
|
||||||
label: (countSuffix, favorited) =>
|
label: (favorited) => (favorited ? "Unfavorite" : "Favorite"),
|
||||||
`${favorited ? "Unfavorite" : "Favorite"}${countSuffix}`,
|
|
||||||
image: "star",
|
image: "star",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -206,12 +200,7 @@ function isActionIncluded(
|
|||||||
export function buildMediaMenuActions(
|
export function buildMediaMenuActions(
|
||||||
config: Omit<MediaMenuConfig, "onAction">
|
config: Omit<MediaMenuConfig, "onAction">
|
||||||
): MenuAction[] {
|
): MenuAction[] {
|
||||||
const {
|
const { favorited, playlistLabel = "Add to Playlist" } = config
|
||||||
selectedCount = 1,
|
|
||||||
favorited,
|
|
||||||
playlistLabel = "Add to Playlist",
|
|
||||||
} = config
|
|
||||||
const countSuffix = selectedCount > 1 ? ` (${selectedCount})` : ""
|
|
||||||
|
|
||||||
const actions: MenuAction[] = []
|
const actions: MenuAction[] = []
|
||||||
|
|
||||||
@@ -230,7 +219,7 @@ export function buildMediaMenuActions(
|
|||||||
|
|
||||||
actions.push({
|
actions.push({
|
||||||
id: item.action,
|
id: item.action,
|
||||||
title: item.label(countSuffix, favorited, playlistLabel),
|
title: item.label(favorited, playlistLabel),
|
||||||
image: item.action === "favorite" && favorited ? "star.fill" : item.image,
|
image: item.action === "favorite" && favorited ? "star.fill" : item.image,
|
||||||
...(item.destructive ? { attributes: { destructive: true } } : {}),
|
...(item.destructive ? { attributes: { destructive: true } } : {}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "@/contexts/downloads"
|
} from "@/contexts/downloads"
|
||||||
import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import type { BrowseSong } from "@otunes/convex/types"
|
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
||||||
import type { CoverPalette } from "@/lib/cover-palette"
|
import type { CoverPalette } from "@/lib/cover-palette"
|
||||||
import { formatDuration } from "@/lib/format"
|
import { formatDuration } from "@/lib/format"
|
||||||
import { albumCoverUrl } from "@/lib/urls"
|
import { albumCoverUrl } from "@/lib/urls"
|
||||||
@@ -41,7 +41,8 @@ export const SongRow = memo(function SongRow({
|
|||||||
swipe,
|
swipe,
|
||||||
downloadFrom,
|
downloadFrom,
|
||||||
}: {
|
}: {
|
||||||
song: BrowseSong
|
/** Search results also show the lyrics line they matched. */
|
||||||
|
song: SearchSong
|
||||||
onPress?: () => void
|
onPress?: () => void
|
||||||
contextMenu?: Omit<MediaMenuConfig, "onAction"> & {
|
contextMenu?: Omit<MediaMenuConfig, "onAction"> & {
|
||||||
onAction: MediaMenuConfig["onAction"]
|
onAction: MediaMenuConfig["onAction"]
|
||||||
@@ -87,6 +88,14 @@ export const SongRow = memo(function SongRow({
|
|||||||
>
|
>
|
||||||
{song.artist.name} · {song.album.title}
|
{song.artist.name} · {song.album.title}
|
||||||
</Text>
|
</Text>
|
||||||
|
{song.lyricsSnippet ? (
|
||||||
|
<Text
|
||||||
|
style={[styles.rowSubtitle, { color: secondaryForeground }]}
|
||||||
|
numberOfLines={1}
|
||||||
|
>
|
||||||
|
Lyrics: “{song.lyricsSnippet}”
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
{downloaded || downloadState === "device" ? (
|
{downloaded || downloadState === "device" ? (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
@@ -181,7 +190,7 @@ export const SongListRow = memo(function SongListRow({
|
|||||||
onPlay,
|
onPlay,
|
||||||
onAction,
|
onAction,
|
||||||
}: {
|
}: {
|
||||||
song: BrowseSong
|
song: SearchSong
|
||||||
favorited: boolean
|
favorited: boolean
|
||||||
playlistLabel?: string
|
playlistLabel?: string
|
||||||
palette?: Pick<CoverPalette, "foreground" | "secondaryForeground" | "divider">
|
palette?: Pick<CoverPalette, "foreground" | "secondaryForeground" | "divider">
|
||||||
|
|||||||
@@ -2,16 +2,23 @@ import { useCallback, useMemo } from "react"
|
|||||||
import { Platform } from "react-native"
|
import { Platform } from "react-native"
|
||||||
import { Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
|
|
||||||
|
import { useQuery } from "convex/react"
|
||||||
|
|
||||||
import { useDebouncedSearch } from "@/hooks/use-debounced-search"
|
import { useDebouncedSearch } from "@/hooks/use-debounced-search"
|
||||||
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
import { useThemeColors } from "@/lib/theme"
|
import { useThemeColors } from "@/lib/theme"
|
||||||
import { filterSongs } from "@otunes/convex/client/song-search"
|
import { filterSongs } from "@otunes/convex/client/song-search"
|
||||||
import type { BrowseSong } from "@otunes/convex/types"
|
import type { BrowseSong } from "@otunes/convex/types"
|
||||||
|
|
||||||
export function usePlaylistSearch(songs: BrowseSong[]) {
|
export function usePlaylistSearch(songs: BrowseSong[]) {
|
||||||
const search = useDebouncedSearch()
|
const search = useDebouncedSearch()
|
||||||
|
const lyricsMatches = useQuery(
|
||||||
|
api.lyrics.matchingSongIds,
|
||||||
|
search.searchQuery.trim() ? { query: search.searchQuery } : "skip"
|
||||||
|
)
|
||||||
const filteredSongs = useMemo(
|
const filteredSongs = useMemo(
|
||||||
() => filterSongs(songs, search.searchQuery),
|
() => filterSongs(songs, search.searchQuery, lyricsMatches),
|
||||||
[songs, search.searchQuery]
|
[songs, search.searchQuery, lyricsMatches]
|
||||||
)
|
)
|
||||||
|
|
||||||
return { ...search, filteredSongs }
|
return { ...search, filteredSongs }
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||||
|
import type { Component } from "react"
|
||||||
|
import {
|
||||||
|
Platform,
|
||||||
|
StyleSheet,
|
||||||
|
type ScrollViewInstance,
|
||||||
|
type StyleProp,
|
||||||
|
type TextStyle,
|
||||||
|
} from "react-native"
|
||||||
|
import Animated, {
|
||||||
|
useAnimatedRef,
|
||||||
|
useAnimatedStyle,
|
||||||
|
useScrollOffset,
|
||||||
|
type SharedValue,
|
||||||
|
} from "react-native-reanimated"
|
||||||
|
|
||||||
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks the scroll view that renders a `ScreenTitle`. Attach `ref` to that
|
||||||
|
* Reanimated `Animated.ScrollView` / `Animated.FlatList` and pass `scrollY`
|
||||||
|
* to the title.
|
||||||
|
*/
|
||||||
|
export function useScreenTitleScroll<
|
||||||
|
TScrollView extends Component | ScrollViewInstance,
|
||||||
|
>() {
|
||||||
|
const ref = useAnimatedRef<TScrollView>()
|
||||||
|
const scrollY = useScrollOffset(ref)
|
||||||
|
return { ref, scrollY }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iOS screen title rendered as the first item of a screen's scroll content,
|
||||||
|
* in place of the native large title (Apple Music style): it scrolls away
|
||||||
|
* with the content, never collapses into the bar, and stays put on
|
||||||
|
* pull-down. Android keeps its native header title, so this renders nothing.
|
||||||
|
*/
|
||||||
|
export function ScreenTitle({
|
||||||
|
title,
|
||||||
|
scrollY,
|
||||||
|
style,
|
||||||
|
}: {
|
||||||
|
title: string
|
||||||
|
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
||||||
|
scrollY?: SharedValue<number>
|
||||||
|
style?: StyleProp<TextStyle>
|
||||||
|
}) {
|
||||||
|
const colors = useThemeColors()
|
||||||
|
// At rest the scroll offset is minus the automatic header inset, so any
|
||||||
|
// offset below that is overscroll the title should cancel out.
|
||||||
|
const headerHeight = useHeaderHeight()
|
||||||
|
const pinStyle = useAnimatedStyle(() => ({
|
||||||
|
transform: [
|
||||||
|
{
|
||||||
|
translateY: scrollY ? Math.min(0, scrollY.value + headerHeight) : 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (Platform.OS !== "ios") return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.Text
|
||||||
|
accessibilityRole="header"
|
||||||
|
numberOfLines={2}
|
||||||
|
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Animated.Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
title: {
|
||||||
|
fontSize: 34,
|
||||||
|
lineHeight: 41,
|
||||||
|
fontWeight: "700",
|
||||||
|
letterSpacing: 0.37,
|
||||||
|
paddingHorizontal: spacing.lg,
|
||||||
|
paddingTop: 3,
|
||||||
|
paddingBottom: 8,
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import { memo, useCallback, useMemo } from "react"
|
import { memo, useCallback, useMemo } from "react"
|
||||||
import {
|
import {
|
||||||
FlatList,
|
type FlatList,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
type ListRenderItemInfo,
|
type ListRenderItemInfo,
|
||||||
} from "react-native"
|
} from "react-native"
|
||||||
|
import Animated from "react-native-reanimated"
|
||||||
|
|
||||||
import { ContentCarousel } from "@/components/media-cards"
|
import { ContentCarousel } from "@/components/media-cards"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import type { MediaAction } from "@/components/media-context-menu"
|
import type { MediaAction } from "@/components/media-context-menu"
|
||||||
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
||||||
import { SongListSkeleton } from "@/components/skeletons"
|
import { SongListSkeleton } from "@/components/skeletons"
|
||||||
@@ -16,11 +18,19 @@ import { usePlaybackActions } from "@/contexts/playback"
|
|||||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
import type { BrowseSong } from "@otunes/convex/types"
|
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
||||||
import { spacing, useThemeColors } from "@/lib/theme"
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
function SearchResultsBody({
|
||||||
|
searchQuery,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
searchQuery: string
|
||||||
|
/** iOS `ScreenTitle`, shown above the results and while idle. */
|
||||||
|
title: string
|
||||||
|
}) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||||
const { playFromSong } = usePlaybackActions()
|
const { playFromSong } = usePlaybackActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
@@ -64,7 +74,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
[handleSongAction]
|
[handleSongAction]
|
||||||
)
|
)
|
||||||
const renderItem = useCallback(
|
const renderItem = useCallback(
|
||||||
({ item: song }: ListRenderItemInfo<BrowseSong>) => (
|
({ item: song }: ListRenderItemInfo<SearchSong>) => (
|
||||||
<SongListRow
|
<SongListRow
|
||||||
song={song}
|
song={song}
|
||||||
favorited={isSongFavorite(song.id)}
|
favorited={isSongFavorite(song.id)}
|
||||||
@@ -76,16 +86,14 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
return <SongListSkeleton />
|
return <SongListSkeleton title={title} />
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasQuery) {
|
|
||||||
return <></>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
data={results?.songs ?? []}
|
ref={ref}
|
||||||
|
scrollEventThrottle={16}
|
||||||
|
data={hasQuery ? (results?.songs ?? []) : []}
|
||||||
keyExtractor={(song) => song.id}
|
keyExtractor={(song) => song.id}
|
||||||
style={{ flex: 1, backgroundColor: colors.background }}
|
style={{ flex: 1, backgroundColor: colors.background }}
|
||||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||||
@@ -93,7 +101,8 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
ListHeaderComponent={
|
ListHeaderComponent={
|
||||||
<>
|
<>
|
||||||
{!hasResults ? (
|
<ScreenTitle title={title} scrollY={scrollY} />
|
||||||
|
{hasQuery && !hasResults ? (
|
||||||
<View style={styles.empty}>
|
<View style={styles.empty}>
|
||||||
<Text
|
<Text
|
||||||
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
||||||
@@ -103,13 +112,13 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{results?.artists.length ? (
|
{hasQuery && results?.artists.length ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Artists" content={results.artists} />
|
<ContentCarousel title="Artists" content={results.artists} />
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{results?.albums.length ? (
|
{hasQuery && results?.albums.length ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Albums" content={results.albums} />
|
<ContentCarousel title="Albums" content={results.albums} />
|
||||||
</View>
|
</View>
|
||||||
@@ -118,7 +127,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
|||||||
}
|
}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
ListFooterComponent={
|
ListFooterComponent={
|
||||||
playlistResults && playlistResults.length > 0 ? (
|
hasQuery && playlistResults && playlistResults.length > 0 ? (
|
||||||
<View style={styles.section}>
|
<View style={styles.section}>
|
||||||
<ContentCarousel title="Playlists" content={playlistResults} />
|
<ContentCarousel title="Playlists" content={playlistResults} />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
collectionInset,
|
collectionInset,
|
||||||
} from "@/components/collection-list"
|
} from "@/components/collection-list"
|
||||||
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
||||||
|
import { ScreenTitle } from "@/components/screen-title"
|
||||||
import { Link } from "expo-router"
|
import { Link } from "expo-router"
|
||||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||||
import Reanimated from "react-native-reanimated"
|
import Reanimated from "react-native-reanimated"
|
||||||
@@ -151,9 +152,16 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
export function SongListSkeleton({
|
||||||
|
rows = 10,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
rows?: number
|
||||||
|
title?: string
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
|
{title ? <ScreenTitle title={title} /> : null}
|
||||||
<SongRows rows={rows} />
|
<SongRows rows={rows} />
|
||||||
</SkeletonScreen>
|
</SkeletonScreen>
|
||||||
)
|
)
|
||||||
@@ -234,23 +242,45 @@ export function MediaGridSkeleton({
|
|||||||
items = 6,
|
items = 6,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
header,
|
header,
|
||||||
|
title,
|
||||||
}: {
|
}: {
|
||||||
items?: number
|
items?: number
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
||||||
header?: ReactNode
|
header?: ReactNode
|
||||||
|
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||||
|
title?: string
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
<MediaGridContent
|
<MediaGridContent
|
||||||
items={items}
|
items={items}
|
||||||
contentInset={contentInset}
|
contentInset={contentInset && !title}
|
||||||
header={header}
|
header={
|
||||||
|
title ? (
|
||||||
|
<>
|
||||||
|
<MediaGridTitle title={title} />
|
||||||
|
{header}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
header
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</SkeletonScreen>
|
</SkeletonScreen>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MediaGridTitle({ title }: { title: string }) {
|
||||||
|
const { horizontalPadding } = useMediaGridLayout()
|
||||||
|
return (
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
style={{ paddingHorizontal: horizontalPadding }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function CarouselSkeleton() {
|
export function CarouselSkeleton() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.carousel}>
|
<View style={styles.carousel}>
|
||||||
@@ -264,10 +294,11 @@ export function CarouselSkeleton() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HomeSkeleton() {
|
export function HomeSkeleton({ title }: { title: string }) {
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
<View style={styles.home}>
|
<View style={styles.home}>
|
||||||
|
<ScreenTitle title={title} style={styles.homeTitle} />
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
<CarouselSkeleton />
|
<CarouselSkeleton />
|
||||||
</View>
|
</View>
|
||||||
@@ -388,10 +419,17 @@ export function CollectionDetailSkeleton({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
export function ArtistListSkeleton({
|
||||||
|
rows = 12,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
rows?: number
|
||||||
|
title?: string
|
||||||
|
}) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
return (
|
return (
|
||||||
<SkeletonScreen>
|
<SkeletonScreen>
|
||||||
|
{title ? <ScreenTitle title={title} /> : null}
|
||||||
{Array.from({ length: rows }, (_, index) => (
|
{Array.from({ length: rows }, (_, index) => (
|
||||||
<View
|
<View
|
||||||
key={index}
|
key={index}
|
||||||
@@ -456,6 +494,12 @@ const styles = StyleSheet.create({
|
|||||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||||
home: { padding: spacing.lg, gap: spacing.xl },
|
home: { padding: spacing.lg, gap: spacing.xl },
|
||||||
|
// Mirrors the home screen's title spacing.
|
||||||
|
homeTitle: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
marginTop: -spacing.lg,
|
||||||
|
marginBottom: -spacing.md,
|
||||||
|
},
|
||||||
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
centeredHero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||||
actions: {
|
actions: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
type ReactElement,
|
type ReactElement,
|
||||||
} from "react"
|
} from "react"
|
||||||
import {
|
import {
|
||||||
ScrollView,
|
type ScrollViewInstance,
|
||||||
View,
|
View,
|
||||||
type NativeSyntheticEvent,
|
type NativeSyntheticEvent,
|
||||||
type NativeScrollEvent,
|
type NativeScrollEvent,
|
||||||
@@ -15,6 +15,7 @@ import Animated from "react-native-reanimated"
|
|||||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||||
|
|
||||||
import type { MediaItem } from "@/components/media-cards"
|
import type { MediaItem } from "@/components/media-cards"
|
||||||
|
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||||
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||||
import { useThemeColors } from "@/lib/theme"
|
import { useThemeColors } from "@/lib/theme"
|
||||||
@@ -28,6 +29,8 @@ type GridProps = {
|
|||||||
onEndReached?: () => void
|
onEndReached?: () => void
|
||||||
ListHeaderComponent?: ReactElement
|
ListHeaderComponent?: ReactElement
|
||||||
contentInset?: boolean
|
contentInset?: boolean
|
||||||
|
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||||
|
title?: string
|
||||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +44,12 @@ export function TabletMediaGrid({
|
|||||||
onEndReached,
|
onEndReached,
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
contentInset = true,
|
contentInset = true,
|
||||||
|
title,
|
||||||
renderCard,
|
renderCard,
|
||||||
}: GridProps) {
|
}: GridProps) {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
|
const { ref, scrollY: titleScrollY } =
|
||||||
|
useScreenTitleScroll<ScrollViewInstance>()
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
||||||
useMediaGridLayout()
|
useMediaGridLayout()
|
||||||
@@ -102,18 +108,27 @@ export function TabletMediaGrid({
|
|||||||
setViewportHeight(event.nativeEvent.layout.height)
|
setViewportHeight(event.nativeEvent.layout.height)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ScrollView
|
<Animated.ScrollView
|
||||||
|
ref={ref}
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
scrollEventThrottle={32}
|
// Every frame, so the title pins smoothly on pull-down.
|
||||||
|
scrollEventThrottle={16}
|
||||||
contentInsetAdjustmentBehavior="automatic"
|
contentInsetAdjustmentBehavior="automatic"
|
||||||
contentContainerStyle={{
|
contentContainerStyle={{
|
||||||
paddingTop: contentInset ? horizontalPadding : 0,
|
paddingTop: contentInset && !title ? horizontalPadding : 0,
|
||||||
paddingBottom: paddingBottom + insets.bottom,
|
paddingBottom: paddingBottom + insets.bottom,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
||||||
>
|
>
|
||||||
|
{title ? (
|
||||||
|
<ScreenTitle
|
||||||
|
title={title}
|
||||||
|
scrollY={titleScrollY}
|
||||||
|
style={{ paddingHorizontal: horizontalPadding }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
{ListHeaderComponent}
|
{ListHeaderComponent}
|
||||||
</View>
|
</View>
|
||||||
<View style={{ height: gridHeight }}>
|
<View style={{ height: gridHeight }}>
|
||||||
@@ -136,7 +151,7 @@ export function TabletMediaGrid({
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</Animated.ScrollView>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@ import { PlayerSymbol } from "@/components/player-symbol"
|
|||||||
import { useFavorites } from "@/contexts/favorites"
|
import { useFavorites } from "@/contexts/favorites"
|
||||||
import { usePlaybackActions, usePlaybackQueue } from "@/contexts/playback"
|
import { usePlaybackActions, usePlaybackQueue } from "@/contexts/playback"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
|
import { useLyrics } from "@/hooks/use-lyrics"
|
||||||
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
||||||
import { tabletMiniPlayerHeight } from "@/lib/theme"
|
import { tabletMiniPlayerHeight } from "@/lib/theme"
|
||||||
import { albumCoverUrl } from "@/lib/urls"
|
import { albumCoverUrl } from "@/lib/urls"
|
||||||
@@ -58,6 +59,7 @@ export function TabletMiniPlayer() {
|
|||||||
const { handleSongAction } = useMediaMenuActions()
|
const { handleSongAction } = useMediaMenuActions()
|
||||||
const { isSongFavorite } = useFavorites()
|
const { isSongFavorite } = useFavorites()
|
||||||
const roomy = width - insets.left - insets.right >= 650
|
const roomy = width - insets.left - insets.right >= 650
|
||||||
|
const lyrics = useLyrics(roomy ? (currentSong?.id ?? null) : null)
|
||||||
|
|
||||||
if (!focused || !config || !currentSong || queueSongIds.length === 0)
|
if (!focused || !config || !currentSong || queueSongIds.length === 0)
|
||||||
return null
|
return null
|
||||||
@@ -166,16 +168,22 @@ export function TabletMiniPlayer() {
|
|||||||
{roomy ? (
|
{roomy ? (
|
||||||
<Pressable
|
<Pressable
|
||||||
style={styles.control}
|
style={styles.control}
|
||||||
disabled
|
disabled={!lyrics}
|
||||||
|
onPress={() =>
|
||||||
|
router.push({
|
||||||
|
pathname: "/(app)/player",
|
||||||
|
params: { lyrics: "1" },
|
||||||
|
})
|
||||||
|
}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Lyrics"
|
accessibilityLabel="Show lyrics"
|
||||||
accessibilityState={{ disabled: true }}
|
accessibilityState={{ disabled: !lyrics }}
|
||||||
>
|
>
|
||||||
<PlayerSymbol
|
<PlayerSymbol
|
||||||
name="quote.bubble"
|
name="quote.bubble"
|
||||||
fallback="chatbox-outline"
|
fallback="chatbox-outline"
|
||||||
size={23}
|
size={23}
|
||||||
color={inactive}
|
color={lyrics ? color : inactive}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { StatusBar } from "expo-status-bar"
|
|||||||
|
|
||||||
import { AudioOutputButton } from "@/components/audio-output-button"
|
import { AudioOutputButton } from "@/components/audio-output-button"
|
||||||
import { CoverImage } from "@/components/cover-image"
|
import { CoverImage } from "@/components/cover-image"
|
||||||
|
import { LyricsView } from "@/components/lyrics-view"
|
||||||
import { NowPlayingQueue } from "@/components/now-playing-queue"
|
import { NowPlayingQueue } from "@/components/now-playing-queue"
|
||||||
import { PlayerProgress } from "@/components/player-progress"
|
import { PlayerProgress } from "@/components/player-progress"
|
||||||
import { PlayerSlider } from "@/components/player-slider"
|
import { PlayerSlider } from "@/components/player-slider"
|
||||||
@@ -24,6 +25,10 @@ import { useServerConfig } from "@/contexts/server-config"
|
|||||||
import { useSystemVolume } from "@/hooks/use-system-volume"
|
import { useSystemVolume } from "@/hooks/use-system-volume"
|
||||||
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||||
import { albumCoverUrl } from "@/lib/urls"
|
import { albumCoverUrl } from "@/lib/urls"
|
||||||
|
import type { Lyrics } from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
|
/** What the Now Playing screen shows beside or instead of the artwork. */
|
||||||
|
export type PlayerPanel = "queue" | "lyrics"
|
||||||
|
|
||||||
const queueMotion = {
|
const queueMotion = {
|
||||||
duration: 420,
|
duration: 420,
|
||||||
@@ -31,14 +36,18 @@ const queueMotion = {
|
|||||||
reduceMotion: ReduceMotion.System,
|
reduceMotion: ReduceMotion.System,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tablet player keeps transport controls visible while the queue opens beside them. */
|
/**
|
||||||
|
* Tablet player keeps transport controls visible while the queue or lyrics
|
||||||
|
* open beside them.
|
||||||
|
*/
|
||||||
export function TabletNowPlaying({
|
export function TabletNowPlaying({
|
||||||
colors,
|
colors,
|
||||||
backgroundStyle,
|
backgroundStyle,
|
||||||
dismissStyle,
|
dismissStyle,
|
||||||
dismissGestures,
|
dismissGestures,
|
||||||
showQueue,
|
panel,
|
||||||
toggleQueue,
|
togglePanel,
|
||||||
|
lyrics,
|
||||||
metadata,
|
metadata,
|
||||||
}: {
|
}: {
|
||||||
colors: NowPlayingColors
|
colors: NowPlayingColors
|
||||||
@@ -48,8 +57,9 @@ export function TabletNowPlaying({
|
|||||||
handle: ReturnType<typeof Gesture.Pan>
|
handle: ReturnType<typeof Gesture.Pan>
|
||||||
artwork: ReturnType<typeof Gesture.Pan>
|
artwork: ReturnType<typeof Gesture.Pan>
|
||||||
}
|
}
|
||||||
showQueue: boolean
|
panel: PlayerPanel | null
|
||||||
toggleQueue: () => void
|
togglePanel: (panel: PlayerPanel) => void
|
||||||
|
lyrics: Lyrics | null | undefined
|
||||||
metadata: ReactNode
|
metadata: ReactNode
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -63,7 +73,9 @@ export function TabletNowPlaying({
|
|||||||
const { volume, setVolume, available: volumeAvailable } = useSystemVolume()
|
const { volume, setVolume, available: volumeAvailable } = useSystemVolume()
|
||||||
const [queueHeight, setQueueHeight] = useState(0)
|
const [queueHeight, setQueueHeight] = useState(0)
|
||||||
const wideLayout = width >= 700
|
const wideLayout = width >= 700
|
||||||
const sideBySide = showQueue && wideLayout
|
const showQueue = panel === "queue"
|
||||||
|
const showLyrics = panel === "lyrics"
|
||||||
|
const sideBySide = panel !== null && wideLayout
|
||||||
const progress = useSharedValue(sideBySide ? 1 : 0)
|
const progress = useSharedValue(sideBySide ? 1 : 0)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
progress.value = withTiming(sideBySide ? 1 : 0, queueMotion)
|
progress.value = withTiming(sideBySide ? 1 : 0, queueMotion)
|
||||||
@@ -124,7 +136,14 @@ export function TabletNowPlaying({
|
|||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
const queue = (
|
const panelContent = showLyrics ? (
|
||||||
|
<LyricsView
|
||||||
|
key={currentSong.id}
|
||||||
|
lyrics={lyrics}
|
||||||
|
colors={colors}
|
||||||
|
fontSize={34}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<NowPlayingQueue
|
<NowPlayingQueue
|
||||||
tablet
|
tablet
|
||||||
colors={colors}
|
colors={colors}
|
||||||
@@ -241,20 +260,18 @@ export function TabletNowPlaying({
|
|||||||
</Animated.View>
|
</Animated.View>
|
||||||
{wideLayout ? (
|
{wideLayout ? (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
pointerEvents={showQueue ? "auto" : "none"}
|
pointerEvents={panel ? "auto" : "none"}
|
||||||
accessibilityElementsHidden={!showQueue}
|
accessibilityElementsHidden={!panel}
|
||||||
importantForAccessibility={
|
importantForAccessibility={panel ? "auto" : "no-hide-descendants"}
|
||||||
showQueue ? "auto" : "no-hide-descendants"
|
|
||||||
}
|
|
||||||
style={[styles.queue, queueStyle]}
|
style={[styles.queue, queueStyle]}
|
||||||
onLayout={(event) =>
|
onLayout={(event) =>
|
||||||
setQueueHeight(event.nativeEvent.layout.height)
|
setQueueHeight(event.nativeEvent.layout.height)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{queueHeight > 0 ? queue : null}
|
{queueHeight > 0 ? panelContent : null}
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
) : null}
|
) : null}
|
||||||
{showQueue && !sideBySide ? (
|
{panel && !sideBySide ? (
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
styles.portraitQueue,
|
styles.portraitQueue,
|
||||||
@@ -264,7 +281,7 @@ export function TabletNowPlaying({
|
|||||||
setQueueHeight(event.nativeEvent.layout.height)
|
setQueueHeight(event.nativeEvent.layout.height)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{queueHeight > 0 ? queue : null}
|
{queueHeight > 0 ? panelContent : null}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
@@ -280,21 +297,29 @@ export function TabletNowPlaying({
|
|||||||
/>
|
/>
|
||||||
<View style={styles.footerActions}>
|
<View style={styles.footerActions}>
|
||||||
<Pressable
|
<Pressable
|
||||||
disabled
|
onPress={() => togglePanel("lyrics")}
|
||||||
|
disabled={!lyrics && !showLyrics}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Lyrics"
|
accessibilityLabel={showLyrics ? "Hide lyrics" : "Show lyrics"}
|
||||||
accessibilityState={{ disabled: true }}
|
accessibilityState={{
|
||||||
style={[styles.footerButton, { opacity: 0.4 }]}
|
selected: showLyrics,
|
||||||
|
disabled: !lyrics && !showLyrics,
|
||||||
|
}}
|
||||||
|
style={[
|
||||||
|
styles.footerButton,
|
||||||
|
!lyrics && !showLyrics && { opacity: 0.4 },
|
||||||
|
showLyrics && { backgroundColor: colors.selected },
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<PlayerSymbol
|
<PlayerSymbol
|
||||||
name="quote.bubble"
|
name="quote.bubble"
|
||||||
fallback="chatbox-outline"
|
fallback="chatbox-outline"
|
||||||
size={25}
|
size={25}
|
||||||
color={colors.foreground}
|
color={showLyrics ? colors.selectedForeground : colors.foreground}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={toggleQueue}
|
onPress={() => togglePanel("queue")}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={showQueue ? "Hide queue" : "Show queue"}
|
accessibilityLabel={showQueue ? "Hide queue" : "Show queue"}
|
||||||
accessibilityState={{ selected: showQueue }}
|
accessibilityState={{ selected: showQueue }}
|
||||||
|
|||||||
@@ -198,7 +198,8 @@ function optionDetail(option: SizedDownloadOption, songCount: number) {
|
|||||||
return `${included} of ${songCount} songs, ${option.fallbackCount} in High`
|
return `${included} of ${songCount} songs, ${option.fallbackCount} in High`
|
||||||
}
|
}
|
||||||
|
|
||||||
function DownloadQualitySheet({
|
/** Centered popup asking which quality to download a target at. */
|
||||||
|
function DownloadQualityPopup({
|
||||||
pending,
|
pending,
|
||||||
onClose,
|
onClose,
|
||||||
onPick,
|
onPick,
|
||||||
@@ -214,7 +215,7 @@ function DownloadQualitySheet({
|
|||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={pending !== null}
|
visible={pending !== null}
|
||||||
animationType="slide"
|
animationType="fade"
|
||||||
transparent
|
transparent
|
||||||
onRequestClose={onClose}
|
onRequestClose={onClose}
|
||||||
>
|
>
|
||||||
@@ -222,14 +223,11 @@ function DownloadQualitySheet({
|
|||||||
<Pressable style={styles.overlay} onPress={onClose}>
|
<Pressable style={styles.overlay} onPress={onClose}>
|
||||||
<Pressable
|
<Pressable
|
||||||
style={[
|
style={[
|
||||||
styles.sheet,
|
styles.popup,
|
||||||
{ backgroundColor: colors.card, borderColor: colors.border },
|
{ backgroundColor: colors.card, borderColor: colors.border },
|
||||||
]}
|
]}
|
||||||
onPress={(event) => event.stopPropagation()}
|
onPress={(event) => event.stopPropagation()}
|
||||||
>
|
>
|
||||||
<View
|
|
||||||
style={[styles.grabber, { backgroundColor: colors.border }]}
|
|
||||||
/>
|
|
||||||
<Text style={[styles.title, { color: colors.foreground }]}>
|
<Text style={[styles.title, { color: colors.foreground }]}>
|
||||||
Download Quality
|
Download Quality
|
||||||
</Text>
|
</Text>
|
||||||
@@ -433,7 +431,7 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
<DownloadsContext.Provider value={value}>
|
<DownloadsContext.Provider value={value}>
|
||||||
{children}
|
{children}
|
||||||
{queue ? <DownloadSync queue={queue} /> : null}
|
{queue ? <DownloadSync queue={queue} /> : null}
|
||||||
<DownloadQualitySheet
|
<DownloadQualityPopup
|
||||||
pending={pending}
|
pending={pending}
|
||||||
onClose={() => setPending(null)}
|
onClose={() => setPending(null)}
|
||||||
onPick={handlePick}
|
onPick={handlePick}
|
||||||
@@ -445,23 +443,17 @@ export function DownloadsProvider({ children }: { children: ReactNode }) {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
overlay: {
|
overlay: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: "rgba(0,0,0,0.45)",
|
backgroundColor: "rgba(0,0,0,0.6)",
|
||||||
justifyContent: "flex-end",
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
padding: 24,
|
||||||
},
|
},
|
||||||
sheet: {
|
popup: {
|
||||||
borderTopLeftRadius: 16,
|
width: "100%",
|
||||||
borderTopRightRadius: 16,
|
maxWidth: 420,
|
||||||
|
borderRadius: 16,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
paddingHorizontal: 16,
|
padding: 16,
|
||||||
paddingTop: 8,
|
|
||||||
paddingBottom: 24,
|
|
||||||
},
|
|
||||||
grabber: {
|
|
||||||
width: 36,
|
|
||||||
height: 4,
|
|
||||||
borderRadius: 2,
|
|
||||||
alignSelf: "center",
|
|
||||||
marginBottom: 12,
|
|
||||||
},
|
},
|
||||||
title: { fontSize: 18, fontWeight: "700" },
|
title: { fontSize: 18, fontWeight: "700" },
|
||||||
subtitle: { fontSize: 13, marginBottom: 4 },
|
subtitle: { fontSize: 13, marginBottom: 4 },
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
"APP_VARIANT": "development"
|
"APP_VARIANT": "development"
|
||||||
},
|
},
|
||||||
"developmentClient": true,
|
"developmentClient": true,
|
||||||
"distribution": "internal"
|
"distribution": "internal",
|
||||||
|
"credentialsSource": "local"
|
||||||
},
|
},
|
||||||
"preview": {
|
"preview": {
|
||||||
"env": {
|
"env": {
|
||||||
"APP_VARIANT": "preview"
|
"APP_VARIANT": "preview"
|
||||||
},
|
},
|
||||||
"distribution": "internal"
|
"distribution": "internal",
|
||||||
|
"credentialsSource": "local"
|
||||||
},
|
},
|
||||||
"production": {
|
"production": {
|
||||||
"env": {
|
"env": {
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import { File } from "expo-file-system"
|
||||||
|
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
||||||
|
|
||||||
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
|
import {
|
||||||
|
followLyrics,
|
||||||
|
parseLyrics,
|
||||||
|
type Lyrics,
|
||||||
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
import { readLyricsTag } from "@otunes/convex/client/lyrics-tags"
|
||||||
|
import { useDownloads } from "@/contexts/downloads"
|
||||||
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
|
import { downloadedAudioUri } from "@/lib/downloads"
|
||||||
|
|
||||||
|
// Lyrics read from downloaded files, by file. Files do not change once saved.
|
||||||
|
const localLyrics = new Map<string, Promise<string | null>>()
|
||||||
|
|
||||||
|
async function readFileLyrics(uri: string) {
|
||||||
|
const handle = new File(uri).open()
|
||||||
|
try {
|
||||||
|
const text = await readLyricsTag({
|
||||||
|
size: handle.size ?? 0,
|
||||||
|
read: (offset, length) => {
|
||||||
|
handle.offset = offset
|
||||||
|
return handle.readBytes(length)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return text?.trim() || null
|
||||||
|
} finally {
|
||||||
|
handle.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readLocalLyrics(uri: string) {
|
||||||
|
let lyrics = localLyrics.get(uri)
|
||||||
|
if (!lyrics) {
|
||||||
|
lyrics = readFileLyrics(uri).catch(() => null)
|
||||||
|
localLyrics.set(uri, lyrics)
|
||||||
|
}
|
||||||
|
return lyrics
|
||||||
|
}
|
||||||
|
|
||||||
|
const noopSubscribe = () => () => {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A song's lyrics: from its downloaded file when there is one, otherwise from
|
||||||
|
* the server. `undefined` while loading, `null` when the song has none.
|
||||||
|
*/
|
||||||
|
export function useLyrics(songId: Id<"songs"> | null) {
|
||||||
|
const { config } = useServerConfig()
|
||||||
|
const { queue } = useDownloads()
|
||||||
|
const fileUri = useSyncExternalStore(queue?.subscribe ?? noopSubscribe, () =>
|
||||||
|
songId && config && queue?.getDownloaded(songId)
|
||||||
|
? downloadedAudioUri(config, songId)
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
const [local, setLocal] = useState<{ uri: string; text: string | null }>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!fileUri) return
|
||||||
|
let current = true
|
||||||
|
void readLocalLyrics(fileUri).then((text) => {
|
||||||
|
if (current) setLocal({ uri: fileUri, text })
|
||||||
|
})
|
||||||
|
return () => {
|
||||||
|
current = false
|
||||||
|
}
|
||||||
|
}, [fileUri])
|
||||||
|
|
||||||
|
const localText = fileUri && local?.uri === fileUri ? local.text : undefined
|
||||||
|
// Songs without a downloaded copy, or whose copy has no lyrics tag.
|
||||||
|
const remote = useCachedQuery(
|
||||||
|
api.lyrics.forSong,
|
||||||
|
songId && (!fileUri || localText === null) ? { id: songId } : "skip"
|
||||||
|
)
|
||||||
|
const text = localText || remote
|
||||||
|
|
||||||
|
return useMemo<Lyrics | null | undefined>(() => {
|
||||||
|
if (!songId) return null
|
||||||
|
if (text === undefined) return undefined
|
||||||
|
return text ? parseLyrics(text) : null
|
||||||
|
}, [songId, text])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The playback time for highlighting lyrics: the player's `currentTime`,
|
||||||
|
* advanced by `followLyrics` between its progress updates.
|
||||||
|
*/
|
||||||
|
export function useLyricsTime(
|
||||||
|
lyrics: Lyrics | null | undefined,
|
||||||
|
currentTime: number,
|
||||||
|
isPlaying: boolean
|
||||||
|
) {
|
||||||
|
// Time reached since the player last reported `from`.
|
||||||
|
const [advanced, setAdvanced] = useState<{ from: number; time: number }>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!lyrics || !isPlaying) return
|
||||||
|
return followLyrics(lyrics, currentTime, (time) =>
|
||||||
|
setAdvanced({ from: currentTime, time })
|
||||||
|
)
|
||||||
|
}, [lyrics, currentTime, isPlaying])
|
||||||
|
|
||||||
|
return isPlaying && advanced?.from === currentTime
|
||||||
|
? advanced.time
|
||||||
|
: currentTime
|
||||||
|
}
|
||||||
@@ -17,13 +17,20 @@ export const tabStackScreenTitles: Record<string, string> = {
|
|||||||
"downloads/other": "Other Downloaded Songs",
|
"downloads/other": "Other Downloaded Songs",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iOS tab stacks render their titles in the scroll content with
|
||||||
|
* `ScreenTitle`, so the bar keeps the title (for back menus) but hides it.
|
||||||
|
*/
|
||||||
|
export const inlineTitleOptions: StackScreenOptions =
|
||||||
|
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
|
||||||
|
|
||||||
export function useStackScreenOptions(
|
export function useStackScreenOptions(
|
||||||
overrides?: StackScreenOptions
|
overrides?: StackScreenOptions
|
||||||
): StackScreenOptions {
|
): StackScreenOptions {
|
||||||
const theme = useThemeColors()
|
const theme = useThemeColors()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
headerLargeTitle: true,
|
headerLargeTitle: false,
|
||||||
headerTransparent: true,
|
headerTransparent: true,
|
||||||
headerTintColor: theme.foreground,
|
headerTintColor: theme.foreground,
|
||||||
headerLargeTitleStyle: { color: theme.foreground },
|
headerLargeTitleStyle: { color: theme.foreground },
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ export type NowPlayingColors = {
|
|||||||
selected: string
|
selected: string
|
||||||
selectedForeground: string
|
selectedForeground: string
|
||||||
highlight: string
|
highlight: string
|
||||||
|
/** Lyrics lines other than the one playing. */
|
||||||
|
lyricsInactive: string
|
||||||
|
/** Words of the playing line not yet sung. */
|
||||||
|
lyricsUnsung: string
|
||||||
isDark: boolean
|
isDark: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +32,8 @@ export function nowPlayingColors(palette: CoverPalette): NowPlayingColors {
|
|||||||
selected: withAlpha(foreground, 0.8),
|
selected: withAlpha(foreground, 0.8),
|
||||||
selectedForeground: palette.background,
|
selectedForeground: palette.background,
|
||||||
highlight: withAlpha(foreground, 0.1),
|
highlight: withAlpha(foreground, 0.1),
|
||||||
|
lyricsInactive: withAlpha(foreground, 0.35),
|
||||||
|
lyricsUnsung: withAlpha(foreground, 0.55),
|
||||||
isDark: palette.isDark,
|
isDark: palette.isDark,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ export const tabletSections = [
|
|||||||
{ name: "albums", group: "(albums)", title: "Albums" },
|
{ name: "albums", group: "(albums)", title: "Albums" },
|
||||||
{ name: "artists", group: "(artists)", title: "Artists" },
|
{ name: "artists", group: "(artists)", title: "Artists" },
|
||||||
{ name: "songs", group: "(songs)", title: "Songs" },
|
{ name: "songs", group: "(songs)", title: "Songs" },
|
||||||
|
{ name: "downloads", group: "(downloads)", title: "Downloads" },
|
||||||
{ name: "playlists", group: "(playlists)", title: "All Playlists" },
|
{ name: "playlists", group: "(playlists)", title: "All Playlists" },
|
||||||
{ name: "favorites", group: "(favorites)", title: "Favorites" },
|
{ name: "favorites", group: "(favorites)", title: "Favorites" },
|
||||||
{ name: "recent", group: "(recent)", title: "Recently Played" },
|
{ name: "recent", group: "(recent)", title: "Recently Played" },
|
||||||
{ name: "downloads", group: "(downloads)", title: "Downloads" },
|
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
export const TabletSectionContext = createContext<
|
export const TabletSectionContext = createContext<
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { audioInfo } from "@/lib/server-audio-info"
|
|||||||
import { streamFile } from "@/lib/server-audio-stream"
|
import { streamFile } from "@/lib/server-audio-stream"
|
||||||
import { spawnFfmpeg } from "@/lib/server-ffmpeg"
|
import { spawnFfmpeg } from "@/lib/server-ffmpeg"
|
||||||
import { seekableLosslessFile } from "@/lib/server-lossless"
|
import { seekableLosslessFile } from "@/lib/server-lossless"
|
||||||
import { getSongSource } from "@/lib/server-song"
|
import { getSongLyrics, getSongSource } from "@/lib/server-song"
|
||||||
import { NextRequest, NextResponse, userAgent } from "next/server"
|
import { NextRequest, NextResponse, userAgent } from "next/server"
|
||||||
import fs from "node:fs/promises"
|
import fs from "node:fs/promises"
|
||||||
import os from "node:os"
|
import os from "node:os"
|
||||||
@@ -40,9 +40,14 @@ async function fileResponse(songId: string, file: string, contentType: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Longest lyrics passed to ffmpeg; Linux caps one argument at 128 KiB. */
|
||||||
|
const MAX_LYRICS_ARGUMENT_BYTES = 100 * 1024
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transcodes to an AAC .m4a with its index up front, so the saved file has a
|
* Transcodes to an AAC .m4a with its index up front, so the saved file has a
|
||||||
* duration and seeks offline. The temporary file is removed once sent.
|
* duration and seeks offline. Tags carry over, and the stored lyrics are
|
||||||
|
* written too, since ffmpeg drops some formats' lyrics tags (like MP3 USLT)
|
||||||
|
* when writing MP4. The temporary file is removed once sent.
|
||||||
*/
|
*/
|
||||||
async function transcodeResponse(
|
async function transcodeResponse(
|
||||||
songId: string,
|
songId: string,
|
||||||
@@ -50,6 +55,11 @@ async function transcodeResponse(
|
|||||||
kbps: number,
|
kbps: number,
|
||||||
signal: AbortSignal
|
signal: AbortSignal
|
||||||
) {
|
) {
|
||||||
|
const lyrics = await getSongLyrics(songId)
|
||||||
|
const lyricsArgs =
|
||||||
|
lyrics && Buffer.byteLength(lyrics) <= MAX_LYRICS_ARGUMENT_BYTES
|
||||||
|
? ["-metadata", `lyrics=${lyrics}`]
|
||||||
|
: []
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "otunes-download-"))
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "otunes-download-"))
|
||||||
const output = path.join(dir, "audio.m4a")
|
const output = path.join(dir, "audio.m4a")
|
||||||
const cleanup = () => fs.rm(dir, { recursive: true, force: true })
|
const cleanup = () => fs.rm(dir, { recursive: true, force: true })
|
||||||
@@ -64,6 +74,7 @@ async function transcodeResponse(
|
|||||||
"aac",
|
"aac",
|
||||||
"-b:a",
|
"-b:a",
|
||||||
`${kbps}k`,
|
`${kbps}k`,
|
||||||
|
...lyricsArgs,
|
||||||
"-movflags",
|
"-movflags",
|
||||||
"+faststart",
|
"+faststart",
|
||||||
output,
|
output,
|
||||||
|
|||||||
@@ -8,8 +8,14 @@ const QueuePanel = dynamic(() =>
|
|||||||
import("@/components/queue-panel").then((module) => module.QueuePanel)
|
import("@/components/queue-panel").then((module) => module.QueuePanel)
|
||||||
)
|
)
|
||||||
|
|
||||||
export function LazyQueuePanel() {
|
const LyricsPanel = dynamic(() =>
|
||||||
const { queueOpen } = usePlayback()
|
import("@/components/lyrics-panel").then((module) => module.LyricsPanel)
|
||||||
|
)
|
||||||
|
|
||||||
|
/** The queue or lyrics panel beside the page, whichever is open. */
|
||||||
|
export function LazyQueuePanel() {
|
||||||
|
const { queueOpen, lyricsOpen } = usePlayback()
|
||||||
|
|
||||||
|
if (lyricsOpen) return <LyricsPanel />
|
||||||
return queueOpen ? <QueuePanel /> : null
|
return queueOpen ? <QueuePanel /> : null
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import {
|
||||||
|
useIsPlaying,
|
||||||
|
usePlayback,
|
||||||
|
usePlaybackProgress,
|
||||||
|
} from "@/components/playback-provider"
|
||||||
|
import { useLyrics, useLyricsTime } from "@/hooks/use-lyrics"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import {
|
||||||
|
activeLineIndex,
|
||||||
|
type LyricLine,
|
||||||
|
type LyricWord,
|
||||||
|
type Lyrics,
|
||||||
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
|
||||||
|
/** How long a manual scroll keeps the panel from following the song. */
|
||||||
|
const MANUAL_SCROLL_HOLD_MS = 3000
|
||||||
|
/** Blur by distance from the playing line; farther lines share the last. */
|
||||||
|
const LINE_BLUR = ["blur-none", "blur-[1px]", "blur-[2px]", "blur-[3px]"]
|
||||||
|
/** Unsung words wipe from dim to bright, soft edge first, as they are sung. */
|
||||||
|
const WORD_FILL = {
|
||||||
|
backgroundImage:
|
||||||
|
"linear-gradient(90deg, var(--foreground) 40%, color-mix(in oklab, var(--foreground) 45%, transparent) 60%)",
|
||||||
|
backgroundSize: "250% 100%",
|
||||||
|
}
|
||||||
|
const WORD_FILL_FRAMES = [
|
||||||
|
{ backgroundPosition: "100% 0" },
|
||||||
|
{ backgroundPosition: "0% 0" },
|
||||||
|
]
|
||||||
|
/** How far a word's fill may drift from playback before it is reset. */
|
||||||
|
const FILL_DRIFT_MS = 80
|
||||||
|
|
||||||
|
/** Lyrics beside the page, in the queue's place. Synced lines follow playback. */
|
||||||
|
export function LyricsPanel() {
|
||||||
|
const { currentSong } = usePlayback()
|
||||||
|
const lyrics = useLyrics(currentSong?.id ?? null)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside
|
||||||
|
aria-label="Lyrics"
|
||||||
|
className={cn(
|
||||||
|
"flex h-svh w-72 shrink-0 flex-col border-l bg-background",
|
||||||
|
"max-md:fixed max-md:inset-y-0 max-md:right-0 max-md:z-20 max-md:shadow-xl"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{lyrics === null ? (
|
||||||
|
<p className="m-auto text-sm text-muted-foreground">No lyrics</p>
|
||||||
|
) : lyrics ? (
|
||||||
|
<LyricsLines key={currentSong?.id} lyrics={lyrics} />
|
||||||
|
) : null}
|
||||||
|
</aside>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
||||||
|
const { seekTo, currentTime } = usePlaybackProgress()
|
||||||
|
const isPlaying = useIsPlaying()
|
||||||
|
const { setIsPlaying } = usePlayback()
|
||||||
|
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||||
|
const active = activeLineIndex(lyrics, time)
|
||||||
|
const scrollRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
const synced = lyrics.synced !== "none"
|
||||||
|
// While the listener scrolls, lines stay sharp and the panel stays put.
|
||||||
|
const [browsing, setBrowsing] = React.useState(false)
|
||||||
|
const browseTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined)
|
||||||
|
|
||||||
|
React.useEffect(() => () => clearTimeout(browseTimer.current), [])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const container = scrollRef.current
|
||||||
|
const line = container?.querySelector<HTMLElement>(
|
||||||
|
`[data-line="${Math.max(active, 0)}"]`
|
||||||
|
)
|
||||||
|
if (!container || !line || !synced || browsing) return
|
||||||
|
container.scrollTo({
|
||||||
|
top: line.offsetTop - container.clientHeight * 0.25,
|
||||||
|
behavior: "smooth",
|
||||||
|
})
|
||||||
|
}, [active, synced, browsing])
|
||||||
|
|
||||||
|
const playFrom = React.useCallback(
|
||||||
|
(seconds: number) => {
|
||||||
|
seekTo(seconds)
|
||||||
|
setIsPlaying(true)
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
setBrowsing(false)
|
||||||
|
},
|
||||||
|
[seekTo, setIsPlaying]
|
||||||
|
)
|
||||||
|
|
||||||
|
const holdScroll = () => {
|
||||||
|
setBrowsing(true)
|
||||||
|
clearTimeout(browseTimer.current)
|
||||||
|
browseTimer.current = setTimeout(
|
||||||
|
() => setBrowsing(false),
|
||||||
|
MANUAL_SCROLL_HOLD_MS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={scrollRef}
|
||||||
|
onWheel={holdScroll}
|
||||||
|
onTouchMove={holdScroll}
|
||||||
|
className="group relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
||||||
|
>
|
||||||
|
{lyrics.lines.map((line, index) =>
|
||||||
|
synced ? (
|
||||||
|
<SyncedLine
|
||||||
|
key={index}
|
||||||
|
index={index}
|
||||||
|
line={line}
|
||||||
|
distance={
|
||||||
|
browsing
|
||||||
|
? 0
|
||||||
|
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||||
|
}
|
||||||
|
active={index === active}
|
||||||
|
time={index === active ? time : null}
|
||||||
|
isPlaying={isPlaying}
|
||||||
|
onSelect={playFrom}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p
|
||||||
|
key={index}
|
||||||
|
className={cn(
|
||||||
|
"text-lg leading-snug font-semibold text-foreground/85",
|
||||||
|
line.text === "" && "h-4"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{line.text}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One timed line, blurred by its `distance` from the playing line. Only the
|
||||||
|
* active line gets the playback time, so memoized lines elsewhere skip
|
||||||
|
* re-rendering as the song plays.
|
||||||
|
*/
|
||||||
|
const SyncedLine = React.memo(function SyncedLine({
|
||||||
|
index,
|
||||||
|
line,
|
||||||
|
distance,
|
||||||
|
active,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
index: number
|
||||||
|
line: LyricLine
|
||||||
|
distance: number
|
||||||
|
active: boolean
|
||||||
|
time: number | null
|
||||||
|
isPlaying: boolean
|
||||||
|
onSelect: (seconds: number) => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-line={index}
|
||||||
|
onClick={() => onSelect(line.start ?? 0)}
|
||||||
|
className={cn(
|
||||||
|
"-mx-2 my-1 block w-[calc(100%+1rem)] rounded-md px-2 py-1.5 text-left text-[22px] leading-tight font-bold transition-[color,filter] duration-300 group-hover:blur-none hover:bg-foreground/5",
|
||||||
|
LINE_BLUR[distance],
|
||||||
|
active && !line.words ? "text-foreground" : "text-foreground/30"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{active && line.words && time !== null ? (
|
||||||
|
<FilledWords words={line.words} time={time} isPlaying={isPlaying} />
|
||||||
|
) : (
|
||||||
|
line.text
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The playing line's words, each filled as far as it has been sung. The
|
||||||
|
* browser runs the fills; playback updates only correct their drift.
|
||||||
|
*/
|
||||||
|
function FilledWords({
|
||||||
|
words,
|
||||||
|
time,
|
||||||
|
isPlaying,
|
||||||
|
}: {
|
||||||
|
words: LyricWord[]
|
||||||
|
time: number
|
||||||
|
isPlaying: boolean
|
||||||
|
}) {
|
||||||
|
const spans = React.useRef<(HTMLSpanElement | null)[]>([])
|
||||||
|
const fills = React.useRef<(Animation | undefined)[]>([])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
fills.current = words.map((word, index) =>
|
||||||
|
spans.current[index]?.animate(WORD_FILL_FRAMES, {
|
||||||
|
duration: Math.max(word.end - word.start, 0.05) * 1000,
|
||||||
|
easing: "linear",
|
||||||
|
fill: "both",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return () => fills.current.forEach((fill) => fill?.cancel())
|
||||||
|
}, [words])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
fills.current.forEach((fill, index) => {
|
||||||
|
if (!fill) return
|
||||||
|
const at = (time - words[index].start) * 1000
|
||||||
|
if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) {
|
||||||
|
fill.currentTime = at
|
||||||
|
}
|
||||||
|
// `play` on a finished fill would rewind it.
|
||||||
|
const duration = Number(fill.effect?.getTiming().duration ?? 0)
|
||||||
|
if (isPlaying && at < duration) fill.play()
|
||||||
|
else fill.pause()
|
||||||
|
})
|
||||||
|
}, [words, time, isPlaying])
|
||||||
|
|
||||||
|
return words.map((word, index) => {
|
||||||
|
const text = word.text.trimEnd()
|
||||||
|
return (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
<span
|
||||||
|
ref={(span) => {
|
||||||
|
spans.current[index] = span
|
||||||
|
}}
|
||||||
|
className="bg-clip-text text-transparent"
|
||||||
|
style={WORD_FILL}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
{word.text.slice(text.length)}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -74,10 +74,6 @@ export function MediaMenuSeparator() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionLabel(base: string, selectedCount: number) {
|
|
||||||
return selectedCount > 1 ? `${base} (${selectedCount})` : base
|
|
||||||
}
|
|
||||||
|
|
||||||
export function MediaContextMenuItems({
|
export function MediaContextMenuItems({
|
||||||
selectedCount,
|
selectedCount,
|
||||||
onAction,
|
onAction,
|
||||||
@@ -121,7 +117,7 @@ export function MediaContextMenuItems({
|
|||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction("playlist")}
|
onClick={() => onAction("playlist")}
|
||||||
>
|
>
|
||||||
{actionLabel(playlistLabel, selectedCount)}
|
{playlistLabel}
|
||||||
<ListPlus />
|
<ListPlus />
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
{downloaded !== undefined ? (
|
{downloaded !== undefined ? (
|
||||||
@@ -129,10 +125,7 @@ export function MediaContextMenuItems({
|
|||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction(downloaded ? "remove-download" : "download")}
|
onClick={() => onAction(downloaded ? "remove-download" : "download")}
|
||||||
>
|
>
|
||||||
{actionLabel(
|
{downloaded ? "Remove Download" : "Download"}
|
||||||
downloaded ? "Remove Download" : "Download",
|
|
||||||
selectedCount
|
|
||||||
)}
|
|
||||||
{downloaded ? <CircleX /> : <ArrowDownToLine />}
|
{downloaded ? <CircleX /> : <ArrowDownToLine />}
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -141,21 +134,21 @@ export function MediaContextMenuItems({
|
|||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction("play-next")}
|
onClick={() => onAction("play-next")}
|
||||||
>
|
>
|
||||||
{actionLabel("Play Next", selectedCount)}
|
Play Next
|
||||||
<ListStart />
|
<ListStart />
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction("play-last")}
|
onClick={() => onAction("play-last")}
|
||||||
>
|
>
|
||||||
{actionLabel("Play Last", selectedCount)}
|
Play Last
|
||||||
<ListEnd />
|
<ListEnd />
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction("shuffle")}
|
onClick={() => onAction("shuffle")}
|
||||||
>
|
>
|
||||||
{actionLabel("Shuffle", selectedCount)}
|
Shuffle
|
||||||
<Shuffle />
|
<Shuffle />
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
{stationArtistId ? (
|
{stationArtistId ? (
|
||||||
@@ -196,7 +189,7 @@ export function MediaContextMenuItems({
|
|||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onAction("favorite")}
|
onClick={() => onAction("favorite")}
|
||||||
>
|
>
|
||||||
{actionLabel(favorited ? "Unfavorite" : "Favorite", selectedCount)}
|
{favorited ? "Unfavorite" : "Favorite"}
|
||||||
<Star />
|
<Star />
|
||||||
</MediaMenuItem>
|
</MediaMenuItem>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -60,10 +60,13 @@ type PlaybackContextValue = {
|
|||||||
shuffleEnabled: boolean
|
shuffleEnabled: boolean
|
||||||
repeatEnabled: RepeatMode
|
repeatEnabled: RepeatMode
|
||||||
queueOpen: boolean
|
queueOpen: boolean
|
||||||
|
/** The lyrics panel, which shares the queue's place beside the page. */
|
||||||
|
lyricsOpen: boolean
|
||||||
isPlaying: boolean
|
isPlaying: boolean
|
||||||
volume: number
|
volume: number
|
||||||
setQueueOpen: (open: boolean) => void
|
setQueueOpen: (open: boolean) => void
|
||||||
toggleQueueOpen: () => void
|
toggleQueueOpen: () => void
|
||||||
|
toggleLyricsOpen: () => void
|
||||||
setIsPlaying: (playing: boolean) => void
|
setIsPlaying: (playing: boolean) => void
|
||||||
setVolume: (volume: number) => void
|
setVolume: (volume: number) => void
|
||||||
/** An origin from `downloadsQueueOrigin` plays downloads in any quality. */
|
/** An origin from `downloadsQueueOrigin` plays downloads in any quality. */
|
||||||
@@ -103,8 +106,11 @@ type PlaybackContextValue = {
|
|||||||
toggleShuffle: () => Promise<void>
|
toggleShuffle: () => Promise<void>
|
||||||
cycleRepeat: () => Promise<void>
|
cycleRepeat: () => Promise<void>
|
||||||
clearQueue: () => Promise<void>
|
clearQueue: () => Promise<void>
|
||||||
|
clearHistory: () => Promise<void>
|
||||||
reorderQueue: (songIds: Id<"songs">[]) => Promise<void>
|
reorderQueue: (songIds: Id<"songs">[]) => Promise<void>
|
||||||
skipToQueueIndex: (index: number) => Promise<void>
|
skipToQueueIndex: (index: number) => Promise<void>
|
||||||
|
/** Plays `history[index]`, moving it and every later song back into the queue. */
|
||||||
|
skipToHistoryIndex: (index: number) => Promise<void>
|
||||||
skipNext: () => Promise<void>
|
skipNext: () => Promise<void>
|
||||||
skipPrevious: () => Promise<void>
|
skipPrevious: () => Promise<void>
|
||||||
dolbyAtmosSupported: boolean | null
|
dolbyAtmosSupported: boolean | null
|
||||||
@@ -119,6 +125,7 @@ type PlaybackActions = Omit<
|
|||||||
| "shuffleEnabled"
|
| "shuffleEnabled"
|
||||||
| "repeatEnabled"
|
| "repeatEnabled"
|
||||||
| "queueOpen"
|
| "queueOpen"
|
||||||
|
| "lyricsOpen"
|
||||||
| "isPlaying"
|
| "isPlaying"
|
||||||
| "volume"
|
| "volume"
|
||||||
| "dolbyAtmosSupported"
|
| "dolbyAtmosSupported"
|
||||||
@@ -503,7 +510,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
const currentTimeRef = useRef(0)
|
const currentTimeRef = useRef(0)
|
||||||
const durationRef = useRef(0)
|
const durationRef = useRef(0)
|
||||||
|
|
||||||
const [queueOpen, setQueueOpen] = useState(false)
|
const [sidePanel, setSidePanel] = useState<"queue" | "lyrics" | null>(null)
|
||||||
|
const queueOpen = sidePanel === "queue"
|
||||||
|
const lyricsOpen = sidePanel === "lyrics"
|
||||||
|
const setQueueOpen = useCallback((open: boolean) => {
|
||||||
|
setSidePanel((panel) => (open ? "queue" : panel === "queue" ? null : panel))
|
||||||
|
}, [])
|
||||||
const [isPlaying, setIsPlaying] = useState(false)
|
const [isPlaying, setIsPlaying] = useState(false)
|
||||||
const [playbackStartVersion, setPlaybackStartVersion] = useState(0)
|
const [playbackStartVersion, setPlaybackStartVersion] = useState(0)
|
||||||
const [currentTime, setCurrentTime] = useState(0)
|
const [currentTime, setCurrentTime] = useState(0)
|
||||||
@@ -1438,7 +1450,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const toggleQueueOpen = useCallback(() => {
|
const toggleQueueOpen = useCallback(() => {
|
||||||
setQueueOpen((open) => !open)
|
setSidePanel((panel) => (panel === "queue" ? null : "queue"))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const toggleLyricsOpen = useCallback(() => {
|
||||||
|
setSidePanel((panel) => (panel === "lyrics" ? null : "lyrics"))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const toggleShuffle = useCallback(async () => {
|
const toggleShuffle = useCallback(async () => {
|
||||||
@@ -1455,6 +1471,10 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
setIsPlaying(false)
|
setIsPlaying(false)
|
||||||
}, [store])
|
}, [store])
|
||||||
|
|
||||||
|
const clearHistory = useCallback(async () => {
|
||||||
|
store.update(playbackQueue.clearHistory)
|
||||||
|
}, [store])
|
||||||
|
|
||||||
const reorderQueue = useCallback(
|
const reorderQueue = useCallback(
|
||||||
async (songIds: Id<"songs">[]) => {
|
async (songIds: Id<"songs">[]) => {
|
||||||
store.update((state) => playbackQueue.reorderQueue(state, songIds))
|
store.update((state) => playbackQueue.reorderQueue(state, songIds))
|
||||||
@@ -1469,6 +1489,13 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
[store]
|
[store]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const skipToHistoryIndex = useCallback(
|
||||||
|
async (index: number) => {
|
||||||
|
store.update((state) => playbackQueue.skipToHistoryIndex(state, index))
|
||||||
|
},
|
||||||
|
[store]
|
||||||
|
)
|
||||||
|
|
||||||
const skipNext = useCallback(async () => {
|
const skipNext = useCallback(async () => {
|
||||||
const before = store.getState()
|
const before = store.getState()
|
||||||
if (before.repeatEnabled === "none" && before.queue.length <= 1) {
|
if (before.repeatEnabled === "none" && before.queue.length <= 1) {
|
||||||
@@ -1533,6 +1560,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
() => ({
|
() => ({
|
||||||
setQueueOpen,
|
setQueueOpen,
|
||||||
toggleQueueOpen,
|
toggleQueueOpen,
|
||||||
|
toggleLyricsOpen,
|
||||||
setIsPlaying,
|
setIsPlaying,
|
||||||
setVolume,
|
setVolume,
|
||||||
playInOrder,
|
playInOrder,
|
||||||
@@ -1550,13 +1578,17 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
toggleShuffle,
|
toggleShuffle,
|
||||||
cycleRepeat,
|
cycleRepeat,
|
||||||
clearQueue,
|
clearQueue,
|
||||||
|
clearHistory,
|
||||||
reorderQueue,
|
reorderQueue,
|
||||||
skipToQueueIndex,
|
skipToQueueIndex,
|
||||||
|
skipToHistoryIndex,
|
||||||
skipNext,
|
skipNext,
|
||||||
skipPrevious,
|
skipPrevious,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
|
setQueueOpen,
|
||||||
toggleQueueOpen,
|
toggleQueueOpen,
|
||||||
|
toggleLyricsOpen,
|
||||||
setVolume,
|
setVolume,
|
||||||
playInOrder,
|
playInOrder,
|
||||||
playShuffled,
|
playShuffled,
|
||||||
@@ -1573,8 +1605,10 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
toggleShuffle,
|
toggleShuffle,
|
||||||
cycleRepeat,
|
cycleRepeat,
|
||||||
clearQueue,
|
clearQueue,
|
||||||
|
clearHistory,
|
||||||
reorderQueue,
|
reorderQueue,
|
||||||
skipToQueueIndex,
|
skipToQueueIndex,
|
||||||
|
skipToHistoryIndex,
|
||||||
skipNext,
|
skipNext,
|
||||||
skipPrevious,
|
skipPrevious,
|
||||||
]
|
]
|
||||||
@@ -1590,6 +1624,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
shuffleEnabled: playback.shuffleEnabled,
|
shuffleEnabled: playback.shuffleEnabled,
|
||||||
repeatEnabled: playback.repeatEnabled,
|
repeatEnabled: playback.repeatEnabled,
|
||||||
queueOpen,
|
queueOpen,
|
||||||
|
lyricsOpen,
|
||||||
isPlaying: isPlaybackActive,
|
isPlaying: isPlaybackActive,
|
||||||
volume,
|
volume,
|
||||||
dolbyAtmosSupported,
|
dolbyAtmosSupported,
|
||||||
@@ -1600,6 +1635,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
|||||||
currentSong,
|
currentSong,
|
||||||
currentFormat,
|
currentFormat,
|
||||||
queueOpen,
|
queueOpen,
|
||||||
|
lyricsOpen,
|
||||||
isPlaybackActive,
|
isPlaybackActive,
|
||||||
volume,
|
volume,
|
||||||
dolbyAtmosSupported,
|
dolbyAtmosSupported,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Slider } from "@/components/ui/slider"
|
import { Slider } from "@/components/ui/slider"
|
||||||
import { useSidebar } from "@/components/ui/sidebar"
|
import { useSidebar } from "@/components/ui/sidebar"
|
||||||
|
import { useLyrics } from "@/hooks/use-lyrics"
|
||||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { formatDuration } from "@/lib/format-duration"
|
import { formatDuration } from "@/lib/format-duration"
|
||||||
@@ -73,18 +74,21 @@ export function PlayerBar() {
|
|||||||
shuffleEnabled,
|
shuffleEnabled,
|
||||||
repeatEnabled,
|
repeatEnabled,
|
||||||
queueOpen,
|
queueOpen,
|
||||||
|
lyricsOpen,
|
||||||
isPlaying,
|
isPlaying,
|
||||||
volume,
|
volume,
|
||||||
queueSongIds,
|
queueSongIds,
|
||||||
setIsPlaying,
|
setIsPlaying,
|
||||||
setVolume,
|
setVolume,
|
||||||
toggleQueueOpen,
|
toggleQueueOpen,
|
||||||
|
toggleLyricsOpen,
|
||||||
toggleShuffle,
|
toggleShuffle,
|
||||||
cycleRepeat,
|
cycleRepeat,
|
||||||
skipNext,
|
skipNext,
|
||||||
skipPrevious,
|
skipPrevious,
|
||||||
} = usePlayback()
|
} = usePlayback()
|
||||||
const { state, isMobile } = useSidebar()
|
const { state, isMobile } = useSidebar()
|
||||||
|
const lyrics = useLyrics(currentSong?.id ?? null)
|
||||||
|
|
||||||
const hasQueue = queueSongIds.length > 0
|
const hasQueue = queueSongIds.length > 0
|
||||||
const sidebarExpanded = !isMobile && state === "expanded"
|
const sidebarExpanded = !isMobile && state === "expanded"
|
||||||
@@ -94,7 +98,7 @@ export function PlayerBar() {
|
|||||||
className={cn(
|
className={cn(
|
||||||
"@container pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
"@container pointer-events-none fixed bottom-4 z-50 flex justify-center px-4 transition-[left,right] duration-200 ease-linear",
|
||||||
sidebarExpanded ? "right-0 left-[16rem]" : "inset-x-0",
|
sidebarExpanded ? "right-0 left-[16rem]" : "inset-x-0",
|
||||||
queueOpen && !isMobile && "right-72"
|
(queueOpen || lyricsOpen) && !isMobile && "right-72"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="pointer-events-auto flex w-full max-w-[40rem] items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] md:gap-3 md:py-1.5 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
|
<div className="pointer-events-auto flex w-full max-w-[40rem] items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] md:gap-3 md:py-1.5 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
|
||||||
@@ -227,9 +231,14 @@ export function PlayerBar() {
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
className="hidden @min-[640px]:inline-flex"
|
|
||||||
aria-label="Lyrics"
|
aria-label="Lyrics"
|
||||||
disabled
|
aria-pressed={lyricsOpen}
|
||||||
|
className={cn(
|
||||||
|
"hidden @min-[640px]:inline-flex",
|
||||||
|
lyricsOpen && "text-primary"
|
||||||
|
)}
|
||||||
|
disabled={!lyrics && !lyricsOpen}
|
||||||
|
onClick={toggleLyricsOpen}
|
||||||
>
|
>
|
||||||
<MessageSquareQuote className="size-4" />
|
<MessageSquareQuote className="size-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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"
|
||||||
import { useMutation } from "convex/react"
|
import { useMutation, useQuery } from "convex/react"
|
||||||
import {
|
import {
|
||||||
ImageIcon,
|
ImageIcon,
|
||||||
Pencil,
|
Pencil,
|
||||||
@@ -101,9 +101,13 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|||||||
: playlistSongs
|
: playlistSongs
|
||||||
const [searchQuery, setSearchQuery] = React.useState("")
|
const [searchQuery, setSearchQuery] = React.useState("")
|
||||||
const isSearching = searchQuery.trim() !== ""
|
const isSearching = searchQuery.trim() !== ""
|
||||||
|
const lyricsMatches = useQuery(
|
||||||
|
api.lyrics.matchingSongIds,
|
||||||
|
isSearching ? { query: searchQuery } : "skip"
|
||||||
|
)
|
||||||
const filteredSongs = React.useMemo(
|
const filteredSongs = React.useMemo(
|
||||||
() => filterSongs(songs, searchQuery),
|
() => filterSongs(songs, searchQuery, lyricsMatches),
|
||||||
[songs, searchQuery]
|
[songs, searchQuery, lyricsMatches]
|
||||||
)
|
)
|
||||||
const playlistSongIds = React.useMemo(
|
const playlistSongIds = React.useMemo(
|
||||||
() => songs.map((song) => song.id as Id<"songs">),
|
() => songs.map((song) => song.id as Id<"songs">),
|
||||||
|
|||||||
+252
-122
@@ -2,24 +2,25 @@
|
|||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { useFavorites } from "@/components/favorites-provider"
|
||||||
|
import type { MediaContextAction } from "@/components/media-context-menu"
|
||||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||||
import { usePlayback } from "@/components/playback-provider"
|
import { usePlayback } from "@/components/playback-provider"
|
||||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||||
import { Button } from "@/components/ui/button"
|
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { Spinner } from "@/components/ui/spinner"
|
import { Spinner } from "@/components/ui/spinner"
|
||||||
|
import { useMediaActions } from "@/hooks/use-media-actions"
|
||||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
import type { BrowseSong, HistorySong, QueueSong } from "@otunes/convex/types"
|
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
||||||
import {
|
import {
|
||||||
getContiguousSelectedIndices,
|
getContiguousSelectedIndices,
|
||||||
moveQueueBlock,
|
moveQueueBlock,
|
||||||
} from "@/lib/move-queue-block"
|
} from "@/lib/move-queue-block"
|
||||||
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
||||||
|
import { stationArtistId } from "@/lib/station-artist"
|
||||||
import { useSongs } from "@/lib/song-cache"
|
import { useSongs } from "@/lib/song-cache"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { formatDuration } from "@/lib/format-duration"
|
|
||||||
|
|
||||||
const QUEUE_INITIAL_VISIBLE_COUNT = 100
|
const QUEUE_INITIAL_VISIBLE_COUNT = 100
|
||||||
const QUEUE_PAGE_SIZE = 50
|
const QUEUE_PAGE_SIZE = 50
|
||||||
@@ -32,11 +33,13 @@ type QueueItem = {
|
|||||||
song: QueueSelectable | null
|
song: QueueSelectable | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Upcoming songs only: queue index 0 is the current song, shown on its own. */
|
||||||
function toSelectableQueue(
|
function toSelectableQueue(
|
||||||
songIds: Id<"songs">[],
|
songIds: Id<"songs">[],
|
||||||
songs: (BrowseSong | undefined)[]
|
songs: (BrowseSong | undefined)[]
|
||||||
): QueueItem[] {
|
): QueueItem[] {
|
||||||
return songIds.map((songId, queueIndex) => {
|
return songIds.slice(1).map((songId, offset) => {
|
||||||
|
const queueIndex = offset + 1
|
||||||
const selectionId = `${songId}-${queueIndex}`
|
const selectionId = `${songId}-${queueIndex}`
|
||||||
const song = songs[queueIndex]
|
const song = songs[queueIndex]
|
||||||
return {
|
return {
|
||||||
@@ -47,57 +50,75 @@ function toSelectableQueue(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function HistorySongRow({ song }: { song: HistorySong }) {
|
/** A played song; clicking it plays it again from that point in history. */
|
||||||
|
function HistorySongRow({
|
||||||
|
song,
|
||||||
|
historyIndex,
|
||||||
|
onPlay,
|
||||||
|
}: {
|
||||||
|
song: BrowseSong | undefined
|
||||||
|
historyIndex: number
|
||||||
|
onPlay: (historyIndex: number) => void
|
||||||
|
}) {
|
||||||
|
if (!song) {
|
||||||
|
return <QueueSongRowSkeleton />
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="relative w-full py-2 text-left text-sm opacity-60">
|
<li
|
||||||
<div className="relative z-10 flex items-center gap-3 px-2">
|
role="button"
|
||||||
<TrackCover
|
tabIndex={0}
|
||||||
albumId={song.album.id}
|
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
||||||
alt={song.album.title}
|
onClick={() => onPlay(historyIndex)}
|
||||||
inRange={false}
|
onKeyDown={(event) => {
|
||||||
square
|
if (event.key === "Enter" || event.key === " ") {
|
||||||
/>
|
event.preventDefault()
|
||||||
|
onPlay(historyIndex)
|
||||||
<PlaybackSongMeta
|
}
|
||||||
song={song}
|
}}
|
||||||
isCurrent={false}
|
>
|
||||||
inRange={false}
|
<TrackCover
|
||||||
align="start"
|
albumId={song.album.id}
|
||||||
showAlbum={false}
|
alt={song.album.title}
|
||||||
/>
|
inRange={false}
|
||||||
|
/>
|
||||||
<span className="shrink-0 text-xs text-muted-foreground tabular-nums">
|
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||||
{formatDuration(song.durationSeconds)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function QueueSongRowSkeleton() {
|
function QueueSongRowSkeleton() {
|
||||||
return (
|
return (
|
||||||
<li className="flex items-center gap-3 px-2 py-2" aria-hidden>
|
<li className="flex items-center gap-3 px-4 py-2" aria-hidden>
|
||||||
<Skeleton className="size-10 shrink-0 rounded-none" />
|
<Skeleton className="size-10 shrink-0 rounded" />
|
||||||
<div className="flex min-w-0 flex-1 flex-col gap-1.5">
|
<div className="flex min-w-0 flex-1 flex-col gap-1.5">
|
||||||
<Skeleton className="h-3.5 w-3/4" />
|
<Skeleton className="h-3.5 w-3/4" />
|
||||||
<Skeleton className="h-3 w-1/2" />
|
<Skeleton className="h-3 w-1/2" />
|
||||||
</div>
|
</div>
|
||||||
<Skeleton className="h-3 w-8 shrink-0" />
|
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The queue sidebar, laid out like the mobile now playing queue: history above
|
||||||
|
* (scrolled out of view at first), then the current song and the upcoming
|
||||||
|
* songs, which can be dragged to reorder. Shuffle and repeat live in the
|
||||||
|
* player bar.
|
||||||
|
*/
|
||||||
export function QueuePanel() {
|
export function QueuePanel() {
|
||||||
const {
|
const {
|
||||||
queueSongIds,
|
queueSongIds,
|
||||||
queueHistorySongIds,
|
queueHistorySongIds,
|
||||||
queueOpen,
|
queueOpen,
|
||||||
|
clearHistory,
|
||||||
clearQueue,
|
clearQueue,
|
||||||
reorderQueue,
|
reorderQueue,
|
||||||
skipToQueueIndex,
|
skipToQueueIndex,
|
||||||
|
skipToHistoryIndex,
|
||||||
} = usePlayback()
|
} = usePlayback()
|
||||||
const loadMoreRef = React.useRef<HTMLDivElement>(null)
|
const loadMoreRef = React.useRef<HTMLDivElement>(null)
|
||||||
const nowPlayingRef = React.useRef<HTMLElement>(null)
|
const scrollRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
const currentRef = React.useRef<HTMLDivElement>(null)
|
||||||
const [visibleCount, setVisibleCount] = React.useState(
|
const [visibleCount, setVisibleCount] = React.useState(
|
||||||
QUEUE_INITIAL_VISIBLE_COUNT
|
QUEUE_INITIAL_VISIBLE_COUNT
|
||||||
)
|
)
|
||||||
@@ -107,15 +128,10 @@ export function QueuePanel() {
|
|||||||
[queueSongIds, visibleCount]
|
[queueSongIds, visibleCount]
|
||||||
)
|
)
|
||||||
const visibleQueueSongs = useSongs(visibleQueueIds)
|
const visibleQueueSongs = useSongs(visibleQueueIds)
|
||||||
const historySongMetadata = useSongs(queueHistorySongIds)
|
const historySongs = useSongs(queueHistorySongIds)
|
||||||
const historySongs = React.useMemo(
|
const currentSong = visibleQueueSongs[0]
|
||||||
() =>
|
|
||||||
historySongMetadata.flatMap((song, historyIndex) =>
|
|
||||||
song ? [{ ...song, historyIndex }] : []
|
|
||||||
),
|
|
||||||
[historySongMetadata]
|
|
||||||
)
|
|
||||||
const hasMore = queueSongIds.length > visibleCount
|
const hasMore = queueSongIds.length > visibleCount
|
||||||
|
const hasUpcoming = queueSongIds.length > 1
|
||||||
|
|
||||||
const selectableQueue = React.useMemo(
|
const selectableQueue = React.useMemo(
|
||||||
() => toSelectableQueue(visibleQueueIds, visibleQueueSongs),
|
() => toSelectableQueue(visibleQueueIds, visibleQueueSongs),
|
||||||
@@ -125,17 +141,21 @@ export function QueuePanel() {
|
|||||||
const [dragIndex, setDragIndex] = React.useState<number | null>(null)
|
const [dragIndex, setDragIndex] = React.useState<number | null>(null)
|
||||||
const currentQueueSongId = queueSongIds[0]
|
const currentQueueSongId = queueSongIds[0]
|
||||||
|
|
||||||
React.useEffect(() => {
|
// Keep the current song at the top as playback moves through the queue:
|
||||||
if (!queueOpen || queueSongIds.length === 0) {
|
// jump there on open, then scroll smoothly as songs change.
|
||||||
|
const hasScrolledRef = React.useRef(false)
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
const scroller = scrollRef.current
|
||||||
|
const current = currentRef.current
|
||||||
|
if (!queueOpen || !scroller || !current) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
scroller.scrollTo({
|
||||||
const frame = requestAnimationFrame(() => {
|
top: current.offsetTop,
|
||||||
nowPlayingRef.current?.scrollIntoView({ block: "center" })
|
behavior: hasScrolledRef.current ? "smooth" : "instant",
|
||||||
})
|
})
|
||||||
|
hasScrolledRef.current = true
|
||||||
return () => cancelAnimationFrame(frame)
|
}, [queueOpen, currentQueueSongId, queueHistorySongIds.length])
|
||||||
}, [queueOpen, queueSongIds.length, currentQueueSongId])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!hasMore) {
|
if (!hasMore) {
|
||||||
@@ -143,12 +163,8 @@ export function QueuePanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sentinel = loadMoreRef.current
|
const sentinel = loadMoreRef.current
|
||||||
if (!sentinel) {
|
const root = scrollRef.current
|
||||||
return
|
if (!sentinel || !root) {
|
||||||
}
|
|
||||||
|
|
||||||
const viewport = sentinel.closest('[data-slot="scroll-area-viewport"]')
|
|
||||||
if (!viewport) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +174,7 @@ export function QueuePanel() {
|
|||||||
setVisibleCount((count) => count + QUEUE_PAGE_SIZE)
|
setVisibleCount((count) => count + QUEUE_PAGE_SIZE)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ root: viewport, rootMargin: "240px" }
|
{ root, rootMargin: "240px" }
|
||||||
)
|
)
|
||||||
|
|
||||||
observer.observe(sentinel)
|
observer.observe(sentinel)
|
||||||
@@ -169,8 +185,66 @@ export function QueuePanel() {
|
|||||||
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
||||||
[selectableQueue]
|
[selectableQueue]
|
||||||
)
|
)
|
||||||
const { selectedIds, handleSelect, handlePointerDown } =
|
const {
|
||||||
useTrackSelection(selectionItems)
|
selectedIds,
|
||||||
|
selectedCount,
|
||||||
|
handleSelect,
|
||||||
|
handlePointerDown,
|
||||||
|
prepareContextMenu,
|
||||||
|
clearSelection,
|
||||||
|
} = useTrackSelection(selectionItems)
|
||||||
|
const { isSongFavorite } = useFavorites()
|
||||||
|
const { runSongsAction } = useMediaActions()
|
||||||
|
|
||||||
|
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||||
|
const menuTargets = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const ids = selectedIds.has(selectionId)
|
||||||
|
? selectedIds
|
||||||
|
: new Set([selectionId])
|
||||||
|
return selectableQueue.filter((item) => ids.has(item.selectionId))
|
||||||
|
},
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
|
const selectedStationArtistId = React.useMemo(
|
||||||
|
() =>
|
||||||
|
stationArtistId(
|
||||||
|
selectableQueue.flatMap((item) =>
|
||||||
|
item.song ? [{ id: item.selectionId, artist: item.song.artist }] : []
|
||||||
|
),
|
||||||
|
selectedIds
|
||||||
|
),
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleMediaAction = React.useCallback(
|
||||||
|
(action: MediaContextAction, selectionId: string) => {
|
||||||
|
const songs = menuTargets(selectionId).flatMap((item) =>
|
||||||
|
item.song ? [item.song] : []
|
||||||
|
)
|
||||||
|
const artistId = songs[0]?.artist.id
|
||||||
|
runSongsAction(
|
||||||
|
action,
|
||||||
|
songs.map((song) => song.id),
|
||||||
|
songs.every((song) => song.artist.id === artistId)
|
||||||
|
? artistId
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
},
|
||||||
|
[menuTargets, runSongsAction]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleRemove = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const removed = new Set(
|
||||||
|
menuTargets(selectionId).map((item) => item.queueIndex)
|
||||||
|
)
|
||||||
|
clearSelection()
|
||||||
|
void reorderQueue(queueSongIds.filter((_, index) => !removed.has(index)))
|
||||||
|
},
|
||||||
|
[clearSelection, menuTargets, queueSongIds, reorderQueue]
|
||||||
|
)
|
||||||
|
|
||||||
const handleRowSelect = React.useCallback(
|
const handleRowSelect = React.useCallback(
|
||||||
(index: number, event: React.MouseEvent) => {
|
(index: number, event: React.MouseEvent) => {
|
||||||
@@ -186,6 +260,11 @@ export function QueuePanel() {
|
|||||||
[selectableQueue, skipToQueueIndex]
|
[selectableQueue, skipToQueueIndex]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const handleHistoryPlay = React.useCallback(
|
||||||
|
(historyIndex: number) => void skipToHistoryIndex(historyIndex),
|
||||||
|
[skipToHistoryIndex]
|
||||||
|
)
|
||||||
|
|
||||||
const selectionPositions = React.useMemo(
|
const selectionPositions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
getSelectionRangePositions(
|
getSelectionRangePositions(
|
||||||
@@ -240,76 +319,127 @@ export function QueuePanel() {
|
|||||||
return (
|
return (
|
||||||
<aside
|
<aside
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-svh w-72 shrink-0 flex-col border-l bg-background",
|
"relative flex h-svh w-72 shrink-0 flex-col border-l bg-background",
|
||||||
"max-md:fixed max-md:inset-y-0 max-md:right-0 max-md:z-20 max-md:shadow-xl"
|
"max-md:fixed max-md:inset-y-0 max-md:right-0 max-md:z-20 max-md:shadow-xl"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
|
<div
|
||||||
<h1 className="text-lg font-semibold">Up Next</h1>
|
ref={scrollRef}
|
||||||
<Button
|
className="relative min-h-0 flex-1 [scrollbar-width:none] overflow-y-auto overscroll-contain"
|
||||||
variant="ghost"
|
>
|
||||||
size="sm"
|
{queueHistorySongIds.length > 0 ? (
|
||||||
className="text-primary hover:text-primary"
|
<section>
|
||||||
onClick={() => void clearQueue()}
|
<header className="flex items-center justify-between px-4 pt-3 pb-1">
|
||||||
disabled={queueSongIds.length === 0}
|
<h2 className="text-base font-bold">History</h2>
|
||||||
>
|
<button
|
||||||
Clear
|
type="button"
|
||||||
</Button>
|
className="text-sm text-muted-foreground hover:text-foreground"
|
||||||
</header>
|
onClick={() => void clearHistory()}
|
||||||
|
|
||||||
<ScrollArea className="min-h-0 flex-1">
|
|
||||||
{queueSongIds.length === 0 ? (
|
|
||||||
<p className="px-4 py-8 text-sm text-muted-foreground">
|
|
||||||
Nothing in the queue.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{historySongs.length > 0 ? (
|
|
||||||
<ul className="flex flex-col border-b py-1">
|
|
||||||
{historySongs.map((song) => (
|
|
||||||
<HistorySongRow
|
|
||||||
key={`history-${song.id}-${song.historyIndex}`}
|
|
||||||
song={song}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
) : null}
|
|
||||||
<ul className="flex flex-col py-1">
|
|
||||||
{selectableQueue.map((item, index) =>
|
|
||||||
item.song ? (
|
|
||||||
<TrackRow
|
|
||||||
key={item.selectionId}
|
|
||||||
ref={item.queueIndex === 0 ? nowPlayingRef : undefined}
|
|
||||||
variant="queue"
|
|
||||||
song={item.song}
|
|
||||||
index={index}
|
|
||||||
isActive={item.queueIndex === 0}
|
|
||||||
isNowPlaying={item.queueIndex === 0}
|
|
||||||
selectionPosition={selectionPositions[index]}
|
|
||||||
isDragging={draggingIndices.has(index)}
|
|
||||||
onPointerDown={handlePointerDown}
|
|
||||||
onSelect={handleRowSelect}
|
|
||||||
onPlay={handleRowPlay}
|
|
||||||
onDragStart={setDragIndex}
|
|
||||||
onDrop={handleDrop}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<QueueSongRowSkeleton key={item.selectionId} />
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
{hasMore ? (
|
|
||||||
<div
|
|
||||||
ref={loadMoreRef}
|
|
||||||
className="flex items-center justify-center py-4"
|
|
||||||
aria-hidden
|
|
||||||
>
|
>
|
||||||
<Spinner className="size-5 text-muted-foreground" />
|
Clear
|
||||||
</div>
|
</button>
|
||||||
) : null}
|
</header>
|
||||||
</>
|
<ul className="flex flex-col">
|
||||||
)}
|
{queueHistorySongIds.map((songId, historyIndex) => (
|
||||||
</ScrollArea>
|
<HistorySongRow
|
||||||
|
key={`history-${songId}-${historyIndex}`}
|
||||||
|
song={historySongs[historyIndex]}
|
||||||
|
historyIndex={historyIndex}
|
||||||
|
onPlay={handleHistoryPlay}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Fills the viewport so the current song can always scroll to the top. */}
|
||||||
|
<div ref={currentRef} className="flex min-h-full flex-col">
|
||||||
|
{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}
|
||||||
|
|
||||||
|
<header className="sticky top-0 z-20 flex items-center justify-between bg-background px-4 py-2">
|
||||||
|
<h2 className="text-base font-bold">Continue Playing</h2>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="text-sm text-muted-foreground hover:text-foreground disabled:pointer-events-none disabled:opacity-50"
|
||||||
|
onClick={() => void clearQueue()}
|
||||||
|
disabled={queueSongIds.length === 0}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{hasUpcoming ? (
|
||||||
|
<>
|
||||||
|
<ul className="flex flex-col pb-8">
|
||||||
|
{selectableQueue.map((item, index) =>
|
||||||
|
item.song ? (
|
||||||
|
<TrackRow
|
||||||
|
key={item.selectionId}
|
||||||
|
variant="queue"
|
||||||
|
song={item.song}
|
||||||
|
index={index}
|
||||||
|
selectionId={item.selectionId}
|
||||||
|
isFavorite={isSongFavorite(item.song.id)}
|
||||||
|
selectedCount={selectedCount}
|
||||||
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
|
removeLabel="Remove from Queue"
|
||||||
|
selectionPosition={selectionPositions[index]}
|
||||||
|
isDragging={draggingIndices.has(index)}
|
||||||
|
onPointerDown={handlePointerDown}
|
||||||
|
onSelect={handleRowSelect}
|
||||||
|
onPlay={handleRowPlay}
|
||||||
|
onDragStart={setDragIndex}
|
||||||
|
onDrop={handleDrop}
|
||||||
|
onPrepareContextMenu={prepareContextMenu}
|
||||||
|
onMediaAction={handleMediaAction}
|
||||||
|
onRemove={handleRemove}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<QueueSongRowSkeleton key={item.selectionId} />
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
{hasMore ? (
|
||||||
|
<div
|
||||||
|
ref={loadMoreRef}
|
||||||
|
className="flex items-center justify-center py-4"
|
||||||
|
aria-hidden
|
||||||
|
>
|
||||||
|
<Spinner className="size-5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="flex flex-1 items-center justify-center px-4 pb-24 text-center text-lg font-semibold text-muted-foreground">
|
||||||
|
Nothing else is queued.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
aria-hidden
|
||||||
|
className="pointer-events-none absolute inset-x-0 bottom-0 h-9 bg-linear-to-b from-transparent to-background"
|
||||||
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -14,10 +14,10 @@ import {
|
|||||||
type MediaContextMenuProps,
|
type MediaContextMenuProps,
|
||||||
} from "@/components/media-context-menu"
|
} from "@/components/media-context-menu"
|
||||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
import type { BrowseSong } from "@otunes/convex/types"
|
import type { SearchSong } from "@otunes/convex/types"
|
||||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||||
|
|
||||||
export function SearchSongItem({ song }: { song: BrowseSong }) {
|
export function SearchSongItem({ song }: { song: SearchSong }) {
|
||||||
const { openAddToPlaylist } = useAddToPlaylist()
|
const { openAddToPlaylist } = useAddToPlaylist()
|
||||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||||
@@ -103,6 +103,11 @@ export function SearchSongItem({ song }: { song: BrowseSong }) {
|
|||||||
>
|
>
|
||||||
<p className="truncate text-sm">{song.artist.name}</p>
|
<p className="truncate text-sm">{song.artist.name}</p>
|
||||||
</Link>
|
</Link>
|
||||||
|
{song.lyricsSnippet ? (
|
||||||
|
<p className="truncate text-xs text-muted-foreground">
|
||||||
|
Lyrics: “{song.lyricsSnippet}”
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MediaContextMenu {...menu} />
|
<MediaContextMenu {...menu} />
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import Image from "next/image"
|
import Image from "next/image"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { ArrowDownToLine, Music2, Play, Star, Trash2 } from "lucide-react"
|
import { ArrowDownToLine, Menu, Music2, Play, Star, Trash2 } from "lucide-react"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MediaContextMenu,
|
MediaContextMenu,
|
||||||
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
|||||||
* columns (use with `LibraryTrackListHeader`).
|
* columns (use with `LibraryTrackListHeader`).
|
||||||
* - `album`: favorite star, track number, title with optional credits.
|
* - `album`: favorite star, track number, title with optional credits.
|
||||||
* - `playlist`: cover with favorite overlay, track number, title.
|
* - `playlist`: cover with favorite overlay, track number, title.
|
||||||
* - `queue`: square cover, title and artist, no menu.
|
* - `queue`: cover, title and artist, duration, and a reorder grip.
|
||||||
*/
|
*/
|
||||||
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
||||||
|
|
||||||
@@ -47,6 +47,12 @@ export type TrackRowProps = {
|
|||||||
song: BrowseSong
|
song: BrowseSong
|
||||||
/** Position in the list the selection hook was given. */
|
/** Position in the list the selection hook was given. */
|
||||||
index: number
|
index: number
|
||||||
|
/**
|
||||||
|
* The id the selection hook knows this row by, passed to the menu and
|
||||||
|
* remove callbacks. Defaults to the song id; the queue uses a per-position
|
||||||
|
* id since a song can appear more than once.
|
||||||
|
*/
|
||||||
|
selectionId?: string
|
||||||
/** Number shown in the track number column (`album` and `playlist`). */
|
/** Number shown in the track number column (`album` and `playlist`). */
|
||||||
trackNumber?: number
|
trackNumber?: number
|
||||||
/** Secondary line under the title, e.g. album track credits. */
|
/** Secondary line under the title, e.g. album track credits. */
|
||||||
@@ -71,10 +77,10 @@ export type TrackRowProps = {
|
|||||||
onPointerDown: (event: React.MouseEvent) => void
|
onPointerDown: (event: React.MouseEvent) => void
|
||||||
onPlay: (index: number) => void
|
onPlay: (index: number) => void
|
||||||
onToggleFavorite?: (songId: string) => void
|
onToggleFavorite?: (songId: string) => void
|
||||||
onPrepareContextMenu?: (songId: string) => void
|
onPrepareContextMenu?: (selectionId: string) => void
|
||||||
/** Renders the "more options" and right-click menus when provided. */
|
/** Renders the "more options" and right-click menus when provided. */
|
||||||
onMediaAction?: (action: MediaContextAction, songId: string) => void
|
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
|
||||||
onRemove?: (songId: string) => void
|
onRemove?: (selectionId: string) => void
|
||||||
/** Makes the row draggable when provided. */
|
/** Makes the row draggable when provided. */
|
||||||
onDragStart?: (index: number) => void
|
onDragStart?: (index: number) => void
|
||||||
onDrop?: (index: number) => void
|
onDrop?: (index: number) => void
|
||||||
@@ -89,13 +95,14 @@ export function TrackCover({
|
|||||||
albumId,
|
albumId,
|
||||||
alt,
|
alt,
|
||||||
inRange,
|
inRange,
|
||||||
square = false,
|
size = "md",
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
albumId: string | undefined
|
albumId: string | undefined
|
||||||
alt: string
|
alt: string
|
||||||
inRange: boolean
|
inRange: boolean
|
||||||
square?: boolean
|
/** `lg` is the larger current-song cover in the queue. */
|
||||||
|
size?: "md" | "lg"
|
||||||
/** Overlay shown above the cover image. */
|
/** Overlay shown above the cover image. */
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
@@ -105,8 +112,8 @@ export function TrackCover({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex size-10 shrink-0 items-center justify-center bg-muted ring-1",
|
"flex shrink-0 items-center justify-center bg-muted ring-1",
|
||||||
!square && "rounded",
|
size === "lg" ? "size-14 rounded-md" : "size-10 rounded",
|
||||||
ringClass
|
ringClass
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -118,8 +125,8 @@ export function TrackCover({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/cover relative size-10 shrink-0 overflow-hidden ring-1",
|
"group/cover relative shrink-0 overflow-hidden ring-1",
|
||||||
!square && "rounded",
|
size === "lg" ? "size-14 rounded-md" : "size-10 rounded",
|
||||||
ringClass
|
ringClass
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -127,7 +134,7 @@ export function TrackCover({
|
|||||||
src={albumCoverUrl(albumId)}
|
src={albumCoverUrl(albumId)}
|
||||||
alt={alt}
|
alt={alt}
|
||||||
fill
|
fill
|
||||||
sizes="40px"
|
sizes={size === "lg" ? "56px" : "40px"}
|
||||||
className="object-cover"
|
className="object-cover"
|
||||||
/>
|
/>
|
||||||
{children}
|
{children}
|
||||||
@@ -250,6 +257,7 @@ function TrackRowComponent({
|
|||||||
variant,
|
variant,
|
||||||
song,
|
song,
|
||||||
index,
|
index,
|
||||||
|
selectionId,
|
||||||
trackNumber,
|
trackNumber,
|
||||||
subtitle,
|
subtitle,
|
||||||
downloadCollection,
|
downloadCollection,
|
||||||
@@ -277,10 +285,13 @@ function TrackRowComponent({
|
|||||||
const inRange = isInSelectionRange(selectionPosition)
|
const inRange = isInSelectionRange(selectionPosition)
|
||||||
const downloadState = useSongDownloadState(song.id, downloadCollection)
|
const downloadState = useSongDownloadState(song.id, downloadCollection)
|
||||||
const isDownloaded = downloadState === "here"
|
const isDownloaded = downloadState === "here"
|
||||||
const showDownloaded = isDownloaded || downloadState === "device"
|
// The queue row only shows the duration, like the mobile queue.
|
||||||
|
const showDownloaded =
|
||||||
|
variant !== "queue" && (isDownloaded || downloadState === "device")
|
||||||
const flush = variant === "library" || variant === "queue"
|
const flush = variant === "library" || variant === "queue"
|
||||||
const play = () => onPlay(index)
|
const play = () => onPlay(index)
|
||||||
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
||||||
|
const rowId = selectionId ?? song.id
|
||||||
|
|
||||||
const favoriteStar = (
|
const favoriteStar = (
|
||||||
<div className="flex shrink-0 items-center justify-center">
|
<div className="flex shrink-0 items-center justify-center">
|
||||||
@@ -330,8 +341,8 @@ function TrackRowComponent({
|
|||||||
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
||||||
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
||||||
inSelectionRange: inRange,
|
inSelectionRange: inRange,
|
||||||
onOpenMenu: () => onPrepareContextMenu?.(song.id),
|
onOpenMenu: () => onPrepareContextMenu?.(rowId),
|
||||||
onAction: (action) => onMediaAction(action, song.id),
|
onAction: (action) => onMediaAction(action, rowId),
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite: showFavoriteInMenu,
|
showFavorite: showFavoriteInMenu,
|
||||||
favorited: isFavorite,
|
favorited: isFavorite,
|
||||||
@@ -348,7 +359,7 @@ function TrackRowComponent({
|
|||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onRemove(song.id)}
|
onClick={() => onRemove(rowId)}
|
||||||
>
|
>
|
||||||
{removeLabel}
|
{removeLabel}
|
||||||
<Trash2 />
|
<Trash2 />
|
||||||
@@ -459,12 +470,11 @@ function TrackRowComponent({
|
|||||||
break
|
break
|
||||||
case "queue":
|
case "queue":
|
||||||
content = (
|
content = (
|
||||||
<div className="relative z-10 flex items-center gap-3 px-2">
|
<div className="relative z-10 flex items-center gap-3 pr-2 pl-4">
|
||||||
<TrackCover
|
<TrackCover
|
||||||
albumId={song.album.id}
|
albumId={song.album.id}
|
||||||
alt={song.album.title}
|
alt={song.album.title}
|
||||||
inRange={inRange}
|
inRange={inRange}
|
||||||
square
|
|
||||||
/>
|
/>
|
||||||
<PlaybackSongMeta
|
<PlaybackSongMeta
|
||||||
song={song}
|
song={song}
|
||||||
@@ -474,6 +484,13 @@ function TrackRowComponent({
|
|||||||
showAlbum={false}
|
showAlbum={false}
|
||||||
/>
|
/>
|
||||||
{duration}
|
{duration}
|
||||||
|
<Menu
|
||||||
|
aria-hidden
|
||||||
|
className={cn(
|
||||||
|
"size-4 shrink-0 cursor-grab",
|
||||||
|
inRange ? "text-primary-foreground" : "text-muted-foreground"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
@@ -546,7 +563,7 @@ function TrackRowComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass stable callbacks: they receive the row's `index` or song id, so one
|
* Pass stable callbacks: they receive the row's `index`, song id or
|
||||||
* handler can serve every row.
|
* `selectionId`, so one handler can serve every row.
|
||||||
*/
|
*/
|
||||||
export const TrackRow = React.memo(TrackRowComponent)
|
export const TrackRow = React.memo(TrackRowComponent)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useState, useSyncExternalStore } from "react"
|
||||||
|
|
||||||
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||||
|
import {
|
||||||
|
followLyrics,
|
||||||
|
parseLyrics,
|
||||||
|
type Lyrics,
|
||||||
|
} from "@otunes/convex/client/lyrics"
|
||||||
|
import { readLyricsTag } from "@otunes/convex/client/lyrics-tags"
|
||||||
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
||||||
|
import { downloadedAudioBlob, downloadQueue } from "@/lib/downloads"
|
||||||
|
|
||||||
|
// Lyrics read from downloaded files, by song. Files do not change once saved.
|
||||||
|
const localLyrics = new Map<string, Promise<string | null>>()
|
||||||
|
|
||||||
|
function readLocalLyrics(songId: string) {
|
||||||
|
let lyrics = localLyrics.get(songId)
|
||||||
|
if (!lyrics) {
|
||||||
|
lyrics = downloadedAudioBlob(songId)
|
||||||
|
.then((blob) =>
|
||||||
|
blob
|
||||||
|
? readLyricsTag({
|
||||||
|
size: blob.size,
|
||||||
|
read: async (offset, length) =>
|
||||||
|
new Uint8Array(
|
||||||
|
await blob.slice(offset, offset + length).arrayBuffer()
|
||||||
|
),
|
||||||
|
})
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
.then((text) => text?.trim() || null)
|
||||||
|
.catch(() => null)
|
||||||
|
localLyrics.set(songId, lyrics)
|
||||||
|
}
|
||||||
|
return lyrics
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A song's lyrics: from its downloaded file when there is one, otherwise from
|
||||||
|
* the server. `undefined` while loading, `null` when the song has none.
|
||||||
|
*/
|
||||||
|
export function useLyrics(songId: Id<"songs"> | null) {
|
||||||
|
const downloaded = useSyncExternalStore(
|
||||||
|
downloadQueue.subscribe,
|
||||||
|
() => (songId ? downloadQueue.getDownloaded(songId) !== undefined : false),
|
||||||
|
() => false
|
||||||
|
)
|
||||||
|
const [local, setLocal] = useState<{
|
||||||
|
songId: string
|
||||||
|
text: string | null
|
||||||
|
} | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!songId || !downloaded) return
|
||||||
|
let current = true
|
||||||
|
void readLocalLyrics(songId).then((text) => {
|
||||||
|
if (current) setLocal({ songId, text })
|
||||||
|
})
|
||||||
|
return () => {
|
||||||
|
current = false
|
||||||
|
}
|
||||||
|
}, [songId, downloaded])
|
||||||
|
|
||||||
|
const localText =
|
||||||
|
songId && downloaded && local?.songId === songId ? local.text : undefined
|
||||||
|
// Songs without a downloaded copy, or whose copy has no lyrics tag.
|
||||||
|
const remote = useCachedQuery(
|
||||||
|
api.lyrics.forSong,
|
||||||
|
songId && (!downloaded || localText === null) ? { id: songId } : "skip"
|
||||||
|
)
|
||||||
|
const text = localText || remote
|
||||||
|
|
||||||
|
return useMemo<Lyrics | null | undefined>(() => {
|
||||||
|
if (!songId) return null
|
||||||
|
if (text === undefined) return undefined
|
||||||
|
return text ? parseLyrics(text) : null
|
||||||
|
}, [songId, text])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The playback time for highlighting lyrics: the player's `currentTime`,
|
||||||
|
* advanced by `followLyrics` between its progress updates.
|
||||||
|
*/
|
||||||
|
export function useLyricsTime(
|
||||||
|
lyrics: Lyrics | null | undefined,
|
||||||
|
currentTime: number,
|
||||||
|
isPlaying: boolean
|
||||||
|
) {
|
||||||
|
// Time reached since the player last reported `from`.
|
||||||
|
const [advanced, setAdvanced] = useState<{ from: number; time: number }>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!lyrics || !isPlaying) return
|
||||||
|
return followLyrics(lyrics, currentTime, (time) =>
|
||||||
|
setAdvanced({ from: currentTime, time })
|
||||||
|
)
|
||||||
|
}, [lyrics, currentTime, isPlaying])
|
||||||
|
|
||||||
|
return isPlaying && advanced?.from === currentTime
|
||||||
|
? advanced.time
|
||||||
|
: currentTime
|
||||||
|
}
|
||||||
@@ -204,11 +204,7 @@ export async function downloadedAudioUrl(songId: string) {
|
|||||||
audioUrls.set(songId, existing)
|
audioUrls.set(songId, existing)
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
const db = await openDatabase()
|
const blob = await downloadedAudioBlob(songId)
|
||||||
const blob = await readRequest<Blob | undefined>(
|
|
||||||
db.transaction(AUDIO_STORE).objectStore(AUDIO_STORE),
|
|
||||||
songId
|
|
||||||
)
|
|
||||||
if (!blob) return null
|
if (!blob) return null
|
||||||
const url = URL.createObjectURL(blob)
|
const url = URL.createObjectURL(blob)
|
||||||
audioUrls.set(songId, url)
|
audioUrls.set(songId, url)
|
||||||
@@ -218,6 +214,16 @@ export async function downloadedAudioUrl(songId: string) {
|
|||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A downloaded song's audio file, or null when it is not downloaded. */
|
||||||
|
export async function downloadedAudioBlob(songId: string) {
|
||||||
|
const db = await openDatabase()
|
||||||
|
const blob = await readRequest<Blob | undefined>(
|
||||||
|
db.transaction(AUDIO_STORE).objectStore(AUDIO_STORE),
|
||||||
|
songId
|
||||||
|
)
|
||||||
|
return blob ?? null
|
||||||
|
}
|
||||||
|
|
||||||
export function readRememberedDownloadQuality() {
|
export function readRememberedDownloadQuality() {
|
||||||
try {
|
try {
|
||||||
return parseDownloadQuality(localStorage.getItem(REMEMBERED_QUALITY_KEY))
|
return parseDownloadQuality(localStorage.getItem(REMEMBERED_QUALITY_KEY))
|
||||||
|
|||||||
@@ -22,6 +22,16 @@ export async function getSongSource(id: string): Promise<SongSource> {
|
|||||||
return song
|
return song
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The song's stored lyrics tag, or null without lyrics. */
|
||||||
|
export async function getSongLyrics(id: string): Promise<string | null> {
|
||||||
|
const token = await convexAuthNextjsToken()
|
||||||
|
return await fetchQuery(
|
||||||
|
api.lyrics.forSong,
|
||||||
|
{ id: id as Id<"songs"> },
|
||||||
|
convexServerOptions(token)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const SOURCE_BATCH_SIZE = 200
|
const SOURCE_BATCH_SIZE = 200
|
||||||
|
|
||||||
/** `getSongSource` for many songs, in batches. Missing songs are left out. */
|
/** `getSongSource` for many songs, in batches. Missing songs are left out. */
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ const isPublic = createRouteMatcher([
|
|||||||
"/api/album/:id/cover",
|
"/api/album/:id/cover",
|
||||||
"/api/artist/:id/cover",
|
"/api/artist/:id/cover",
|
||||||
"/api/playlist/:id/cover",
|
"/api/playlist/:id/cover",
|
||||||
|
// Mobile clients load avatars without the web auth cookie.
|
||||||
|
"/api/user/:id/avatar",
|
||||||
"/album/:id",
|
"/album/:id",
|
||||||
"/artist/:id",
|
"/artist/:id",
|
||||||
"/library/artists/:id",
|
"/library/artists/:id",
|
||||||
|
|||||||
@@ -0,0 +1,214 @@
|
|||||||
|
/**
|
||||||
|
* Reads the lyrics tag from a downloaded audio file, so offline playback shows
|
||||||
|
* the same lyrics the server has. Downloads are MP4 (`©lyr`), FLAC (`LYRICS`
|
||||||
|
* Vorbis comment) or MP3 (ID3 `USLT`), and only the tag bytes are read.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type ByteReader = {
|
||||||
|
size: number
|
||||||
|
read: (offset: number, length: number) => Promise<Uint8Array>
|
||||||
|
}
|
||||||
|
|
||||||
|
const utf8 = new TextDecoder("utf-8")
|
||||||
|
|
||||||
|
function ascii(bytes: Uint8Array, start: number, length: number) {
|
||||||
|
let text = ""
|
||||||
|
for (let i = start; i < Math.min(start + length, bytes.length); i++) {
|
||||||
|
text += String.fromCharCode(bytes[i])
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
function view(bytes: Uint8Array) {
|
||||||
|
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Most bytes read for a tag, so a corrupt length cannot load a whole file. */
|
||||||
|
const MAX_TAG_BYTES = 16 * 1024 * 1024
|
||||||
|
|
||||||
|
type Box = { type: string; start: number; size: number; header: number }
|
||||||
|
|
||||||
|
/** The boxes inside `bytes[start, end)`. */
|
||||||
|
function* boxes(bytes: Uint8Array, start: number, end: number) {
|
||||||
|
const data = view(bytes)
|
||||||
|
let offset = start
|
||||||
|
while (offset + 8 <= end) {
|
||||||
|
let size = data.getUint32(offset)
|
||||||
|
let header = 8
|
||||||
|
if (size === 1 && offset + 16 <= end) {
|
||||||
|
size = Number(data.getBigUint64(offset + 8))
|
||||||
|
header = 16
|
||||||
|
} else if (size === 0) {
|
||||||
|
size = end - offset
|
||||||
|
}
|
||||||
|
if (size < header) return
|
||||||
|
yield { type: ascii(bytes, offset + 4, 4), start: offset, size, header }
|
||||||
|
offset += size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function child(bytes: Uint8Array, parent: Box, type: string, skip = 0) {
|
||||||
|
for (const box of boxes(
|
||||||
|
bytes,
|
||||||
|
parent.start + parent.header + skip,
|
||||||
|
parent.start + parent.size
|
||||||
|
)) {
|
||||||
|
if (box.type === type) return box
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
async function mp4Lyrics(file: ByteReader) {
|
||||||
|
// `moov` may sit after the audio, so walk the top-level box headers.
|
||||||
|
let offset = 0
|
||||||
|
while (offset + 8 <= file.size) {
|
||||||
|
const head = await file.read(offset, 16)
|
||||||
|
if (head.length < 8) return null
|
||||||
|
const data = view(head)
|
||||||
|
let size = data.getUint32(0)
|
||||||
|
if (size === 1 && head.length === 16) size = Number(data.getBigUint64(8))
|
||||||
|
else if (size === 0) size = file.size - offset
|
||||||
|
if (size < 8) return null
|
||||||
|
if (ascii(head, 4, 4) === "moov") {
|
||||||
|
if (size > MAX_TAG_BYTES) return null
|
||||||
|
const moov = await file.read(offset, size)
|
||||||
|
const root = [...boxes(moov, 0, moov.length)][0]
|
||||||
|
const udta = root && child(moov, root, "udta")
|
||||||
|
const meta = udta && child(moov, udta, "meta")
|
||||||
|
// `meta` is a full box: 4 bytes of version and flags precede children.
|
||||||
|
const ilst = meta && child(moov, meta, "ilst", 4)
|
||||||
|
const lyr = ilst && child(moov, ilst, "\u00a9lyr")
|
||||||
|
const text = lyr && child(moov, lyr, "data")
|
||||||
|
if (!text) return null
|
||||||
|
// Type (4 bytes) and locale (4 bytes) precede the UTF-8 text.
|
||||||
|
return utf8.decode(
|
||||||
|
moov.subarray(text.start + text.header + 8, text.start + text.size)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
offset += size
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const VORBIS_LYRICS_KEYS = new Set(["LYRICS", "UNSYNCEDLYRICS"])
|
||||||
|
|
||||||
|
async function flacLyrics(file: ByteReader) {
|
||||||
|
let offset = 4
|
||||||
|
for (;;) {
|
||||||
|
const header = await file.read(offset, 4)
|
||||||
|
if (header.length < 4) return null
|
||||||
|
const last = (header[0] & 0x80) !== 0
|
||||||
|
const type = header[0] & 0x7f
|
||||||
|
const length = (header[1] << 16) | (header[2] << 8) | header[3]
|
||||||
|
offset += 4
|
||||||
|
if (type === 4) {
|
||||||
|
const block = await file.read(offset, Math.min(length, MAX_TAG_BYTES))
|
||||||
|
const data = view(block)
|
||||||
|
let at = 4 + data.getUint32(0, true)
|
||||||
|
const count = data.getUint32(at, true)
|
||||||
|
at += 4
|
||||||
|
for (let i = 0; i < count && at + 4 <= block.length; i++) {
|
||||||
|
const commentLength = data.getUint32(at, true)
|
||||||
|
const comment = utf8.decode(
|
||||||
|
block.subarray(at + 4, at + 4 + commentLength)
|
||||||
|
)
|
||||||
|
at += 4 + commentLength
|
||||||
|
const equals = comment.indexOf("=")
|
||||||
|
if (VORBIS_LYRICS_KEYS.has(comment.slice(0, equals).toUpperCase())) {
|
||||||
|
return comment.slice(equals + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (last) return null
|
||||||
|
offset += length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncsafe(bytes: Uint8Array, at: number) {
|
||||||
|
return (
|
||||||
|
(bytes[at] << 21) |
|
||||||
|
(bytes[at + 1] << 14) |
|
||||||
|
(bytes[at + 2] << 7) |
|
||||||
|
bytes[at + 3]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latin-1 (0), UTF-16 with a byte order mark (1) or UTF-16BE (2). Decoded by
|
||||||
|
* hand because React Native's TextDecoder only knows UTF-8.
|
||||||
|
*/
|
||||||
|
function decodeLegacy(raw: Uint8Array, encoding: number) {
|
||||||
|
let text = ""
|
||||||
|
if (encoding === 0) {
|
||||||
|
for (const byte of raw) text += String.fromCharCode(byte)
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
let start = 0
|
||||||
|
let bigEndian = encoding === 2
|
||||||
|
if (encoding === 1 && raw.length >= 2) {
|
||||||
|
bigEndian = raw[0] === 0xfe && raw[1] === 0xff
|
||||||
|
if (bigEndian || (raw[0] === 0xff && raw[1] === 0xfe)) start = 2
|
||||||
|
}
|
||||||
|
for (let i = start; i + 1 < raw.length; i += 2) {
|
||||||
|
text += String.fromCharCode(
|
||||||
|
bigEndian ? (raw[i] << 8) | raw[i + 1] : raw[i] | (raw[i + 1] << 8)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decodes ID3 text in `encoding`, returning it and where its terminator ends. */
|
||||||
|
function id3Text(bytes: Uint8Array, encoding: number, terminated: boolean) {
|
||||||
|
const wide = encoding === 1 || encoding === 2
|
||||||
|
let end = bytes.length
|
||||||
|
if (terminated) {
|
||||||
|
for (let i = 0; i < bytes.length; i += wide ? 2 : 1) {
|
||||||
|
if (bytes[i] === 0 && (!wide || bytes[i + 1] === 0)) {
|
||||||
|
end = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const raw = bytes.subarray(0, end)
|
||||||
|
const text = encoding === 3 ? utf8.decode(raw) : decodeLegacy(raw, encoding)
|
||||||
|
return { text, next: Math.min(bytes.length, end + (wide ? 2 : 1)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function id3Lyrics(file: ByteReader) {
|
||||||
|
const header = await file.read(0, 10)
|
||||||
|
const version = header[3]
|
||||||
|
const size = syncsafe(header, 6)
|
||||||
|
if (size > MAX_TAG_BYTES) return null
|
||||||
|
const tag = await file.read(10, size)
|
||||||
|
const data = view(tag)
|
||||||
|
let at = 0
|
||||||
|
while (at + 10 <= tag.length) {
|
||||||
|
const id = ascii(tag, at, 4)
|
||||||
|
if (!/^[A-Z0-9]{4}$/.test(id)) return null
|
||||||
|
const frameSize =
|
||||||
|
version === 4 ? syncsafe(tag, at + 4) : data.getUint32(at + 4)
|
||||||
|
const body = tag.subarray(at + 10, at + 10 + frameSize)
|
||||||
|
at += 10 + frameSize
|
||||||
|
if (id !== "USLT" || body.length < 5) continue
|
||||||
|
const encoding = body[0]
|
||||||
|
// Encoding, a 3 letter language, then a terminated description.
|
||||||
|
const description = id3Text(body.subarray(4), encoding, true)
|
||||||
|
return id3Text(body.subarray(4 + description.next), encoding, false).text
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The raw lyrics tag of an audio file, or null when it has none. */
|
||||||
|
export async function readLyricsTag(file: ByteReader): Promise<string | null> {
|
||||||
|
const head = await file.read(0, 12)
|
||||||
|
const magic = ascii(head, 0, 4)
|
||||||
|
try {
|
||||||
|
if (magic === "fLaC") return await flacLyrics(file)
|
||||||
|
if (magic.startsWith("ID3")) return await id3Lyrics(file)
|
||||||
|
if (ascii(head, 4, 4) === "ftyp") return await mp4Lyrics(file)
|
||||||
|
} catch {
|
||||||
|
// An unexpected layout reads as no lyrics; the server copy is used instead.
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
/**
|
||||||
|
* Lyrics as tagged in the music files: plain text, LRC (`[mm:ss.xx]line`), or
|
||||||
|
* word-timed LRC (`<mm:ss.xx>word`). The server stores that text unchanged and
|
||||||
|
* clients parse it here, so a downloaded file's tag and the server copy read
|
||||||
|
* the same.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type LyricWord = {
|
||||||
|
/** Includes its trailing space, so a line's words join back into its text. */
|
||||||
|
text: string
|
||||||
|
start: number
|
||||||
|
end: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LyricLine = {
|
||||||
|
text: string
|
||||||
|
/** Seconds; `null` for plain lyrics. */
|
||||||
|
start: number | null
|
||||||
|
/** Set only on word-timed lines. */
|
||||||
|
words: LyricWord[] | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Lyrics = {
|
||||||
|
synced: "none" | "line" | "word"
|
||||||
|
lines: LyricLine[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const LINE_STAMP = /^\[(\d+):(\d+(?:[.:]\d+)?)\]/
|
||||||
|
const WORD_STAMP = /<(\d+):(\d+(?:[.:]\d+)?)>/g
|
||||||
|
const HAS_WORD_STAMP = /<\d+:\d+(?:[.:]\d+)?>/
|
||||||
|
const ID_TAG = /^\[[a-z]+:.*\]$/i
|
||||||
|
|
||||||
|
function seconds(minutes: string, rest: string) {
|
||||||
|
return Number(minutes) * 60 + Number(rest.replace(":", "."))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Splits `<t>word <t>word<t>` into words; the last stamp ends the last word. */
|
||||||
|
function parseWords(body: string): LyricWord[] {
|
||||||
|
const stamps = [...body.matchAll(WORD_STAMP)]
|
||||||
|
const words: LyricWord[] = []
|
||||||
|
for (let i = 0; i < stamps.length; i++) {
|
||||||
|
const stamp = stamps[i]
|
||||||
|
const textStart = stamp.index + stamp[0].length
|
||||||
|
const next = stamps[i + 1]
|
||||||
|
const text = body.slice(textStart, next?.index ?? body.length)
|
||||||
|
const start = seconds(stamp[1], stamp[2])
|
||||||
|
if (text.trim()) {
|
||||||
|
words.push({
|
||||||
|
text,
|
||||||
|
start,
|
||||||
|
end: next ? seconds(next[1], next[2]) : start,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return words
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseLyrics(raw: string): Lyrics | null {
|
||||||
|
const rows = raw.replace(/\r\n?/g, "\n").split("\n")
|
||||||
|
const timed = rows.some((row) => LINE_STAMP.test(row.trim()))
|
||||||
|
const wordTimed = rows.some((row) => HAS_WORD_STAMP.test(row))
|
||||||
|
|
||||||
|
if (!timed && !wordTimed) {
|
||||||
|
const lines = rows.map((row) => ({
|
||||||
|
text: row.trim(),
|
||||||
|
start: null,
|
||||||
|
words: null,
|
||||||
|
}))
|
||||||
|
// Blank rows between stanzas stay as spacing; ones at the ends go.
|
||||||
|
while (lines[0]?.text === "") lines.shift()
|
||||||
|
while (lines.at(-1)?.text === "") lines.pop()
|
||||||
|
return lines.length > 0 ? { synced: "none", lines } : null
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines: LyricLine[] = []
|
||||||
|
for (const row of rows) {
|
||||||
|
let body = row.trim()
|
||||||
|
if (ID_TAG.test(body) && !LINE_STAMP.test(body)) continue
|
||||||
|
// A line may repeat under several stamps: `[00:12.00][01:30.00]Chorus`.
|
||||||
|
const starts: number[] = []
|
||||||
|
for (let match = LINE_STAMP.exec(body); match;) {
|
||||||
|
starts.push(seconds(match[1], match[2]))
|
||||||
|
body = body.slice(match[0].length)
|
||||||
|
match = LINE_STAMP.exec(body)
|
||||||
|
}
|
||||||
|
const words = wordTimed ? parseWords(body) : []
|
||||||
|
const text = (
|
||||||
|
words.length > 0 ? words.map((word) => word.text).join("") : body
|
||||||
|
).trim()
|
||||||
|
if (!text) continue
|
||||||
|
if (starts.length === 0 && words.length > 0) starts.push(words[0].start)
|
||||||
|
for (const start of starts) {
|
||||||
|
const shift = words.length > 0 ? start - words[0].start : 0
|
||||||
|
lines.push({
|
||||||
|
text,
|
||||||
|
start,
|
||||||
|
words:
|
||||||
|
words.length > 0
|
||||||
|
? words.map((word) => ({
|
||||||
|
...word,
|
||||||
|
start: word.start + shift,
|
||||||
|
end: word.end + shift,
|
||||||
|
}))
|
||||||
|
: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.sort((a, b) => a.start! - b.start!)
|
||||||
|
if (lines.length === 0) return null
|
||||||
|
return {
|
||||||
|
synced: lines.every((line) => line.words) ? "word" : "line",
|
||||||
|
lines,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The text without timestamps, one line per row, for search and snippets. */
|
||||||
|
export function plainLyrics(lyrics: Lyrics) {
|
||||||
|
return lyrics.lines.map((line) => line.text).join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How well a tag's lyrics are timed, to keep the best of a song's files. */
|
||||||
|
export function lyricsRank(raw: string | null) {
|
||||||
|
const synced = raw ? parseLyrics(raw)?.synced : undefined
|
||||||
|
return synced === "word" ? 3 : synced === "line" ? 2 : synced ? 1 : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The line playing at `time` (the last one started), or -1 before the first.
|
||||||
|
* Plain lyrics never have one.
|
||||||
|
*/
|
||||||
|
export function activeLineIndex(lyrics: Lyrics, time: number) {
|
||||||
|
let active = -1
|
||||||
|
for (let i = 0; i < lyrics.lines.length; i++) {
|
||||||
|
const start = lyrics.lines[i].start
|
||||||
|
if (start === null || start > time) break
|
||||||
|
active = i
|
||||||
|
}
|
||||||
|
return active
|
||||||
|
}
|
||||||
|
|
||||||
|
/** When the highlighted line or word next changes after `time`, if ever. */
|
||||||
|
export function nextLyricsChange(lyrics: Lyrics, time: number) {
|
||||||
|
let next = Infinity
|
||||||
|
for (const line of lyrics.lines) {
|
||||||
|
if (line.start !== null && line.start > time) {
|
||||||
|
next = Math.min(next, line.start)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for (const word of line.words ?? []) {
|
||||||
|
if (word.start > time) {
|
||||||
|
next = Math.min(next, word.start)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While audio plays on from `time` seconds, calls `onChange` with the playback
|
||||||
|
* time whenever the highlighted line or word changes. Players report progress
|
||||||
|
* only a few times a second, which is too coarse for word timing. Returns a
|
||||||
|
* function that stops it.
|
||||||
|
*/
|
||||||
|
export function followLyrics(
|
||||||
|
lyrics: Lyrics,
|
||||||
|
time: number,
|
||||||
|
onChange: (time: number) => void
|
||||||
|
) {
|
||||||
|
const startedAt = Date.now() - time * 1000
|
||||||
|
let timer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
const schedule = (from: number) => {
|
||||||
|
const next = nextLyricsChange(lyrics, from)
|
||||||
|
if (!Number.isFinite(next)) return
|
||||||
|
timer = setTimeout(
|
||||||
|
() => {
|
||||||
|
const now = (Date.now() - startedAt) / 1000
|
||||||
|
onChange(now)
|
||||||
|
schedule(now)
|
||||||
|
},
|
||||||
|
(next - from) * 1000
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (lyrics.synced !== "none") schedule(time)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lowercase words of a search, for matching lyrics the way the search index does. */
|
||||||
|
function searchTerms(query: string): string[] {
|
||||||
|
return query.toLowerCase().match(/[\p{L}\p{N}']+/gu) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
const SNIPPET_LEAD = 24
|
||||||
|
|
||||||
|
export type LyricsMatch = {
|
||||||
|
/** The matched line, trimmed to start near the match. */
|
||||||
|
snippet: string
|
||||||
|
/** Whether the line holds the query as typed, not just its words. */
|
||||||
|
exact: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where a search matched the lyrics: a line holding the query as typed, or
|
||||||
|
* else a line holding every word of it (the last may be a prefix, as when
|
||||||
|
* typing). Null when no single line does.
|
||||||
|
*/
|
||||||
|
export function matchLyrics(plain: string, query: string): LyricsMatch | null {
|
||||||
|
const needle = query.trim().toLowerCase()
|
||||||
|
const terms = searchTerms(needle)
|
||||||
|
const last = terms.at(-1)
|
||||||
|
if (!needle || last === undefined) return null
|
||||||
|
|
||||||
|
let loose: string | null = null
|
||||||
|
for (const line of plain.split("\n")) {
|
||||||
|
const column = line.toLowerCase().indexOf(needle)
|
||||||
|
if (column !== -1) {
|
||||||
|
const snippet =
|
||||||
|
column > SNIPPET_LEAD
|
||||||
|
? `…${line.slice(column - SNIPPET_LEAD).trimStart()}`
|
||||||
|
: line.trim()
|
||||||
|
return { snippet, exact: true }
|
||||||
|
}
|
||||||
|
if (loose === null) {
|
||||||
|
const words = searchTerms(line)
|
||||||
|
const hasAll =
|
||||||
|
terms.slice(0, -1).every((term) => words.includes(term)) &&
|
||||||
|
words.some((word) => word.startsWith(last))
|
||||||
|
if (hasAll) loose = line.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loose === null ? null : { snippet: loose, exact: false }
|
||||||
|
}
|
||||||
@@ -1,21 +1,30 @@
|
|||||||
type SearchableSong = {
|
type SearchableSong = {
|
||||||
|
id: string
|
||||||
title: string
|
title: string
|
||||||
artist: { name: string }
|
artist: { name: string }
|
||||||
album: { title: string }
|
album: { title: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Case-insensitive match on title, artist, or album. A blank query keeps every song. */
|
/**
|
||||||
|
* Case-insensitive match on title, artist, or album, plus the songs in
|
||||||
|
* `lyricsMatches` (from `api.lyrics.matchingSongIds`). A blank query keeps
|
||||||
|
* every song.
|
||||||
|
*/
|
||||||
export function filterSongs<T extends SearchableSong>(
|
export function filterSongs<T extends SearchableSong>(
|
||||||
songs: T[],
|
songs: T[],
|
||||||
query: string
|
query: string,
|
||||||
|
lyricsMatches?: readonly string[]
|
||||||
) {
|
) {
|
||||||
const normalized = query.trim().toLowerCase()
|
const normalized = query.trim().toLowerCase()
|
||||||
if (!normalized) {
|
if (!normalized) {
|
||||||
return songs
|
return songs
|
||||||
}
|
}
|
||||||
return songs.filter((song) =>
|
const byLyrics = new Set(lyricsMatches)
|
||||||
[song.title, song.artist.name, song.album.title].some((value) =>
|
return songs.filter(
|
||||||
value.toLowerCase().includes(normalized)
|
(song) =>
|
||||||
)
|
byLyrics.has(song.id) ||
|
||||||
|
[song.title, song.artist.name, song.album.title].some((value) =>
|
||||||
|
value.toLowerCase().includes(normalized)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+2
@@ -19,6 +19,7 @@ import type * as intentCatalog from "../intentCatalog.js";
|
|||||||
import type * as intentCatalogChanges from "../intentCatalogChanges.js";
|
import type * as intentCatalogChanges from "../intentCatalogChanges.js";
|
||||||
import type * as library from "../library.js";
|
import type * as library from "../library.js";
|
||||||
import type * as limits from "../limits.js";
|
import type * as limits from "../limits.js";
|
||||||
|
import type * as lyrics from "../lyrics.js";
|
||||||
import type * as migrations from "../migrations.js";
|
import type * as migrations from "../migrations.js";
|
||||||
import type * as playback from "../playback.js";
|
import type * as playback from "../playback.js";
|
||||||
import type * as playbackState from "../playbackState.js";
|
import type * as playbackState from "../playbackState.js";
|
||||||
@@ -46,6 +47,7 @@ declare const fullApi: ApiFromModules<{
|
|||||||
intentCatalogChanges: typeof intentCatalogChanges;
|
intentCatalogChanges: typeof intentCatalogChanges;
|
||||||
library: typeof library;
|
library: typeof library;
|
||||||
limits: typeof limits;
|
limits: typeof limits;
|
||||||
|
lyrics: typeof lyrics;
|
||||||
migrations: typeof migrations;
|
migrations: typeof migrations;
|
||||||
playback: typeof playback;
|
playback: typeof playback;
|
||||||
playbackState: typeof playbackState;
|
playbackState: typeof playbackState;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { ConvexError } from "convex/values"
|
|||||||
|
|
||||||
import type { Id } from "./_generated/dataModel"
|
import type { Id } from "./_generated/dataModel"
|
||||||
import { action, internalAction, type ActionCtx } from "./_generated/server"
|
import { action, internalAction, type ActionCtx } from "./_generated/server"
|
||||||
|
import { lyricsRank } from "../client/lyrics"
|
||||||
|
|
||||||
const DATA_DIR = process.env.DATA || "/data"
|
const DATA_DIR = process.env.DATA || "/data"
|
||||||
const HLS_CACHE_DIR = "/tmp/otunes"
|
const HLS_CACHE_DIR = "/tmp/otunes"
|
||||||
@@ -67,6 +68,8 @@ const SCAN_LOCK_LEASE_MS = 15 * 60 * 1000
|
|||||||
/** New files left unparsed after this are picked up by the next scan. */
|
/** New files left unparsed after this are picked up by the next scan. */
|
||||||
const SCAN_PARSE_BUDGET_MS = 6 * 60 * 1000
|
const SCAN_PARSE_BUDGET_MS = 6 * 60 * 1000
|
||||||
const SCAN_BATCH_SIZE = 200
|
const SCAN_BATCH_SIZE = 200
|
||||||
|
/** Lyrics text per mutation, well under Convex's argument size limit. */
|
||||||
|
const SCAN_BATCH_LYRICS_BYTES = 2 * 1024 * 1024
|
||||||
const FS_CONCURRENCY = 16
|
const FS_CONCURRENCY = 16
|
||||||
|
|
||||||
type Page<T> = { page: T[]; isDone: boolean; continueCursor: string }
|
type Page<T> = { page: T[]; isDone: boolean; continueCursor: string }
|
||||||
@@ -220,6 +223,55 @@ function releaseDate(common: music.ICommonTagsResult) {
|
|||||||
return common.year ? `01-01-${common.year}` : ""
|
return common.year ? `01-01-${common.year}` : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LYRICS_TAG_IDS = new Set(["©LYR", "LYRICS", "UNSYNCEDLYRICS", "USLT"])
|
||||||
|
|
||||||
|
function lrcStamp(milliseconds: number) {
|
||||||
|
const totalSeconds = milliseconds / 1000
|
||||||
|
const minutes = Math.floor(totalSeconds / 60)
|
||||||
|
const rest = (totalSeconds - minutes * 60).toFixed(2).padStart(5, "0")
|
||||||
|
return `[${String(minutes).padStart(2, "0")}:${rest}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One native tag's lyrics as text; ID3 synced lyrics become LRC. */
|
||||||
|
function lyricsTagText({ id, value }: music.ITag): string | null {
|
||||||
|
const key = id.toUpperCase()
|
||||||
|
if (typeof value === "string") {
|
||||||
|
return LYRICS_TAG_IDS.has(key) ? value : null
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(key !== "USLT" && key !== "SYLT") ||
|
||||||
|
!value ||
|
||||||
|
typeof value !== "object"
|
||||||
|
) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const lyrics = value as music.ILyricsTag
|
||||||
|
const synced = lyrics.syncText ?? []
|
||||||
|
// Timestamp format 2 is milliseconds; frame-based stamps cannot be used.
|
||||||
|
if (synced.length > 0 && lyrics.timeStampFormat === 2) {
|
||||||
|
return synced
|
||||||
|
.map((line) => `${lrcStamp(line.timestamp ?? 0)}${line.text}`)
|
||||||
|
.join("\n")
|
||||||
|
}
|
||||||
|
return lyrics.text ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The best timed lyrics tag in a file, or null without one. */
|
||||||
|
function lyricsTag(metadata: music.IAudioMetadata): string | null {
|
||||||
|
let best: string | null = null
|
||||||
|
for (const tags of Object.values(metadata.native)) {
|
||||||
|
for (const tag of tags) {
|
||||||
|
const text = lyricsTagText(tag)?.trim() || null
|
||||||
|
if (lyricsRank(text) > lyricsRank(best)) best = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best
|
||||||
|
}
|
||||||
|
|
||||||
|
function betterLyrics(a: string | null, b: string | null) {
|
||||||
|
return lyricsRank(b) > lyricsRank(a) ? b : a
|
||||||
|
}
|
||||||
|
|
||||||
type NewSong = {
|
type NewSong = {
|
||||||
name: string
|
name: string
|
||||||
files: Record<string, string>
|
files: Record<string, string>
|
||||||
@@ -230,6 +282,7 @@ type NewSong = {
|
|||||||
year: number
|
year: number
|
||||||
date: string
|
date: string
|
||||||
genres: string[]
|
genres: string[]
|
||||||
|
lyrics: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImportEntry = {
|
type ImportEntry = {
|
||||||
@@ -386,9 +439,11 @@ async function scanLibrary(ctx: ActionCtx) {
|
|||||||
imports.set(key, entry)
|
imports.set(key, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lyrics = lyricsTag(metadata)
|
||||||
const pending = entry.songs.get(title)
|
const pending = entry.songs.get(title)
|
||||||
if (pending) {
|
if (pending) {
|
||||||
pending.files[codec] ??= filePath
|
pending.files[codec] ??= filePath
|
||||||
|
pending.lyrics = betterLyrics(pending.lyrics, lyrics)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
entry.songs.set(title, {
|
entry.songs.set(title, {
|
||||||
@@ -402,9 +457,39 @@ async function scanLibrary(ctx: ActionCtx) {
|
|||||||
year: common.year || 0,
|
year: common.year || 0,
|
||||||
date: releaseDate(common),
|
date: releaseDate(common),
|
||||||
genres: common.genre || [],
|
genres: common.genre || [],
|
||||||
|
lyrics,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Songs scanned before lyrics were stored, read once for their lyrics.
|
||||||
|
const unreadLyrics = songs.filter(
|
||||||
|
(song) =>
|
||||||
|
song.hasLyrics === undefined &&
|
||||||
|
Object.keys(songFiles.get(song._id)!).length > 0
|
||||||
|
)
|
||||||
|
const readLyrics = await mapLimit(
|
||||||
|
unreadLyrics,
|
||||||
|
FS_CONCURRENCY,
|
||||||
|
async (song) => {
|
||||||
|
let best: string | null = null
|
||||||
|
for (const filePath of Object.values(songFiles.get(song._id)!)) {
|
||||||
|
if (Date.now() > deadline) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const metadata = await music.parseFile(filePath, {
|
||||||
|
skipCovers: true,
|
||||||
|
})
|
||||||
|
best = betterLyrics(best, lyricsTag(metadata))
|
||||||
|
} catch {
|
||||||
|
// An unreadable file contributes no lyrics.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { id: song._id, lyrics: best }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const songLyrics = readLyrics.filter((song) => song !== null)
|
||||||
|
|
||||||
const deletedSongs = songs.flatMap((song) =>
|
const deletedSongs = songs.flatMap((song) =>
|
||||||
Object.keys(songFiles.get(song._id)!).length === 0 ? [song._id] : []
|
Object.keys(songFiles.get(song._id)!).length === 0 ? [song._id] : []
|
||||||
)
|
)
|
||||||
@@ -469,6 +554,7 @@ async function scanLibrary(ctx: ActionCtx) {
|
|||||||
|
|
||||||
let importBatch: ImportEntry[] = []
|
let importBatch: ImportEntry[] = []
|
||||||
let importBatchSongs = 0
|
let importBatchSongs = 0
|
||||||
|
let importBatchBytes = 0
|
||||||
const flushImports = async () => {
|
const flushImports = async () => {
|
||||||
if (importBatch.length === 0) {
|
if (importBatch.length === 0) {
|
||||||
return
|
return
|
||||||
@@ -481,16 +567,41 @@ async function scanLibrary(ctx: ActionCtx) {
|
|||||||
})
|
})
|
||||||
importBatch = []
|
importBatch = []
|
||||||
importBatchSongs = 0
|
importBatchSongs = 0
|
||||||
|
importBatchBytes = 0
|
||||||
}
|
}
|
||||||
for (const entry of imports.values()) {
|
for (const entry of imports.values()) {
|
||||||
importBatch.push(entry)
|
importBatch.push(entry)
|
||||||
importBatchSongs += entry.songs.size
|
importBatchSongs += entry.songs.size
|
||||||
if (importBatchSongs >= SCAN_BATCH_SIZE) {
|
for (const song of entry.songs.values()) {
|
||||||
|
importBatchBytes += song.lyrics?.length ?? 0
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
importBatchSongs >= SCAN_BATCH_SIZE ||
|
||||||
|
importBatchBytes >= SCAN_BATCH_LYRICS_BYTES
|
||||||
|
) {
|
||||||
await flushImports()
|
await flushImports()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await flushImports()
|
await flushImports()
|
||||||
|
|
||||||
|
let lyricsBatch: typeof songLyrics = []
|
||||||
|
let lyricsBatchBytes = 0
|
||||||
|
for (const [index, song] of songLyrics.entries()) {
|
||||||
|
lyricsBatch.push(song)
|
||||||
|
lyricsBatchBytes += song.lyrics?.length ?? 0
|
||||||
|
if (
|
||||||
|
lyricsBatch.length >= SCAN_BATCH_SIZE ||
|
||||||
|
lyricsBatchBytes >= SCAN_BATCH_LYRICS_BYTES ||
|
||||||
|
index === songLyrics.length - 1
|
||||||
|
) {
|
||||||
|
await ctx.runMutation(internal.lyrics.setSongLyrics, {
|
||||||
|
songs: lyricsBatch,
|
||||||
|
})
|
||||||
|
lyricsBatch = []
|
||||||
|
lyricsBatchBytes = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const batch of chunk(artistCovers, SCAN_BATCH_SIZE)) {
|
for (const batch of chunk(artistCovers, SCAN_BATCH_SIZE)) {
|
||||||
await ctx.runMutation(internal.library.updateArtistCovers, {
|
await ctx.runMutation(internal.library.updateArtistCovers, {
|
||||||
artists: batch,
|
artists: batch,
|
||||||
@@ -523,7 +634,8 @@ async function scanLibrary(ctx: ActionCtx) {
|
|||||||
)
|
)
|
||||||
const summary =
|
const summary =
|
||||||
`songs: ${importedSongs} added, ${updatedSongs.length} updated, ` +
|
`songs: ${importedSongs} added, ${updatedSongs.length} updated, ` +
|
||||||
`${deletedSongs.length} removed; albums removed: ${removedAlbums}; ` +
|
`${deletedSongs.length} removed, ${songLyrics.length} read for lyrics ` +
|
||||||
|
`(${unreadLyrics.length - songLyrics.length} deferred); albums removed: ${removedAlbums}; ` +
|
||||||
`artists removed: ${removedArtists}; covers updated: ` +
|
`artists removed: ${removedArtists}; covers updated: ` +
|
||||||
`${artistCovers.length + albumCovers.length}; ` +
|
`${artistCovers.length + albumCovers.length}; ` +
|
||||||
`files deferred: ${skipped}; ${Date.now() - startedAt}ms`
|
`files deferred: ${skipped}; ${Date.now() - startedAt}ms`
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import type {
|
|||||||
LibrarySearchResults,
|
LibrarySearchResults,
|
||||||
OwnedPlaylistForAdd,
|
OwnedPlaylistForAdd,
|
||||||
PlaylistSummary,
|
PlaylistSummary,
|
||||||
|
SearchSong,
|
||||||
SearchTopResultItem,
|
SearchTopResultItem,
|
||||||
SidebarPlaylists,
|
SidebarPlaylists,
|
||||||
} from "./types"
|
} from "./types"
|
||||||
@@ -25,6 +26,7 @@ import { purgeFavoriteEntities } from "./favoriteStore"
|
|||||||
import { chunk, type Chunked } from "./limits"
|
import { chunk, type Chunked } from "./limits"
|
||||||
import { recordIntentCatalogChanges } from "./intentCatalogChanges"
|
import { recordIntentCatalogChanges } from "./intentCatalogChanges"
|
||||||
import { playlistCoverVersion } from "./playlistCover"
|
import { playlistCoverVersion } from "./playlistCover"
|
||||||
|
import { deleteSongLyrics, searchSongLyrics, writeSongLyrics } from "./lyrics"
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
BrowseAlbum,
|
BrowseAlbum,
|
||||||
@@ -39,6 +41,7 @@ export type {
|
|||||||
LibrarySearchResults,
|
LibrarySearchResults,
|
||||||
OwnedPlaylistForAdd,
|
OwnedPlaylistForAdd,
|
||||||
PlaylistSummary,
|
PlaylistSummary,
|
||||||
|
SearchSong,
|
||||||
SearchTopResultItem,
|
SearchTopResultItem,
|
||||||
SidebarPlaylists,
|
SidebarPlaylists,
|
||||||
} from "./types"
|
} from "./types"
|
||||||
@@ -648,6 +651,9 @@ function matchScoreSongArtists(
|
|||||||
*/
|
*/
|
||||||
const MAX_SEARCH_RESULTS = 500
|
const MAX_SEARCH_RESULTS = 500
|
||||||
|
|
||||||
|
/** Songs found by lyrics alone, listed after title, artist and album matches. */
|
||||||
|
const MAX_LYRICS_SEARCH_RESULTS = 50
|
||||||
|
|
||||||
export const searchLibrary = query({
|
export const searchLibrary = query({
|
||||||
args: { query: v.string() },
|
args: { query: v.string() },
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
@@ -732,6 +738,25 @@ export const searchLibrary = query({
|
|||||||
(a, b) => b.score - a.score || a.item.title.localeCompare(b.item.title)
|
(a, b) => b.score - a.score || a.item.title.localeCompare(b.item.title)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const songById = new Map(songs.map((song) => [song._id, song]))
|
||||||
|
const matchedSongIds = new Set(songResults.map((result) => result.item.id))
|
||||||
|
const lyricsResults: SearchSong[] = (
|
||||||
|
await searchSongLyrics(ctx, args.query, MAX_LYRICS_SEARCH_RESULTS)
|
||||||
|
).flatMap(({ song: songId, snippet }) => {
|
||||||
|
const song = songById.get(songId)
|
||||||
|
const album = song && albumMap.get(song.album)
|
||||||
|
const albumArtist = song && artistMap.get(song.albumArtist)
|
||||||
|
if (!song || !album || !albumArtist || matchedSongIds.has(songId)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
...toBrowseSong(song, album, albumArtist),
|
||||||
|
lyricsSnippet: snippet,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
const topResults: SearchTopResultItem[] = [
|
const topResults: SearchTopResultItem[] = [
|
||||||
...songResults,
|
...songResults,
|
||||||
...albumResults,
|
...albumResults,
|
||||||
@@ -749,9 +774,10 @@ export const searchLibrary = query({
|
|||||||
albums: albumResults
|
albums: albumResults
|
||||||
.slice(0, MAX_SEARCH_RESULTS)
|
.slice(0, MAX_SEARCH_RESULTS)
|
||||||
.map((result) => result.item),
|
.map((result) => result.item),
|
||||||
songs: songResults
|
songs: [
|
||||||
.slice(0, MAX_SEARCH_RESULTS)
|
...songResults.map((result): SearchSong => result.item),
|
||||||
.map((result) => result.item),
|
...lyricsResults,
|
||||||
|
].slice(0, MAX_SEARCH_RESULTS),
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
@@ -934,11 +960,12 @@ export const scanSongsPage = internalQuery({
|
|||||||
const result = await ctx.db.query("songs").paginate(args.paginationOpts)
|
const result = await ctx.db.query("songs").paginate(args.paginationOpts)
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
page: result.page.map(({ _id, name, files, album }) => ({
|
page: result.page.map(({ _id, name, files, album, hasLyrics }) => ({
|
||||||
_id,
|
_id,
|
||||||
name,
|
name,
|
||||||
files,
|
files,
|
||||||
album,
|
album,
|
||||||
|
hasLyrics,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1100,6 +1127,8 @@ export const importAlbums = internalMutation({
|
|||||||
year: v.number(),
|
year: v.number(),
|
||||||
date: v.string(),
|
date: v.string(),
|
||||||
genres: v.array(v.string()),
|
genres: v.array(v.string()),
|
||||||
|
/** The best lyrics tag among the song's files. */
|
||||||
|
lyrics: v.nullable(v.string()),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@@ -1130,7 +1159,7 @@ export const importAlbums = internalMutation({
|
|||||||
)?._id ??
|
)?._id ??
|
||||||
(await ctx.db.insert("albums", { ...entry.album, artist: artistId }))
|
(await ctx.db.insert("albums", { ...entry.album, artist: artistId }))
|
||||||
|
|
||||||
for (const song of entry.songs) {
|
for (const { lyrics, ...song } of entry.songs) {
|
||||||
const existing = await ctx.db
|
const existing = await ctx.db
|
||||||
.query("songs")
|
.query("songs")
|
||||||
.withIndex("by_all", (q) =>
|
.withIndex("by_all", (q) =>
|
||||||
@@ -1146,11 +1175,12 @@ export const importAlbums = internalMutation({
|
|||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
await ctx.db.insert("songs", {
|
const songId = await ctx.db.insert("songs", {
|
||||||
...song,
|
...song,
|
||||||
album: albumId,
|
album: albumId,
|
||||||
albumArtist: artistId,
|
albumArtist: artistId,
|
||||||
})
|
})
|
||||||
|
await writeSongLyrics(ctx, songId, lyrics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1162,6 +1192,7 @@ export const deleteSongs = internalMutation({
|
|||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
for (const id of args.ids) {
|
for (const id of args.ids) {
|
||||||
await ctx.db.delete("songs", id)
|
await ctx.db.delete("songs", id)
|
||||||
|
await deleteSongLyrics(ctx, id)
|
||||||
}
|
}
|
||||||
await purgeSongsFromUsersAndPlaylists(ctx, new Set(args.ids))
|
await purgeSongsFromUsersAndPlaylists(ctx, new Set(args.ids))
|
||||||
await recordIntentCatalogChanges(ctx, "song", args.ids, true)
|
await recordIntentCatalogChanges(ctx, "song", args.ids, true)
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { getAuthUserId } from "@convex-dev/auth/server"
|
||||||
|
import { v } from "convex/values"
|
||||||
|
|
||||||
|
import type { Id } from "./_generated/dataModel"
|
||||||
|
import {
|
||||||
|
internalMutation,
|
||||||
|
query,
|
||||||
|
type MutationCtx,
|
||||||
|
type QueryCtx,
|
||||||
|
} from "./_generated/server"
|
||||||
|
import { matchLyrics, parseLyrics, plainLyrics } from "../client/lyrics"
|
||||||
|
|
||||||
|
/** Shorter searches match too much of every song to be useful. */
|
||||||
|
const MIN_LYRICS_QUERY_LENGTH = 3
|
||||||
|
|
||||||
|
/** The largest page a search index returns. */
|
||||||
|
const MAX_LYRICS_MATCHES = 1_024
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces a song's lyrics, or removes them when `text` is null or holds no
|
||||||
|
* lyrics, and marks the song as read for lyrics.
|
||||||
|
*/
|
||||||
|
export async function writeSongLyrics(
|
||||||
|
ctx: MutationCtx,
|
||||||
|
songId: Id<"songs">,
|
||||||
|
text: string | null
|
||||||
|
) {
|
||||||
|
const lyrics = text ? parseLyrics(text) : null
|
||||||
|
const [stored, searchable] = await Promise.all([
|
||||||
|
ctx.db
|
||||||
|
.query("lyrics")
|
||||||
|
.withIndex("by_song", (q) => q.eq("song", songId))
|
||||||
|
.first(),
|
||||||
|
ctx.db
|
||||||
|
.query("lyricsSearch")
|
||||||
|
.withIndex("by_song", (q) => q.eq("song", songId))
|
||||||
|
.first(),
|
||||||
|
])
|
||||||
|
await ctx.db.patch("songs", songId, { hasLyrics: lyrics !== null })
|
||||||
|
|
||||||
|
if (!lyrics || !text) {
|
||||||
|
if (stored) await ctx.db.delete("lyrics", stored._id)
|
||||||
|
if (searchable) await ctx.db.delete("lyricsSearch", searchable._id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const plain = plainLyrics(lyrics)
|
||||||
|
if (stored) await ctx.db.patch("lyrics", stored._id, { text })
|
||||||
|
else await ctx.db.insert("lyrics", { song: songId, text })
|
||||||
|
if (searchable) await ctx.db.patch("lyricsSearch", searchable._id, { plain })
|
||||||
|
else await ctx.db.insert("lyricsSearch", { song: songId, plain })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes a deleted song's lyrics. */
|
||||||
|
export async function deleteSongLyrics(ctx: MutationCtx, songId: Id<"songs">) {
|
||||||
|
for (const table of ["lyrics", "lyricsSearch"] as const) {
|
||||||
|
const row = await ctx.db
|
||||||
|
.query(table)
|
||||||
|
.withIndex("by_song", (q) => q.eq("song", songId))
|
||||||
|
.first()
|
||||||
|
if (row) await ctx.db.delete(table, row._id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Songs with a lyrics line matching `query` (see `matchLyrics`), with that
|
||||||
|
* line. Lines holding the query as typed come first, then the search index's
|
||||||
|
* relevance order. The index matches words anywhere in the lyrics, so its
|
||||||
|
* results are checked line by line.
|
||||||
|
*/
|
||||||
|
export async function searchSongLyrics(
|
||||||
|
ctx: QueryCtx,
|
||||||
|
query: string,
|
||||||
|
limit: number
|
||||||
|
): Promise<{ song: Id<"songs">; snippet: string }[]> {
|
||||||
|
const text = query.trim()
|
||||||
|
if (text.length < MIN_LYRICS_QUERY_LENGTH) return []
|
||||||
|
const rows = await ctx.db
|
||||||
|
.query("lyricsSearch")
|
||||||
|
.withSearchIndex("search_plain", (q) => q.search("plain", text))
|
||||||
|
.take(limit)
|
||||||
|
const matches = rows.flatMap((row) => {
|
||||||
|
const match = matchLyrics(row.plain, text)
|
||||||
|
return match ? [{ song: row.song, ...match }] : []
|
||||||
|
})
|
||||||
|
return [
|
||||||
|
...matches.filter((match) => match.exact),
|
||||||
|
...matches.filter((match) => !match.exact),
|
||||||
|
].map(({ song, snippet }) => ({ song, snippet }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The song's lyrics tag (see `client/lyrics.ts`), or null without lyrics. */
|
||||||
|
export const forSong = query({
|
||||||
|
args: { id: v.id("songs") },
|
||||||
|
handler: async (ctx, args): Promise<string | null> => {
|
||||||
|
if ((await getAuthUserId(ctx)) === null) return null
|
||||||
|
const row = await ctx.db
|
||||||
|
.query("lyrics")
|
||||||
|
.withIndex("by_song", (q) => q.eq("song", args.id))
|
||||||
|
.first()
|
||||||
|
return row?.text ?? null
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Songs whose lyrics match a search, so in-list filters can include them. */
|
||||||
|
export const matchingSongIds = query({
|
||||||
|
args: { query: v.string() },
|
||||||
|
handler: async (ctx, args): Promise<Id<"songs">[]> => {
|
||||||
|
if ((await getAuthUserId(ctx)) === null) return []
|
||||||
|
const matches = await searchSongLyrics(ctx, args.query, MAX_LYRICS_MATCHES)
|
||||||
|
return matches.map((match) => match.song)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Stores lyrics the library scan read from files; null marks none found. */
|
||||||
|
export const setSongLyrics = internalMutation({
|
||||||
|
args: {
|
||||||
|
songs: v.array(
|
||||||
|
v.object({ id: v.id("songs"), lyrics: v.nullable(v.string()) })
|
||||||
|
),
|
||||||
|
},
|
||||||
|
handler: async (ctx, args) => {
|
||||||
|
for (const song of args.songs) {
|
||||||
|
// The song may have been deleted since the scan read it.
|
||||||
|
if (await ctx.db.get("songs", song.id)) {
|
||||||
|
await writeSongLyrics(ctx, song.id, song.lyrics)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -140,11 +140,28 @@ export default defineSchema({
|
|||||||
year: v.number(),
|
year: v.number(),
|
||||||
date: v.string(),
|
date: v.string(),
|
||||||
genres: v.array(v.string()),
|
genres: v.array(v.string()),
|
||||||
|
/**
|
||||||
|
* Whether the files have a lyrics tag, stored in `lyrics`. Unset until the
|
||||||
|
* library scan has read the files for lyrics.
|
||||||
|
*/
|
||||||
|
hasLyrics: v.optional(v.boolean()),
|
||||||
})
|
})
|
||||||
.index("by_name", ["name"])
|
.index("by_name", ["name"])
|
||||||
.index("by_artist", ["albumArtist"])
|
.index("by_artist", ["albumArtist"])
|
||||||
.index("by_album", ["album"])
|
.index("by_album", ["album"])
|
||||||
.index("by_all", ["name", "albumArtist", "album"]),
|
.index("by_all", ["name", "albumArtist", "album"]),
|
||||||
|
/** A song's lyrics tag as written in its file: plain, LRC, or word-timed LRC. */
|
||||||
|
lyrics: defineTable({
|
||||||
|
song: v.id("songs"),
|
||||||
|
text: v.string(),
|
||||||
|
}).index("by_song", ["song"]),
|
||||||
|
/** The same lyrics without timestamps. Kept apart so search reads only this. */
|
||||||
|
lyricsSearch: defineTable({
|
||||||
|
song: v.id("songs"),
|
||||||
|
plain: v.string(),
|
||||||
|
})
|
||||||
|
.index("by_song", ["song"])
|
||||||
|
.searchIndex("search_plain", { searchField: "plain" }),
|
||||||
playlists: defineTable({
|
playlists: defineTable({
|
||||||
name: v.string(),
|
name: v.string(),
|
||||||
owner: v.id("users"),
|
owner: v.id("users"),
|
||||||
|
|||||||
@@ -95,11 +95,15 @@ export type SearchTopResultItem =
|
|||||||
| { kind: "album"; item: BrowseAlbum }
|
| { kind: "album"; item: BrowseAlbum }
|
||||||
| { kind: "artist"; item: BrowseArtist }
|
| { kind: "artist"; item: BrowseArtist }
|
||||||
|
|
||||||
|
/** A song search result. Songs found only by their lyrics carry the matched line. */
|
||||||
|
export type SearchSong = BrowseSong & { lyricsSnippet?: string }
|
||||||
|
|
||||||
export type LibrarySearchResults = {
|
export type LibrarySearchResults = {
|
||||||
topResults: SearchTopResultItem[]
|
topResults: SearchTopResultItem[]
|
||||||
artists: BrowseArtist[]
|
artists: BrowseArtist[]
|
||||||
albums: BrowseAlbum[]
|
albums: BrowseAlbum[]
|
||||||
songs: BrowseSong[]
|
/** Title, artist and album matches, then lyrics matches. */
|
||||||
|
songs: SearchSong[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type QueueSong = BrowseSong & { queueIndex: number }
|
export type QueueSong = BrowseSong & { queueIndex: number }
|
||||||
|
|||||||
@@ -51,6 +51,14 @@
|
|||||||
"types": "./client/favorites.ts",
|
"types": "./client/favorites.ts",
|
||||||
"default": "./client/favorites.ts"
|
"default": "./client/favorites.ts"
|
||||||
},
|
},
|
||||||
|
"./client/lyrics": {
|
||||||
|
"types": "./client/lyrics.ts",
|
||||||
|
"default": "./client/lyrics.ts"
|
||||||
|
},
|
||||||
|
"./client/lyrics-tags": {
|
||||||
|
"types": "./client/lyrics-tags.ts",
|
||||||
|
"default": "./client/lyrics-tags.ts"
|
||||||
|
},
|
||||||
"./client/media-links": {
|
"./client/media-links": {
|
||||||
"types": "./client/media-links.ts",
|
"types": "./client/media-links.ts",
|
||||||
"default": "./client/media-links.ts"
|
"default": "./client/media-links.ts"
|
||||||
|
|||||||
Reference in new issue
Block a user