Compare commits
3
Commits
No files matched your search
+6
-1
@@ -1,7 +1,11 @@
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
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"
|
||||
|
||||
export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||
@@ -14,6 +18,7 @@ export default function TabletSectionLayout({ segment }: { segment: string }) {
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...options,
|
||||
...inlineTitleOptions,
|
||||
title:
|
||||
route.name === "index"
|
||||
? section?.title
|
||||
|
||||
@@ -2,7 +2,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -16,19 +21,12 @@ export default function HomeLayout() {
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ export default function AlbumsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<MediaGridSkeleton />
|
||||
<MediaGridSkeleton title="Albums" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -63,6 +63,7 @@ export default function AlbumsScreen() {
|
||||
{searchBar}
|
||||
|
||||
<MediaGridList
|
||||
title="Albums"
|
||||
content={albums}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
import { memo, useCallback } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import {
|
||||
MediaContextMenu,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
} from "@/components/media-context-menu"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { ArtistListSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { contentBottomInset } from "@/components/player"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import {
|
||||
@@ -33,6 +35,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function ArtistsScreen() {
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseArtist>>()
|
||||
const { push } = useAppNavigation()
|
||||
const colors = useThemeColors()
|
||||
const { config } = useServerConfig()
|
||||
@@ -94,7 +97,7 @@ export default function ArtistsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<ArtistListSkeleton />
|
||||
<ArtistListSkeleton title="Artists" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -103,8 +106,11 @@ export default function ArtistsScreen() {
|
||||
<>
|
||||
{searchBar}
|
||||
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
ListHeaderComponent={<ScreenTitle title="Artists" scrollY={scrollY} />}
|
||||
data={artists}
|
||||
keyExtractor={artistKey}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useContext } from "react"
|
||||
import { Pressable } from "react-native"
|
||||
|
||||
import { MediaGridList } from "@/components/media-cards"
|
||||
@@ -10,19 +11,20 @@ import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
import { SymbolView } from "expo-symbols"
|
||||
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
||||
import { TabletSectionContext } from "@/lib/tablet-navigation"
|
||||
|
||||
export default function PlaylistsTabScreen() {
|
||||
const colors = useThemeColors()
|
||||
const playlists = useCachedQuery(api.playlists.listAllPlaylists)
|
||||
const { openCreatePlaylist } = useAddToPlaylist()
|
||||
const title = useContext(TabletSectionContext)?.title ?? "Playlists"
|
||||
|
||||
if (playlists === undefined) {
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Playlists",
|
||||
headerLargeTitle: true,
|
||||
title,
|
||||
headerRight: () => (
|
||||
<Pressable
|
||||
onPress={openCreatePlaylist}
|
||||
@@ -38,7 +40,7 @@ export default function PlaylistsTabScreen() {
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<MediaGridSkeleton />
|
||||
<MediaGridSkeleton title={title} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -47,8 +49,7 @@ export default function PlaylistsTabScreen() {
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: "Playlists",
|
||||
headerLargeTitle: true,
|
||||
title,
|
||||
headerRight: () => (
|
||||
<Pressable
|
||||
onPress={openCreatePlaylist}
|
||||
@@ -61,6 +62,7 @@ export default function PlaylistsTabScreen() {
|
||||
}}
|
||||
/>
|
||||
<MediaGridList
|
||||
title={title}
|
||||
content={playlists}
|
||||
paddingBottom={tabContentBottomInset}
|
||||
/>
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Stack } from "expo-router"
|
||||
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 { contentBottomInset, SongListRow } from "@/components/player"
|
||||
import { SongListSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useFavorites } from "@/contexts/favorites"
|
||||
import { usePlaybackActions } from "@/contexts/playback"
|
||||
import {
|
||||
@@ -20,6 +26,7 @@ import { longListProps } from "@/lib/list"
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function SongsScreen() {
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
const { playFromLibrarySong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
@@ -87,7 +94,7 @@ export default function SongsScreen() {
|
||||
return (
|
||||
<>
|
||||
{searchBar}
|
||||
<SongListSkeleton />
|
||||
<SongListSkeleton title="Songs" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -96,8 +103,11 @@ export default function SongsScreen() {
|
||||
<>
|
||||
{searchBar}
|
||||
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
ListHeaderComponent={<ScreenTitle title="Songs" scrollY={scrollY} />}
|
||||
data={songs}
|
||||
keyExtractor={songKey}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import { Stack } from "expo-router"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import {
|
||||
FAVORITES_DOWNLOAD_ID,
|
||||
@@ -53,6 +55,7 @@ export default function DownloadsScreen() {
|
||||
const { push } = useAppNavigation()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||
useMediaGridLayout()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<Card>>()
|
||||
|
||||
const cards = useMemo<Card[]>(() => {
|
||||
if (!queue) return []
|
||||
@@ -135,8 +138,10 @@ export default function DownloadsScreen() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ title: "Downloads", headerLargeTitle: true }} />
|
||||
<FlatList
|
||||
<Stack.Screen options={{ title: "Downloads" }} />
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
key={columns}
|
||||
onLayout={onLayout}
|
||||
data={cards}
|
||||
@@ -149,13 +154,20 @@ export default function DownloadsScreen() {
|
||||
numColumns={columns}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{
|
||||
paddingTop: spacing.lg,
|
||||
paddingHorizontal: horizontalPadding,
|
||||
paddingBottom: tabContentBottomInset,
|
||||
gap,
|
||||
}}
|
||||
columnWrapperStyle={columns > 1 ? { gap } : undefined}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
ListHeaderComponent={
|
||||
<ScreenTitle
|
||||
title="Downloads"
|
||||
scrollY={scrollY}
|
||||
// The list padding already insets the title.
|
||||
style={{ paddingHorizontal: 0 }}
|
||||
/>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<View style={styles.empty}>
|
||||
<Text style={{ color: colors.mutedForeground }}>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { useCallback, useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useSwipeRowGroup } from "@/components/ios-swipe-to-remove-row"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
@@ -52,6 +54,7 @@ export default function OtherDownloadsScreen() {
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
const swipeGroup = useSwipeRowGroup()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) => void playFromSong(song.id, playableIds, PLAY_ORIGIN),
|
||||
@@ -90,11 +93,11 @@ export default function OtherDownloadsScreen() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{ title: OTHER_DOWNLOADS_TITLE, headerLargeTitle: false }}
|
||||
/>
|
||||
<FlatList
|
||||
<Stack.Screen options={{ title: OTHER_DOWNLOADS_TITLE }} />
|
||||
<Animated.FlatList
|
||||
{...longListProps}
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
data={songs}
|
||||
keyExtractor={(song) => song.id}
|
||||
renderItem={renderItem}
|
||||
@@ -103,25 +106,32 @@ export default function OtherDownloadsScreen() {
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||
ListHeaderComponent={
|
||||
songs.length > 0 ? (
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||
style={styles.play}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
||||
>
|
||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
) : undefined
|
||||
<>
|
||||
<ScreenTitle title={OTHER_DOWNLOADS_TITLE} scrollY={scrollY} />
|
||||
{songs.length > 0 ? (
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playInOrder(playableIds, PLAY_ORIGIN)}
|
||||
style={styles.play}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playShuffled(playableIds, PLAY_ORIGIN)}
|
||||
style={[styles.shuffle, { backgroundColor: colors.card }]}
|
||||
>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={24}
|
||||
color={colors.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<Text style={[styles.empty, { color: colors.mutedForeground }]}>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
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 { HomeSkeleton } from "@/components/skeletons"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -38,6 +41,7 @@ const HomeCarousels = memo(function HomeCarousels({
|
||||
|
||||
export default function HomeScreen() {
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY } = useScreenTitleScroll<ScrollViewInstance>()
|
||||
const recentlyAdded = useCachedPaginatedQuery(
|
||||
api.library.browseRecentlyAddedPaginated,
|
||||
{},
|
||||
@@ -53,14 +57,18 @@ export default function HomeScreen() {
|
||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||
)
|
||||
if (isLoading) {
|
||||
return <HomeSkeleton />
|
||||
return (
|
||||
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
|
||||
)
|
||||
}
|
||||
|
||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||
const played = recentlyPlayed.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
<Animated.ScrollView
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={[
|
||||
styles.content,
|
||||
@@ -68,8 +76,14 @@ export default function HomeScreen() {
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<ScreenTitle
|
||||
title="Home"
|
||||
scrollY={scrollY}
|
||||
accessory={<ProfileHeaderButton />}
|
||||
style={styles.title}
|
||||
/>
|
||||
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||
</ScrollView>
|
||||
</Animated.ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,4 +92,10 @@ const styles = StyleSheet.create({
|
||||
padding: spacing.lg,
|
||||
gap: spacing.xl,
|
||||
},
|
||||
// The content padding already insets the title.
|
||||
title: {
|
||||
paddingHorizontal: 0,
|
||||
marginTop: -spacing.lg,
|
||||
marginBottom: -spacing.md,
|
||||
},
|
||||
})
|
||||
@@ -14,11 +14,12 @@ export default function RecentlyAddedScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton />
|
||||
return <MediaGridSkeleton title="Recently Added" />
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title="Recently Added"
|
||||
content={results}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -14,11 +14,12 @@ export default function RecentlyPlayedScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton />
|
||||
return <MediaGridSkeleton title="Recently Played" />
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title="Recently Played"
|
||||
content={results}
|
||||
paddingBottom={contentBottomInset}
|
||||
onEndReached={() => {
|
||||
|
||||
@@ -3,7 +3,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -18,21 +23,14 @@ export default function LibraryLayout() {
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title:
|
||||
tabStackScreenTitles[route.name] ??
|
||||
(tabletLayout ? "Recently Added" : "Library"),
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Ionicons } from "@expo/vector-icons"
|
||||
import { MediaGridList } from "@/components/media-cards"
|
||||
import { tabContentBottomInset } from "@/components/player"
|
||||
import { MediaGridSkeleton } from "@/components/skeletons"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
|
||||
import { useAppNavigation } from "@/lib/app-navigation"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
@@ -72,6 +73,7 @@ export default function LibraryScreen() {
|
||||
const { push } = useAppNavigation()
|
||||
const isTablet = tabletLayout
|
||||
const colors = useThemeColors()
|
||||
const title = isTablet ? "Recently Added" : "Library"
|
||||
const { results, status, loadMore, isCached } = useCachedPaginatedQuery(
|
||||
api.library.browseRecentlyAddedPaginated,
|
||||
{},
|
||||
@@ -124,11 +126,20 @@ export default function LibraryScreen() {
|
||||
)
|
||||
|
||||
if (status === "LoadingFirstPage" && !isCached) {
|
||||
return <MediaGridSkeleton contentInset={false} header={listHeader} />
|
||||
return (
|
||||
<MediaGridSkeleton
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
contentInset={false}
|
||||
header={listHeader}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaGridList
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
content={results}
|
||||
paddingBottom={tabContentBottomInset}
|
||||
contentInset={false}
|
||||
|
||||
@@ -2,7 +2,12 @@ import { renderTabScreenContent } from "@/components/tab-screen-content"
|
||||
import { Stack } from "expo-router"
|
||||
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -16,19 +21,12 @@ export default function SearchLayout() {
|
||||
screenLayout={renderTabScreenContent}
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ export default function SearchScreen() {
|
||||
: {})}
|
||||
/>
|
||||
|
||||
<SearchResults searchQuery={searchQuery} />
|
||||
<SearchResults searchQuery={searchQuery} title="Search" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -7,14 +7,6 @@ import {
|
||||
View,
|
||||
type ScrollViewInstance,
|
||||
} from "react-native"
|
||||
import Animated, {
|
||||
cancelAnimation,
|
||||
Easing,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withTiming,
|
||||
type SharedValue,
|
||||
} from "react-native-reanimated"
|
||||
|
||||
import {
|
||||
usePlaybackActions,
|
||||
@@ -26,7 +18,6 @@ import type { NowPlayingColors } from "@/lib/now-playing-colors"
|
||||
import {
|
||||
activeLineIndex,
|
||||
type LyricLine,
|
||||
type LyricWord,
|
||||
type Lyrics,
|
||||
} from "@otunes/convex/client/lyrics"
|
||||
|
||||
@@ -34,8 +25,6 @@ import {
|
||||
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
|
||||
@@ -81,22 +70,19 @@ function LyricsLines({
|
||||
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 manualScrollAt = useRef(0)
|
||||
|
||||
const scrollToLine = useCallback(
|
||||
(index: number) => {
|
||||
const y = lineOffsets.current[Math.max(index, 0)]
|
||||
if (y === undefined || !synced || height === 0 || browsing) return
|
||||
if (y === undefined || !synced || height === 0) return
|
||||
if (Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS) return
|
||||
scrollRef.current?.scrollTo({
|
||||
y: Math.max(0, y - height * ACTIVE_LINE_POSITION),
|
||||
animated: true,
|
||||
})
|
||||
},
|
||||
[height, synced, browsing]
|
||||
[height, synced]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -120,20 +106,11 @@ function LyricsLines({
|
||||
(seconds: number) => {
|
||||
seekTo(seconds)
|
||||
setIsPlaying(true)
|
||||
clearTimeout(browseTimer.current)
|
||||
setBrowsing(false)
|
||||
manualScrollAt.current = 0
|
||||
},
|
||||
[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]
|
||||
@@ -150,12 +127,12 @@ function LyricsLines({
|
||||
showsVerticalScrollIndicator={false}
|
||||
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
|
||||
onScrollBeginDrag={() => {
|
||||
clearTimeout(browseTimer.current)
|
||||
setBrowsing(true)
|
||||
manualScrollAt.current = Date.now()
|
||||
}}
|
||||
onMomentumScrollEnd={() => {
|
||||
// Hold from when the scroll settles, not when the finger lifted.
|
||||
if (manualScrollAt.current > 0) manualScrollAt.current = Date.now()
|
||||
}}
|
||||
// Hold from when the scroll settles, not when the finger lifted.
|
||||
onScrollEndDrag={releaseScroll}
|
||||
onMomentumScrollEnd={releaseScroll}
|
||||
>
|
||||
{lyrics.lines.map((line, index) =>
|
||||
synced ? (
|
||||
@@ -163,14 +140,10 @@ function LyricsLines({
|
||||
key={index}
|
||||
index={index}
|
||||
line={line}
|
||||
distance={
|
||||
browsing
|
||||
? 0
|
||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||
state={
|
||||
index === active ? "active" : index < active ? "past" : "next"
|
||||
}
|
||||
active={index === active}
|
||||
time={index === active ? time : null}
|
||||
isPlaying={isPlaying}
|
||||
colors={colors}
|
||||
textStyle={lineStyle}
|
||||
onSelect={playFrom}
|
||||
@@ -198,17 +171,14 @@ function LyricsLines({
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* One timed 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,
|
||||
state,
|
||||
time,
|
||||
isPlaying,
|
||||
colors,
|
||||
textStyle,
|
||||
onSelect,
|
||||
@@ -216,155 +186,58 @@ const SyncedLine = memo(function SyncedLine({
|
||||
}: {
|
||||
index: number
|
||||
line: LyricLine
|
||||
distance: number
|
||||
active: boolean
|
||||
state: "past" | "active" | "next"
|
||||
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]
|
||||
const active = state === "active"
|
||||
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 }] }]}
|
||||
style={styles.line}
|
||||
>
|
||||
{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>
|
||||
)}
|
||||
<Text
|
||||
style={[
|
||||
styles.lineText,
|
||||
textStyle,
|
||||
{
|
||||
color:
|
||||
active && !line.words ? colors.foreground : colors.lyricsInactive,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{active && line.words
|
||||
? line.words.map((word, wordIndex) => (
|
||||
<Text
|
||||
key={wordIndex}
|
||||
style={{
|
||||
color:
|
||||
time !== null && time >= word.start
|
||||
? colors.foreground
|
||||
: colors.lyricsUnsung,
|
||||
}}
|
||||
>
|
||||
{word.text}
|
||||
</Text>
|
||||
))
|
||||
: 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,9 +4,10 @@ import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||
import { TabletMediaGrid } from "@/components/tablet-media-grid"
|
||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||
import { MusicEntityView } from "@/components/music-entity-view"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { Link } from "expo-router"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
import { memo, useCallback, type ReactElement } from "react"
|
||||
import { memo, useCallback, type ReactElement, type ReactNode } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
Platform,
|
||||
@@ -300,17 +301,23 @@ export function MediaGridList({
|
||||
onEndReached,
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
content: MediaItem[]
|
||||
paddingBottom: number
|
||||
onEndReached?: () => void
|
||||
ListHeaderComponent?: ReactElement
|
||||
contentInset?: boolean
|
||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
const tabletLayout = useTabletLayout()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap } =
|
||||
useMediaGridLayout()
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY } = useScreenTitleScroll<FlatList<MediaItem>>()
|
||||
const renderItem = useCallback(
|
||||
({ item }: ListRenderItemInfo<MediaItem>) => (
|
||||
<View style={{ width: cardWidth }}>
|
||||
@@ -328,13 +335,32 @@ export function MediaGridList({
|
||||
onEndReached={onEndReached}
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
contentInset={contentInset}
|
||||
title={title}
|
||||
titleAccessory={titleAccessory}
|
||||
renderCard={renderTabletCard}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const header = title ? (
|
||||
<View>
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={scrollY}
|
||||
accessory={titleAccessory}
|
||||
// Inset grids already pad the whole list horizontally.
|
||||
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||
/>
|
||||
{ListHeaderComponent}
|
||||
</View>
|
||||
) : (
|
||||
ListHeaderComponent
|
||||
)
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
key={columns}
|
||||
onLayout={onLayout}
|
||||
data={content}
|
||||
@@ -351,6 +377,7 @@ export function MediaGridList({
|
||||
paddingBottom,
|
||||
gap,
|
||||
...(contentInset ? { paddingHorizontal: horizontalPadding } : {}),
|
||||
...(title ? { paddingTop: 0 } : {}),
|
||||
},
|
||||
]}
|
||||
columnWrapperStyle={[
|
||||
@@ -359,7 +386,7 @@ export function MediaGridList({
|
||||
{ gap },
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
ListHeaderComponent={header}
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||
import type { Component, ReactNode } from "react"
|
||||
import {
|
||||
Platform,
|
||||
StyleSheet,
|
||||
Text,
|
||||
type ScrollViewInstance,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} 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. `accessory` (e.g. the profile button) sits on the same row and
|
||||
* scrolls with it. Android keeps its native header, so this renders nothing.
|
||||
*/
|
||||
export function ScreenTitle({
|
||||
title,
|
||||
scrollY,
|
||||
accessory,
|
||||
style,
|
||||
}: {
|
||||
title: string
|
||||
/** From `useScreenTitleScroll`; omit for screens that never scroll. */
|
||||
scrollY?: SharedValue<number>
|
||||
accessory?: ReactNode
|
||||
style?: StyleProp<ViewStyle>
|
||||
}) {
|
||||
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.View style={[styles.row, style, pinStyle]}>
|
||||
<Text
|
||||
accessibilityRole="header"
|
||||
numberOfLines={2}
|
||||
style={[styles.title, { color: colors.foreground }]}
|
||||
>
|
||||
{title}
|
||||
</Text>
|
||||
{accessory}
|
||||
</Animated.View>
|
||||
)
|
||||
}
|
||||
|
||||
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingTop: 3,
|
||||
paddingBottom: 8,
|
||||
},
|
||||
title: {
|
||||
flex: 1,
|
||||
fontSize: 34,
|
||||
lineHeight: 41,
|
||||
fontWeight: "700",
|
||||
letterSpacing: 0.37,
|
||||
},
|
||||
})
|
||||
@@ -1,13 +1,16 @@
|
||||
import { memo, useCallback, useMemo } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
type FlatList,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
import Animated from "react-native-reanimated"
|
||||
|
||||
import { ContentCarousel } from "@/components/media-cards"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import type { MediaAction } from "@/components/media-context-menu"
|
||||
import { tabContentBottomInset, SongListRow } from "@/components/player"
|
||||
import { SongListSkeleton } from "@/components/skeletons"
|
||||
@@ -19,8 +22,16 @@ import { api } from "@otunes/convex/_generated/api"
|
||||
import type { BrowseSong, SearchSong } from "@otunes/convex/types"
|
||||
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 { ref, scrollY } = useScreenTitleScroll<FlatList<BrowseSong>>()
|
||||
const { playFromSong } = usePlaybackActions()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { handleSongAction } = useMediaMenuActions()
|
||||
@@ -76,16 +87,19 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
)
|
||||
|
||||
if (isSearching) {
|
||||
return <SongListSkeleton />
|
||||
}
|
||||
|
||||
if (!hasQuery) {
|
||||
return <></>
|
||||
return (
|
||||
<SongListSkeleton
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
data={results?.songs ?? []}
|
||||
<Animated.FlatList
|
||||
ref={ref}
|
||||
scrollEventThrottle={16}
|
||||
data={hasQuery ? (results?.songs ?? []) : []}
|
||||
keyExtractor={(song) => song.id}
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: tabContentBottomInset }}
|
||||
@@ -93,7 +107,12 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
keyboardShouldPersistTaps="handled"
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
{!hasResults ? (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={scrollY}
|
||||
accessory={<ProfileHeaderButton />}
|
||||
/>
|
||||
{hasQuery && !hasResults ? (
|
||||
<View style={styles.empty}>
|
||||
<Text
|
||||
style={[styles.emptyText, { color: colors.mutedForeground }]}
|
||||
@@ -103,13 +122,13 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.artists.length ? (
|
||||
{hasQuery && results?.artists.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Artists" content={results.artists} />
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{results?.albums.length ? (
|
||||
{hasQuery && results?.albums.length ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Albums" content={results.albums} />
|
||||
</View>
|
||||
@@ -118,7 +137,7 @@ function SearchResultsBody({ searchQuery }: { searchQuery: string }) {
|
||||
}
|
||||
renderItem={renderItem}
|
||||
ListFooterComponent={
|
||||
playlistResults && playlistResults.length > 0 ? (
|
||||
hasQuery && playlistResults && playlistResults.length > 0 ? (
|
||||
<View style={styles.section}>
|
||||
<ContentCarousel title="Playlists" content={playlistResults} />
|
||||
</View>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
collectionInset,
|
||||
} from "@/components/collection-list"
|
||||
import { tabletCardTextHeight } from "@/components/tablet-media-grid"
|
||||
import { ScreenTitle } from "@/components/screen-title"
|
||||
import { Link } from "expo-router"
|
||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||
import Reanimated from "react-native-reanimated"
|
||||
@@ -151,9 +152,18 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
||||
))
|
||||
}
|
||||
|
||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
||||
export function SongListSkeleton({
|
||||
rows = 10,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
rows?: number
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
{title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
|
||||
<SongRows rows={rows} />
|
||||
</SkeletonScreen>
|
||||
)
|
||||
@@ -234,23 +244,54 @@ export function MediaGridSkeleton({
|
||||
items = 6,
|
||||
contentInset = true,
|
||||
header,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
items?: number
|
||||
contentInset?: boolean
|
||||
/** The loaded list's `ListHeaderComponent`, so it keeps its position. */
|
||||
header?: ReactNode
|
||||
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
<MediaGridContent
|
||||
items={items}
|
||||
contentInset={contentInset}
|
||||
header={header}
|
||||
contentInset={contentInset && !title}
|
||||
header={
|
||||
title ? (
|
||||
<>
|
||||
<MediaGridTitle title={title} accessory={titleAccessory} />
|
||||
{header}
|
||||
</>
|
||||
) : (
|
||||
header
|
||||
)
|
||||
}
|
||||
/>
|
||||
</SkeletonScreen>
|
||||
)
|
||||
}
|
||||
|
||||
function MediaGridTitle({
|
||||
title,
|
||||
accessory,
|
||||
}: {
|
||||
title: string
|
||||
accessory?: ReactNode
|
||||
}) {
|
||||
const { horizontalPadding } = useMediaGridLayout()
|
||||
return (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
accessory={accessory}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function CarouselSkeleton() {
|
||||
return (
|
||||
<View style={styles.carousel}>
|
||||
@@ -264,10 +305,21 @@ export function CarouselSkeleton() {
|
||||
)
|
||||
}
|
||||
|
||||
export function HomeSkeleton() {
|
||||
export function HomeSkeleton({
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
title: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
<View style={styles.home}>
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
accessory={titleAccessory}
|
||||
style={styles.homeTitle}
|
||||
/>
|
||||
<CarouselSkeleton />
|
||||
<CarouselSkeleton />
|
||||
</View>
|
||||
@@ -388,10 +440,17 @@ export function CollectionDetailSkeleton({
|
||||
)
|
||||
}
|
||||
|
||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
||||
export function ArtistListSkeleton({
|
||||
rows = 12,
|
||||
title,
|
||||
}: {
|
||||
rows?: number
|
||||
title?: string
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
{title ? <ScreenTitle title={title} /> : null}
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
@@ -456,6 +515,12 @@ const styles = StyleSheet.create({
|
||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||
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 },
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -4,9 +4,10 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
type ReactElement,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import {
|
||||
ScrollView,
|
||||
type ScrollViewInstance,
|
||||
View,
|
||||
type NativeSyntheticEvent,
|
||||
type NativeScrollEvent,
|
||||
@@ -15,6 +16,7 @@ import Animated from "react-native-reanimated"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
|
||||
import type { MediaItem } from "@/components/media-cards"
|
||||
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
|
||||
import { useMediaGridLayout } from "@/hooks/use-media-grid-layout"
|
||||
import { tabletLayoutTransition } from "@/lib/tablet-motion"
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
@@ -28,6 +30,9 @@ type GridProps = {
|
||||
onEndReached?: () => void
|
||||
ListHeaderComponent?: ReactElement
|
||||
contentInset?: boolean
|
||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||
}
|
||||
|
||||
@@ -41,9 +46,13 @@ export function TabletMediaGrid({
|
||||
onEndReached,
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
titleAccessory,
|
||||
renderCard,
|
||||
}: GridProps) {
|
||||
const colors = useThemeColors()
|
||||
const { ref, scrollY: titleScrollY } =
|
||||
useScreenTitleScroll<ScrollViewInstance>()
|
||||
const insets = useSafeAreaInsets()
|
||||
const { columns, cardWidth, onLayout, horizontalPadding, gap, ready } =
|
||||
useMediaGridLayout()
|
||||
@@ -102,18 +111,28 @@ export function TabletMediaGrid({
|
||||
setViewportHeight(event.nativeEvent.layout.height)
|
||||
}}
|
||||
>
|
||||
<ScrollView
|
||||
<Animated.ScrollView
|
||||
ref={ref}
|
||||
onScroll={onScroll}
|
||||
scrollEventThrottle={32}
|
||||
// Every frame, so the title pins smoothly on pull-down.
|
||||
scrollEventThrottle={16}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
contentContainerStyle={{
|
||||
paddingTop: contentInset ? horizontalPadding : 0,
|
||||
paddingTop: contentInset && !title ? horizontalPadding : 0,
|
||||
paddingBottom: paddingBottom + insets.bottom,
|
||||
}}
|
||||
>
|
||||
<View
|
||||
onLayout={(event) => setHeaderHeight(event.nativeEvent.layout.height)}
|
||||
>
|
||||
{title ? (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={titleScrollY}
|
||||
accessory={titleAccessory}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
) : null}
|
||||
{ListHeaderComponent}
|
||||
</View>
|
||||
<View style={{ height: gridHeight }}>
|
||||
@@ -136,7 +155,7 @@ export function TabletMediaGrid({
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</Animated.ScrollView>
|
||||
</Animated.View>
|
||||
)
|
||||
}
|
||||
@@ -9,13 +9,15 @@
|
||||
"APP_VARIANT": "development"
|
||||
},
|
||||
"developmentClient": true,
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"preview": {
|
||||
"env": {
|
||||
"APP_VARIANT": "preview"
|
||||
},
|
||||
"distribution": "internal"
|
||||
"distribution": "internal",
|
||||
"credentialsSource": "local"
|
||||
},
|
||||
"production": {
|
||||
"env": {
|
||||
|
||||
@@ -17,13 +17,25 @@ export const tabStackScreenTitles: Record<string, string> = {
|
||||
"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" } } : {}
|
||||
|
||||
/** Tab roots show the profile button in the header, except on iOS where `ScreenTitle` holds it. */
|
||||
export function showHeaderProfile(routeName: string) {
|
||||
return routeName === "index" && Platform.OS !== "ios"
|
||||
}
|
||||
|
||||
export function useStackScreenOptions(
|
||||
overrides?: StackScreenOptions
|
||||
): StackScreenOptions {
|
||||
const theme = useThemeColors()
|
||||
|
||||
return {
|
||||
headerLargeTitle: true,
|
||||
headerLargeTitle: false,
|
||||
headerTransparent: true,
|
||||
headerTintColor: theme.foreground,
|
||||
headerLargeTitleStyle: { color: theme.foreground },
|
||||
|
||||
@@ -114,7 +114,6 @@ export function AlbumView({
|
||||
}) {
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
isAlbumFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleAlbumFavorite,
|
||||
@@ -155,7 +154,6 @@ export function AlbumView({
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -415,7 +413,6 @@ export function AlbumView({
|
||||
isFavorite={isSongFavorite(track.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={album.artist.id}
|
||||
selectionFavorited={selectionFavorited}
|
||||
isNowPlaying={currentSongId === track.id}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
|
||||
@@ -37,8 +37,7 @@ type FavoritesContextValue = {
|
||||
) => Promise<boolean>
|
||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||
/** True when `songIds` is non-empty and every song is favorited. */
|
||||
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
||||
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
||||
}
|
||||
|
||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||
@@ -131,16 +130,26 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
[songIds, favoriteSong, unfavoriteSong]
|
||||
)
|
||||
|
||||
const areSongsFavorite = React.useCallback(
|
||||
(ids: Iterable<string>) => {
|
||||
let any = false
|
||||
for (const id of ids) {
|
||||
if (!songIds.has(id)) return false
|
||||
any = true
|
||||
const favoriteSongs = React.useCallback(
|
||||
async (ids: Id<"songs">[]) => {
|
||||
const unique = [...new Set(ids)]
|
||||
if (unique.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await favoriteSongsMutation({ songIds: unique })
|
||||
toast.success(
|
||||
unique.length > 1
|
||||
? `Favorited ${unique.length} songs`
|
||||
: "Added to favorites"
|
||||
)
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : "Failed to update favorites"
|
||||
)
|
||||
}
|
||||
return any
|
||||
},
|
||||
[songIds]
|
||||
[favoriteSongsMutation]
|
||||
)
|
||||
|
||||
const toggleSongsFavorite = React.useCallback(
|
||||
@@ -223,7 +232,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
}),
|
||||
[
|
||||
isSongFavorite,
|
||||
@@ -233,7 +242,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -12,26 +12,11 @@ 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() {
|
||||
@@ -62,42 +47,38 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
||||
const time = useLyricsTime(lyrics, currentTime, isPlaying)
|
||||
const active = activeLineIndex(lyrics, time)
|
||||
const scrollRef = React.useRef<HTMLDivElement>(null)
|
||||
const manualScrollAt = React.useRef(0)
|
||||
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
|
||||
if (
|
||||
!container ||
|
||||
!line ||
|
||||
!synced ||
|
||||
Date.now() - manualScrollAt.current < MANUAL_SCROLL_HOLD_MS
|
||||
) {
|
||||
return
|
||||
}
|
||||
container.scrollTo({
|
||||
top: line.offsetTop - container.clientHeight * 0.25,
|
||||
behavior: "smooth",
|
||||
})
|
||||
}, [active, synced, browsing])
|
||||
}, [active, synced])
|
||||
|
||||
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
|
||||
)
|
||||
manualScrollAt.current = Date.now()
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -105,7 +86,7 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
||||
ref={scrollRef}
|
||||
onWheel={holdScroll}
|
||||
onTouchMove={holdScroll}
|
||||
className="group relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
||||
className="relative min-h-0 flex-1 overflow-y-auto px-6 pt-[25svh] pb-[60svh]"
|
||||
>
|
||||
{lyrics.lines.map((line, index) =>
|
||||
synced ? (
|
||||
@@ -113,14 +94,10 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
||||
key={index}
|
||||
index={index}
|
||||
line={line}
|
||||
distance={
|
||||
browsing
|
||||
? 0
|
||||
: Math.min(Math.abs(index - active), LINE_BLUR.length - 1)
|
||||
state={
|
||||
index === active ? "active" : index < active ? "past" : "next"
|
||||
}
|
||||
active={index === active}
|
||||
time={index === active ? time : null}
|
||||
isPlaying={isPlaying}
|
||||
onSelect={playFrom}
|
||||
/>
|
||||
) : (
|
||||
@@ -140,103 +117,48 @@ function LyricsLines({ lyrics }: { lyrics: Lyrics }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* One timed 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,
|
||||
state,
|
||||
time,
|
||||
isPlaying,
|
||||
onSelect,
|
||||
}: {
|
||||
index: number
|
||||
line: LyricLine
|
||||
distance: number
|
||||
active: boolean
|
||||
state: "past" | "active" | "next"
|
||||
time: number | null
|
||||
isPlaying: boolean
|
||||
onSelect: (seconds: number) => void
|
||||
}) {
|
||||
const active = state === "active"
|
||||
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],
|
||||
"-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-colors duration-300 hover:bg-foreground/5",
|
||||
active && !line.words ? "text-foreground" : "text-foreground/30"
|
||||
)}
|
||||
>
|
||||
{active && line.words && time !== null ? (
|
||||
<FilledWords words={line.words} time={time} isPlaying={isPlaying} />
|
||||
) : (
|
||||
line.text
|
||||
)}
|
||||
{active && line.words
|
||||
? line.words.map((word, wordIndex) => (
|
||||
<span
|
||||
key={wordIndex}
|
||||
className={cn(
|
||||
"transition-colors duration-200",
|
||||
time !== null && time >= word.start
|
||||
? "text-foreground"
|
||||
: "text-foreground/45"
|
||||
)}
|
||||
>
|
||||
{word.text}
|
||||
</span>
|
||||
))
|
||||
: 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>
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -48,8 +48,7 @@ export function OtherDownloadsView() {
|
||||
[songs]
|
||||
)
|
||||
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||
const {
|
||||
selectedIds,
|
||||
@@ -63,7 +62,6 @@ export function OtherDownloadsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
@@ -142,7 +140,6 @@ export function OtherDownloadsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -74,12 +74,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
currentUser === undefined
|
||||
? playlist.isOwner
|
||||
: currentUser?._id === playlist.owner.id
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleSongsFavorite,
|
||||
} = useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
|
||||
useFavorites()
|
||||
const currentSongId = useCurrentSongId()
|
||||
const {
|
||||
playInOrder,
|
||||
@@ -147,7 +143,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -470,7 +465,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
onAction={handlePlaylistMediaAction}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
showFavorite={!isFavorites}
|
||||
favorited={areSongsFavorite(playlistSongIds)}
|
||||
downloaded={playlistDownloaded}
|
||||
trackRowTrigger={false}
|
||||
triggerVariant="secondary"
|
||||
@@ -528,7 +522,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
selectionPosition={selectionPositions[index]}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
downloadCollection={downloadRef}
|
||||
showFavoriteInMenu={!isFavorites}
|
||||
|
||||
@@ -2,18 +2,11 @@
|
||||
|
||||
import * as React from "react"
|
||||
|
||||
import { useFavorites } from "@/components/favorites-provider"
|
||||
import {
|
||||
MediaContextMenuArea,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
import { useSongDownloadState } from "@/hooks/use-downloads"
|
||||
import { useMediaActions } from "@/hooks/use-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
||||
@@ -22,7 +15,6 @@ import {
|
||||
moveQueueBlock,
|
||||
} from "@/lib/move-queue-block"
|
||||
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
||||
import { stationArtistId } from "@/lib/station-artist"
|
||||
import { useSongs } from "@/lib/song-cache"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
@@ -54,51 +46,6 @@ function toSelectableQueue(
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the song's right-click menu over `children`, for the queue rows that
|
||||
* stand alone (history and the current song) rather than in the selection.
|
||||
*/
|
||||
function SongMenuArea({
|
||||
song,
|
||||
children,
|
||||
}: {
|
||||
song: BrowseSong
|
||||
children: React.ReactElement
|
||||
}) {
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { runSongsAction } = useMediaActions()
|
||||
const downloaded = useSongDownloadState(song.id) === "here"
|
||||
|
||||
function handleAction(action: MediaContextAction) {
|
||||
if (action === "favorite") {
|
||||
void toggleSongFavorite(song.id)
|
||||
return
|
||||
}
|
||||
runSongsAction(action, [song.id], song.artist.id)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaContextMenuArea
|
||||
menu={{
|
||||
label: `More options for ${song.title}`,
|
||||
stationArtistId: song.artist.id,
|
||||
selectedCount: 1,
|
||||
onOpenMenu: () => {},
|
||||
onAction: handleAction,
|
||||
favorited: isSongFavorite(song.id),
|
||||
downloaded,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
},
|
||||
share: { type: "song", albumId: song.album.id, songId: song.id },
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</MediaContextMenuArea>
|
||||
)
|
||||
}
|
||||
|
||||
/** A played song; clicking it plays it again from that point in history. */
|
||||
function HistorySongRow({
|
||||
song,
|
||||
@@ -114,27 +61,25 @@ function HistorySongRow({
|
||||
}
|
||||
|
||||
return (
|
||||
<SongMenuArea song={song}>
|
||||
<li
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
|
||||
onClick={() => onPlay(historyIndex)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault()
|
||||
onPlay(historyIndex)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TrackCover
|
||||
albumId={song.album.id}
|
||||
alt={song.album.title}
|
||||
inRange={false}
|
||||
/>
|
||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||
</li>
|
||||
</SongMenuArea>
|
||||
<li
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
||||
onClick={() => onPlay(historyIndex)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault()
|
||||
onPlay(historyIndex)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TrackCover
|
||||
albumId={song.album.id}
|
||||
alt={song.album.title}
|
||||
inRange={false}
|
||||
/>
|
||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -236,71 +181,8 @@ export function QueuePanel() {
|
||||
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
||||
[selectableQueue]
|
||||
)
|
||||
const {
|
||||
selectedIds,
|
||||
selectedCount,
|
||||
handleSelect,
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(selectionItems)
|
||||
const { isSongFavorite, areSongsFavorite } = 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 selectionFavorited = areSongsFavorite(
|
||||
selectableQueue.flatMap((item) =>
|
||||
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
|
||||
)
|
||||
)
|
||||
|
||||
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 { selectedIds, handleSelect, handlePointerDown } =
|
||||
useTrackSelection(selectionItems)
|
||||
|
||||
const handleRowSelect = React.useCallback(
|
||||
(index: number, event: React.MouseEvent) => {
|
||||
@@ -410,25 +292,25 @@ export function QueuePanel() {
|
||||
|
||||
{/* Fills the viewport so the current song can always scroll to the top. */}
|
||||
<div ref={currentRef} className="flex min-h-full flex-col">
|
||||
{currentSong ? (
|
||||
<SongMenuArea song={currentSong}>
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<TrackCover
|
||||
albumId={currentSong.album.id}
|
||||
alt={currentSong.album.title}
|
||||
inRange={false}
|
||||
size="lg"
|
||||
/>
|
||||
<PlaybackSongMeta
|
||||
song={currentSong}
|
||||
align="start"
|
||||
showAlbum={false}
|
||||
/>
|
||||
</div>
|
||||
</SongMenuArea>
|
||||
) : currentQueueSongId ? (
|
||||
<div className="px-4 py-3">
|
||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||
{currentQueueSongId ? (
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
{currentSong ? (
|
||||
<>
|
||||
<TrackCover
|
||||
albumId={currentSong.album.id}
|
||||
alt={currentSong.album.title}
|
||||
inRange={false}
|
||||
size="lg"
|
||||
/>
|
||||
<PlaybackSongMeta
|
||||
song={currentSong}
|
||||
align="start"
|
||||
showAlbum={false}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -454,12 +336,6 @@ export function QueuePanel() {
|
||||
variant="queue"
|
||||
song={item.song}
|
||||
index={index}
|
||||
selectionId={item.selectionId}
|
||||
isFavorite={isSongFavorite(item.song.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
removeLabel="Remove from Queue"
|
||||
selectionPosition={selectionPositions[index]}
|
||||
isDragging={draggingIndices.has(index)}
|
||||
onPointerDown={handlePointerDown}
|
||||
@@ -467,9 +343,6 @@ export function QueuePanel() {
|
||||
onPlay={handleRowPlay}
|
||||
onDragStart={setDragIndex}
|
||||
onDrop={handleDrop}
|
||||
onPrepareContextMenu={prepareContextMenu}
|
||||
onMediaAction={handleMediaAction}
|
||||
onRemove={handleRemove}
|
||||
/>
|
||||
) : (
|
||||
<QueueSongRowSkeleton key={item.selectionId} />
|
||||
|
||||
@@ -47,8 +47,7 @@ const SONGS_PAGE_SIZE = 50
|
||||
const estimateSongRowSize = () => 56
|
||||
|
||||
export function SongsView() {
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromLibrarySong } = usePlaybackActions()
|
||||
const [sortKey, setSortKey] = useState<SortKey>("title")
|
||||
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
|
||||
@@ -99,7 +98,6 @@ export function SongsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
@@ -224,7 +222,6 @@ export function SongsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
||||
* columns (use with `LibraryTrackListHeader`).
|
||||
* - `album`: favorite star, track number, title with optional credits.
|
||||
* - `playlist`: cover with favorite overlay, track number, title.
|
||||
* - `queue`: cover, title and artist, duration, and a reorder grip.
|
||||
* - `queue`: cover, title and artist, duration, and a reorder grip. No menu.
|
||||
*/
|
||||
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
||||
|
||||
@@ -47,12 +47,6 @@ export type TrackRowProps = {
|
||||
song: BrowseSong
|
||||
/** Position in the list the selection hook was given. */
|
||||
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`). */
|
||||
trackNumber?: number
|
||||
/** Secondary line under the title, e.g. album track credits. */
|
||||
@@ -68,8 +62,6 @@ export type TrackRowProps = {
|
||||
selectedCount?: number
|
||||
/** Station artist for the selection when this row is selected. */
|
||||
selectionStationArtistId?: string
|
||||
/** Whether every selected song is favorited, when this row is selected. */
|
||||
selectionFavorited?: boolean
|
||||
playlistLabel?: string
|
||||
showFavoriteInMenu?: boolean
|
||||
/** Adds a destructive menu item calling `onRemove`. */
|
||||
@@ -79,10 +71,10 @@ export type TrackRowProps = {
|
||||
onPointerDown: (event: React.MouseEvent) => void
|
||||
onPlay: (index: number) => void
|
||||
onToggleFavorite?: (songId: string) => void
|
||||
onPrepareContextMenu?: (selectionId: string) => void
|
||||
onPrepareContextMenu?: (songId: string) => void
|
||||
/** Renders the "more options" and right-click menus when provided. */
|
||||
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
|
||||
onRemove?: (selectionId: string) => void
|
||||
onMediaAction?: (action: MediaContextAction, songId: string) => void
|
||||
onRemove?: (songId: string) => void
|
||||
/** Makes the row draggable when provided. */
|
||||
onDragStart?: (index: number) => void
|
||||
onDrop?: (index: number) => void
|
||||
@@ -259,7 +251,6 @@ function TrackRowComponent({
|
||||
variant,
|
||||
song,
|
||||
index,
|
||||
selectionId,
|
||||
trackNumber,
|
||||
subtitle,
|
||||
downloadCollection,
|
||||
@@ -270,7 +261,6 @@ function TrackRowComponent({
|
||||
isDragging = false,
|
||||
selectedCount = 0,
|
||||
selectionStationArtistId,
|
||||
selectionFavorited,
|
||||
playlistLabel,
|
||||
showFavoriteInMenu = true,
|
||||
removeLabel,
|
||||
@@ -294,7 +284,6 @@ function TrackRowComponent({
|
||||
const flush = variant === "library" || variant === "queue"
|
||||
const play = () => onPlay(index)
|
||||
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
||||
const rowId = selectionId ?? song.id
|
||||
|
||||
const favoriteStar = (
|
||||
<div className="flex shrink-0 items-center justify-center">
|
||||
@@ -344,14 +333,11 @@ function TrackRowComponent({
|
||||
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
||||
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
||||
inSelectionRange: inRange,
|
||||
onOpenMenu: () => onPrepareContextMenu?.(rowId),
|
||||
onAction: (action) => onMediaAction(action, rowId),
|
||||
onOpenMenu: () => onPrepareContextMenu?.(song.id),
|
||||
onAction: (action) => onMediaAction(action, song.id),
|
||||
playlistLabel,
|
||||
showFavorite: showFavoriteInMenu,
|
||||
favorited:
|
||||
inRange && selectedCount > 0
|
||||
? (selectionFavorited ?? isFavorite)
|
||||
: isFavorite,
|
||||
favorited: isFavorite,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
@@ -365,7 +351,7 @@ function TrackRowComponent({
|
||||
<MediaMenuItem
|
||||
variant="destructive"
|
||||
className="justify-between"
|
||||
onClick={() => onRemove(rowId)}
|
||||
onClick={() => onRemove(song.id)}
|
||||
>
|
||||
{removeLabel}
|
||||
<Trash2 />
|
||||
@@ -569,7 +555,7 @@ function TrackRowComponent({
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass stable callbacks: they receive the row's `index`, song id or
|
||||
* `selectionId`, so one handler can serve every row.
|
||||
* Pass stable callbacks: they receive the row's `index` or song id, so one
|
||||
* handler can serve every row.
|
||||
*/
|
||||
export const TrackRow = React.memo(TrackRowComponent)
|
||||
@@ -26,8 +26,7 @@ function songsTitle(songIds: readonly string[]) {
|
||||
|
||||
export function useMediaActions() {
|
||||
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
||||
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
|
||||
useFavorites()
|
||||
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
|
||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||
const convex = useConvex()
|
||||
const cacheScope = useCacheScope()
|
||||
@@ -45,8 +44,7 @@ export function useMediaActions() {
|
||||
if (stationArtist) void createStation(stationArtist)
|
||||
break
|
||||
case "favorite":
|
||||
// Unfavorite only when every song already is, matching the menu label.
|
||||
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
|
||||
void favoriteSongs(songIds)
|
||||
break
|
||||
case "playlist":
|
||||
openAddToPlaylist(songIds)
|
||||
@@ -75,8 +73,7 @@ export function useMediaActions() {
|
||||
},
|
||||
[
|
||||
createStation,
|
||||
areSongsFavorite,
|
||||
toggleSongsFavorite,
|
||||
favoriteSongs,
|
||||
openAddToPlaylist,
|
||||
runQueueAction,
|
||||
requestDownload,
|
||||
|
||||
Reference in new issue
Block a user