Compare commits

...
20 changed files with 340 additions and 144 deletions

No files matched your search

+5 -12
View File
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function HomeLayout() {
...baseOptions, ...baseOptions,
...inlineTitleOptions, ...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Home", title: tabStackScreenTitles[route.name] ?? "Home",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
+10 -2
View File
@@ -5,6 +5,7 @@ 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 { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { ProfileHeaderButton } from "@/components/profile-header-button"
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"
@@ -56,7 +57,9 @@ export default function HomeScreen() {
(result) => result.status === "LoadingFirstPage" && !result.isCached (result) => result.status === "LoadingFirstPage" && !result.isCached
) )
if (isLoading) { if (isLoading) {
return <HomeSkeleton title="Home" /> return (
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
)
} }
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT) const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
@@ -73,7 +76,12 @@ export default function HomeScreen() {
]} ]}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
> >
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} /> <ScreenTitle
title="Home"
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
style={styles.title}
/>
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} /> <HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
</Animated.ScrollView> </Animated.ScrollView>
) )
@@ -5,6 +5,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -26,18 +27,10 @@ export default function LibraryLayout() {
title: title:
tabStackScreenTitles[route.name] ?? tabStackScreenTitles[route.name] ??
(tabletLayout ? "Recently Added" : "Library"), (tabletLayout ? "Recently Added" : "Library"),
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
@@ -8,6 +8,7 @@ import { Ionicons } from "@expo/vector-icons"
import { MediaGridList } from "@/components/media-cards" import { MediaGridList } from "@/components/media-cards"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { MediaGridSkeleton } from "@/components/skeletons" import { MediaGridSkeleton } from "@/components/skeletons"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query" import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { useAppNavigation } from "@/lib/app-navigation" import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
@@ -128,6 +129,7 @@ export default function LibraryScreen() {
return ( return (
<MediaGridSkeleton <MediaGridSkeleton
title={title} title={title}
titleAccessory={<ProfileHeaderButton />}
contentInset={false} contentInset={false}
header={listHeader} header={listHeader}
/> />
@@ -137,6 +139,7 @@ export default function LibraryScreen() {
return ( return (
<MediaGridList <MediaGridList
title={title} title={title}
titleAccessory={<ProfileHeaderButton />}
content={results} content={results}
paddingBottom={tabContentBottomInset} paddingBottom={tabContentBottomInset}
contentInset={false} contentInset={false}
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function SearchLayout() {
...baseOptions, ...baseOptions,
...inlineTitleOptions, ...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Search", title: tabStackScreenTitles[route.name] ?? "Search",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
+5 -1
View File
@@ -7,7 +7,7 @@ import { MusicEntityView } from "@/components/music-entity-view"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title" 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, type ReactNode } from "react"
import { import {
FlatList, FlatList,
Platform, Platform,
@@ -302,6 +302,7 @@ export function MediaGridList({
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title, title,
titleAccessory,
}: { }: {
content: MediaItem[] content: MediaItem[]
paddingBottom: number paddingBottom: number
@@ -310,6 +311,7 @@ export function MediaGridList({
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */ /** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
const tabletLayout = useTabletLayout() const tabletLayout = useTabletLayout()
const { columns, cardWidth, onLayout, horizontalPadding, gap } = const { columns, cardWidth, onLayout, horizontalPadding, gap } =
@@ -334,6 +336,7 @@ export function MediaGridList({
ListHeaderComponent={ListHeaderComponent} ListHeaderComponent={ListHeaderComponent}
contentInset={contentInset} contentInset={contentInset}
title={title} title={title}
titleAccessory={titleAccessory}
renderCard={renderTabletCard} renderCard={renderTabletCard}
/> />
) )
@@ -344,6 +347,7 @@ export function MediaGridList({
<ScreenTitle <ScreenTitle
title={title} title={title}
scrollY={scrollY} scrollY={scrollY}
accessory={titleAccessory}
// Inset grids already pad the whole list horizontally. // Inset grids already pad the whole list horizontally.
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }} style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
/> />
+29 -16
View File
@@ -1,11 +1,12 @@
import { useHeaderHeight } from "expo-router/react-navigation" import { useHeaderHeight } from "expo-router/react-navigation"
import type { Component } from "react" import type { Component, ReactNode } from "react"
import { import {
Platform, Platform,
StyleSheet, StyleSheet,
Text,
type ScrollViewInstance, type ScrollViewInstance,
type StyleProp, type StyleProp,
type TextStyle, type ViewStyle,
} from "react-native" } from "react-native"
import Animated, { import Animated, {
useAnimatedRef, useAnimatedRef,
@@ -33,17 +34,20 @@ export function useScreenTitleScroll<
* iOS screen title rendered as the first item of a screen's scroll content, * 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 * 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 * with the content, never collapses into the bar, and stays put on
* pull-down. Android keeps its native header title, so this renders nothing. * 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({ export function ScreenTitle({
title, title,
scrollY, scrollY,
accessory,
style, style,
}: { }: {
title: string title: string
/** From `useScreenTitleScroll`; omit for screens that never scroll. */ /** From `useScreenTitleScroll`; omit for screens that never scroll. */
scrollY?: SharedValue<number> scrollY?: SharedValue<number>
style?: StyleProp<TextStyle> accessory?: ReactNode
style?: StyleProp<ViewStyle>
}) { }) {
const colors = useThemeColors() const colors = useThemeColors()
// At rest the scroll offset is minus the automatic header inset, so any // At rest the scroll offset is minus the automatic header inset, so any
@@ -60,25 +64,34 @@ export function ScreenTitle({
if (Platform.OS !== "ios") return null if (Platform.OS !== "ios") return null
return ( return (
<Animated.Text <Animated.View style={[styles.row, style, pinStyle]}>
accessibilityRole="header" <Text
numberOfLines={2} accessibilityRole="header"
style={[styles.title, { color: colors.foreground }, style, pinStyle]} numberOfLines={2}
> style={[styles.title, { color: colors.foreground }]}
{title} >
</Animated.Text> {title}
</Text>
{accessory}
</Animated.View>
) )
} }
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area. // Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
const styles = StyleSheet.create({ const styles = StyleSheet.create({
title: { row: {
fontSize: 34, flexDirection: "row",
lineHeight: 41, alignItems: "center",
fontWeight: "700", gap: spacing.md,
letterSpacing: 0.37,
paddingHorizontal: spacing.lg, paddingHorizontal: spacing.lg,
paddingTop: 3, paddingTop: 3,
paddingBottom: 8, paddingBottom: 8,
}, },
title: {
flex: 1,
fontSize: 34,
lineHeight: 41,
fontWeight: "700",
letterSpacing: 0.37,
},
}) })
+12 -2
View File
@@ -9,6 +9,7 @@ import {
import Animated from "react-native-reanimated" import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards" import { ContentCarousel } from "@/components/media-cards"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title" 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"
@@ -86,7 +87,12 @@ function SearchResultsBody({
) )
if (isSearching) { if (isSearching) {
return <SongListSkeleton title={title} /> return (
<SongListSkeleton
title={title}
titleAccessory={<ProfileHeaderButton />}
/>
)
} }
return ( return (
@@ -101,7 +107,11 @@ function SearchResultsBody({
keyboardShouldPersistTaps="handled" keyboardShouldPersistTaps="handled"
ListHeaderComponent={ ListHeaderComponent={
<> <>
<ScreenTitle title={title} scrollY={scrollY} /> <ScreenTitle
title={title}
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
/>
{hasQuery && !hasResults ? ( {hasQuery && !hasResults ? (
<View style={styles.empty}> <View style={styles.empty}>
<Text <Text
+26 -5
View File
@@ -155,13 +155,15 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
export function SongListSkeleton({ export function SongListSkeleton({
rows = 10, rows = 10,
title, title,
titleAccessory,
}: { }: {
rows?: number rows?: number
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
{title ? <ScreenTitle title={title} /> : null} {title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
<SongRows rows={rows} /> <SongRows rows={rows} />
</SkeletonScreen> </SkeletonScreen>
) )
@@ -243,6 +245,7 @@ export function MediaGridSkeleton({
contentInset = true, contentInset = true,
header, header,
title, title,
titleAccessory,
}: { }: {
items?: number items?: number
contentInset?: boolean contentInset?: boolean
@@ -250,6 +253,7 @@ export function MediaGridSkeleton({
header?: ReactNode header?: ReactNode
/** The loaded list's `ScreenTitle`, which replaces its top inset. */ /** The loaded list's `ScreenTitle`, which replaces its top inset. */
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
@@ -259,7 +263,7 @@ export function MediaGridSkeleton({
header={ header={
title ? ( title ? (
<> <>
<MediaGridTitle title={title} /> <MediaGridTitle title={title} accessory={titleAccessory} />
{header} {header}
</> </>
) : ( ) : (
@@ -271,11 +275,18 @@ export function MediaGridSkeleton({
) )
} }
function MediaGridTitle({ title }: { title: string }) { function MediaGridTitle({
title,
accessory,
}: {
title: string
accessory?: ReactNode
}) {
const { horizontalPadding } = useMediaGridLayout() const { horizontalPadding } = useMediaGridLayout()
return ( return (
<ScreenTitle <ScreenTitle
title={title} title={title}
accessory={accessory}
style={{ paddingHorizontal: horizontalPadding }} style={{ paddingHorizontal: horizontalPadding }}
/> />
) )
@@ -294,11 +305,21 @@ export function CarouselSkeleton() {
) )
} }
export function HomeSkeleton({ title }: { title: string }) { export function HomeSkeleton({
title,
titleAccessory,
}: {
title: string
titleAccessory?: ReactNode
}) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
<View style={styles.home}> <View style={styles.home}>
<ScreenTitle title={title} style={styles.homeTitle} /> <ScreenTitle
title={title}
accessory={titleAccessory}
style={styles.homeTitle}
/>
<CarouselSkeleton /> <CarouselSkeleton />
<CarouselSkeleton /> <CarouselSkeleton />
</View> </View>
@@ -4,6 +4,7 @@ import {
useRef, useRef,
useState, useState,
type ReactElement, type ReactElement,
type ReactNode,
} from "react" } from "react"
import { import {
type ScrollViewInstance, type ScrollViewInstance,
@@ -31,6 +32,7 @@ type GridProps = {
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */ /** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string title?: string
titleAccessory?: ReactNode
renderCard: (item: MediaItem, width: number) => ReactElement renderCard: (item: MediaItem, width: number) => ReactElement
} }
@@ -45,6 +47,7 @@ export function TabletMediaGrid({
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title, title,
titleAccessory,
renderCard, renderCard,
}: GridProps) { }: GridProps) {
const colors = useThemeColors() const colors = useThemeColors()
@@ -126,6 +129,7 @@ export function TabletMediaGrid({
<ScreenTitle <ScreenTitle
title={title} title={title}
scrollY={titleScrollY} scrollY={titleScrollY}
accessory={titleAccessory}
style={{ paddingHorizontal: horizontalPadding }} style={{ paddingHorizontal: horizontalPadding }}
/> />
) : null} ) : null}
+2 -4
View File
@@ -9,15 +9,13 @@
"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": {
+5
View File
@@ -24,6 +24,11 @@ export const tabStackScreenTitles: Record<string, string> = {
export const inlineTitleOptions: StackScreenOptions = export const inlineTitleOptions: StackScreenOptions =
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {} 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( export function useStackScreenOptions(
overrides?: StackScreenOptions overrides?: StackScreenOptions
): StackScreenOptions { ): StackScreenOptions {
+3
View File
@@ -114,6 +114,7 @@ export function AlbumView({
}) { }) {
const { const {
isSongFavorite, isSongFavorite,
areSongsFavorite,
isAlbumFavorite, isAlbumFavorite,
toggleSongFavorite, toggleSongFavorite,
toggleAlbumFavorite, toggleAlbumFavorite,
@@ -154,6 +155,7 @@ export function AlbumView({
handlePointerDown, handlePointerDown,
prepareContextMenu, prepareContextMenu,
} = useTrackSelection(album.tracks, validHighlightedSongId) } = useTrackSelection(album.tracks, validHighlightedSongId)
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = React.useMemo( const selectionPositions = React.useMemo(
() => () =>
@@ -413,6 +415,7 @@ export function AlbumView({
isFavorite={isSongFavorite(track.id)} isFavorite={isSongFavorite(track.id)}
selectedCount={selectedCount} selectedCount={selectedCount}
selectionStationArtistId={album.artist.id} selectionStationArtistId={album.artist.id}
selectionFavorited={selectionFavorited}
isNowPlaying={currentSongId === track.id} isNowPlaying={currentSongId === track.id}
onPointerDown={handlePointerDown} onPointerDown={handlePointerDown}
onSelect={handleRowSelect} onSelect={handleRowSelect}
+12 -21
View File
@@ -37,7 +37,8 @@ type FavoritesContextValue = {
) => Promise<boolean> ) => Promise<boolean>
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void> toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void> toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void> /** True when `songIds` is non-empty and every song is favorited. */
areSongsFavorite: (songIds: Iterable<string>) => boolean
} }
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null) const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
@@ -130,26 +131,16 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
[songIds, favoriteSong, unfavoriteSong] [songIds, favoriteSong, unfavoriteSong]
) )
const favoriteSongs = React.useCallback( const areSongsFavorite = React.useCallback(
async (ids: Id<"songs">[]) => { (ids: Iterable<string>) => {
const unique = [...new Set(ids)] let any = false
if (unique.length === 0) { for (const id of ids) {
return if (!songIds.has(id)) return false
} any = true
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
}, },
[favoriteSongsMutation] [songIds]
) )
const toggleSongsFavorite = React.useCallback( const toggleSongsFavorite = React.useCallback(
@@ -232,7 +223,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
toggleSongsFavorite, toggleSongsFavorite,
toggleAlbumFavorite, toggleAlbumFavorite,
toggleArtistFavorite, toggleArtistFavorite,
favoriteSongs, areSongsFavorite,
}), }),
[ [
isSongFavorite, isSongFavorite,
@@ -242,7 +233,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
toggleSongsFavorite, toggleSongsFavorite,
toggleAlbumFavorite, toggleAlbumFavorite,
toggleArtistFavorite, toggleArtistFavorite,
favoriteSongs, areSongsFavorite,
] ]
) )
+4 -1
View File
@@ -48,7 +48,8 @@ export function OtherDownloadsView() {
[songs] [songs]
) )
const { isSongFavorite, toggleSongFavorite } = useFavorites() const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
useFavorites()
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions() const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
const { const {
selectedIds, selectedIds,
@@ -62,6 +63,7 @@ export function OtherDownloadsView() {
() => stationArtistId(songs, selectedIds), () => stationArtistId(songs, selectedIds),
[songs, selectedIds] [songs, selectedIds]
) )
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = useMemo( const selectionPositions = useMemo(
() => () =>
getSelectionRangePositions( getSelectionRangePositions(
@@ -140,6 +142,7 @@ export function OtherDownloadsView() {
isFavorite={isSongFavorite(songs[index].id)} isFavorite={isSongFavorite(songs[index].id)}
selectedCount={selectedCount} selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId} selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
onPointerDown={handlePointerDown} onPointerDown={handlePointerDown}
onSelect={handleRowSelect} onSelect={handleRowSelect}
onPlay={handleRowPlay} onPlay={handleRowPlay}
+9 -2
View File
@@ -74,8 +74,12 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
currentUser === undefined currentUser === undefined
? playlist.isOwner ? playlist.isOwner
: currentUser?._id === playlist.owner.id : currentUser?._id === playlist.owner.id
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } = const {
useFavorites() isSongFavorite,
areSongsFavorite,
toggleSongFavorite,
toggleSongsFavorite,
} = useFavorites()
const currentSongId = useCurrentSongId() const currentSongId = useCurrentSongId()
const { const {
playInOrder, playInOrder,
@@ -143,6 +147,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
() => stationArtistId(songs, selectedIds), () => stationArtistId(songs, selectedIds),
[songs, selectedIds] [songs, selectedIds]
) )
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = React.useMemo( const selectionPositions = React.useMemo(
() => () =>
@@ -465,6 +470,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
onAction={handlePlaylistMediaAction} onAction={handlePlaylistMediaAction}
playlistLabel={ADD_TO_ANOTHER_PLAYLIST} playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
showFavorite={!isFavorites} showFavorite={!isFavorites}
favorited={areSongsFavorite(playlistSongIds)}
downloaded={playlistDownloaded} downloaded={playlistDownloaded}
trackRowTrigger={false} trackRowTrigger={false}
triggerVariant="secondary" triggerVariant="secondary"
@@ -522,6 +528,7 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
selectionPosition={selectionPositions[index]} selectionPosition={selectionPositions[index]}
selectedCount={selectedCount} selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId} selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
playlistLabel={ADD_TO_ANOTHER_PLAYLIST} playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
downloadCollection={downloadRef} downloadCollection={downloadRef}
showFavoriteInMenu={!isFavorites} showFavoriteInMenu={!isFavorites}
+167 -40
View File
@@ -2,11 +2,18 @@
import * as React from "react" 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 { 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 { Skeleton } from "@/components/ui/skeleton" import { Skeleton } from "@/components/ui/skeleton"
import { Spinner } from "@/components/ui/spinner" 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 { 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, QueueSong } from "@otunes/convex/types" import type { BrowseSong, QueueSong } from "@otunes/convex/types"
@@ -15,6 +22,7 @@ import {
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"
@@ -46,6 +54,51 @@ 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. */ /** A played song; clicking it plays it again from that point in history. */
function HistorySongRow({ function HistorySongRow({
song, song,
@@ -61,25 +114,27 @@ function HistorySongRow({
} }
return ( return (
<li <SongMenuArea song={song}>
role="button" <li
tabIndex={0} role="button"
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5" tabIndex={0}
onClick={() => onPlay(historyIndex)} className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
onKeyDown={(event) => { onClick={() => onPlay(historyIndex)}
if (event.key === "Enter" || event.key === " ") { onKeyDown={(event) => {
event.preventDefault() if (event.key === "Enter" || event.key === " ") {
onPlay(historyIndex) event.preventDefault()
} onPlay(historyIndex)
}} }
> }}
<TrackCover >
albumId={song.album.id} <TrackCover
alt={song.album.title} albumId={song.album.id}
inRange={false} alt={song.album.title}
/> inRange={false}
<PlaybackSongMeta song={song} align="start" showAlbum={false} /> />
</li> <PlaybackSongMeta song={song} align="start" showAlbum={false} />
</li>
</SongMenuArea>
) )
} }
@@ -181,8 +236,71 @@ 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, 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 handleRowSelect = React.useCallback( const handleRowSelect = React.useCallback(
(index: number, event: React.MouseEvent) => { (index: number, event: React.MouseEvent) => {
@@ -292,25 +410,25 @@ export function QueuePanel() {
{/* Fills the viewport so the current song can always scroll to the top. */} {/* Fills the viewport so the current song can always scroll to the top. */}
<div ref={currentRef} className="flex min-h-full flex-col"> <div ref={currentRef} className="flex min-h-full flex-col">
{currentQueueSongId ? ( {currentSong ? (
<div className="flex items-center gap-3 px-4 py-3"> <SongMenuArea song={currentSong}>
{currentSong ? ( <div className="flex items-center gap-3 px-4 py-3">
<> <TrackCover
<TrackCover albumId={currentSong.album.id}
albumId={currentSong.album.id} alt={currentSong.album.title}
alt={currentSong.album.title} inRange={false}
inRange={false} size="lg"
size="lg" />
/> <PlaybackSongMeta
<PlaybackSongMeta song={currentSong}
song={currentSong} align="start"
align="start" showAlbum={false}
showAlbum={false} />
/> </div>
</> </SongMenuArea>
) : ( ) : currentQueueSongId ? (
<Skeleton className="size-14 shrink-0 rounded-md" /> <div className="px-4 py-3">
)} <Skeleton className="size-14 shrink-0 rounded-md" />
</div> </div>
) : null} ) : null}
@@ -336,6 +454,12 @@ export function QueuePanel() {
variant="queue" variant="queue"
song={item.song} song={item.song}
index={index} index={index}
selectionId={item.selectionId}
isFavorite={isSongFavorite(item.song.id)}
selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
removeLabel="Remove from Queue"
selectionPosition={selectionPositions[index]} selectionPosition={selectionPositions[index]}
isDragging={draggingIndices.has(index)} isDragging={draggingIndices.has(index)}
onPointerDown={handlePointerDown} onPointerDown={handlePointerDown}
@@ -343,6 +467,9 @@ export function QueuePanel() {
onPlay={handleRowPlay} onPlay={handleRowPlay}
onDragStart={setDragIndex} onDragStart={setDragIndex}
onDrop={handleDrop} onDrop={handleDrop}
onPrepareContextMenu={prepareContextMenu}
onMediaAction={handleMediaAction}
onRemove={handleRemove}
/> />
) : ( ) : (
<QueueSongRowSkeleton key={item.selectionId} /> <QueueSongRowSkeleton key={item.selectionId} />
+4 -1
View File
@@ -47,7 +47,8 @@ const SONGS_PAGE_SIZE = 50
const estimateSongRowSize = () => 56 const estimateSongRowSize = () => 56
export function SongsView() { export function SongsView() {
const { isSongFavorite, toggleSongFavorite } = useFavorites() const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
useFavorites()
const { playFromLibrarySong } = usePlaybackActions() const { playFromLibrarySong } = usePlaybackActions()
const [sortKey, setSortKey] = useState<SortKey>("title") const [sortKey, setSortKey] = useState<SortKey>("title")
const [sortDirection, setSortDirection] = useState<SortDirection>("asc") const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
@@ -98,6 +99,7 @@ export function SongsView() {
() => stationArtistId(songs, selectedIds), () => stationArtistId(songs, selectedIds),
[songs, selectedIds] [songs, selectedIds]
) )
const selectionFavorited = areSongsFavorite(selectedIds)
const selectionPositions = useMemo( const selectionPositions = useMemo(
() => () =>
@@ -222,6 +224,7 @@ export function SongsView() {
isFavorite={isSongFavorite(songs[index].id)} isFavorite={isSongFavorite(songs[index].id)}
selectedCount={selectedCount} selectedCount={selectedCount}
selectionStationArtistId={selectedStationArtistId} selectionStationArtistId={selectedStationArtistId}
selectionFavorited={selectionFavorited}
onPointerDown={handlePointerDown} onPointerDown={handlePointerDown}
onSelect={handleRowSelect} onSelect={handleRowSelect}
onPlay={handleRowPlay} onPlay={handleRowPlay}
+24 -10
View File
@@ -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`: cover, title and artist, duration, and a reorder grip. 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. */
@@ -62,6 +68,8 @@ export type TrackRowProps = {
selectedCount?: number selectedCount?: number
/** Station artist for the selection when this row is selected. */ /** Station artist for the selection when this row is selected. */
selectionStationArtistId?: string selectionStationArtistId?: string
/** Whether every selected song is favorited, when this row is selected. */
selectionFavorited?: boolean
playlistLabel?: string playlistLabel?: string
showFavoriteInMenu?: boolean showFavoriteInMenu?: boolean
/** Adds a destructive menu item calling `onRemove`. */ /** Adds a destructive menu item calling `onRemove`. */
@@ -71,10 +79,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
@@ -251,6 +259,7 @@ function TrackRowComponent({
variant, variant,
song, song,
index, index,
selectionId,
trackNumber, trackNumber,
subtitle, subtitle,
downloadCollection, downloadCollection,
@@ -261,6 +270,7 @@ function TrackRowComponent({
isDragging = false, isDragging = false,
selectedCount = 0, selectedCount = 0,
selectionStationArtistId, selectionStationArtistId,
selectionFavorited,
playlistLabel, playlistLabel,
showFavoriteInMenu = true, showFavoriteInMenu = true,
removeLabel, removeLabel,
@@ -284,6 +294,7 @@ function TrackRowComponent({
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">
@@ -333,11 +344,14 @@ 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:
inRange && selectedCount > 0
? (selectionFavorited ?? isFavorite)
: isFavorite,
navigation: { navigation: {
artist: { id: song.artist.id }, artist: { id: song.artist.id },
album: { id: song.album.id }, album: { id: song.album.id },
@@ -351,7 +365,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 />
@@ -555,7 +569,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)
+6 -3
View File
@@ -26,7 +26,8 @@ function songsTitle(songIds: readonly string[]) {
export function useMediaActions() { export function useMediaActions() {
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist() const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
const { favoriteSongs, toggleArtistFavorite } = useFavorites() const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
useFavorites()
const { runQueueAction, createStation } = useQueueMediaActions() const { runQueueAction, createStation } = useQueueMediaActions()
const convex = useConvex() const convex = useConvex()
const cacheScope = useCacheScope() const cacheScope = useCacheScope()
@@ -44,7 +45,8 @@ export function useMediaActions() {
if (stationArtist) void createStation(stationArtist) if (stationArtist) void createStation(stationArtist)
break break
case "favorite": case "favorite":
void favoriteSongs(songIds) // Unfavorite only when every song already is, matching the menu label.
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
break break
case "playlist": case "playlist":
openAddToPlaylist(songIds) openAddToPlaylist(songIds)
@@ -73,7 +75,8 @@ export function useMediaActions() {
}, },
[ [
createStation, createStation,
favoriteSongs, areSongsFavorite,
toggleSongsFavorite,
openAddToPlaylist, openAddToPlaylist,
runQueueAction, runQueueAction,
requestDownload, requestDownload,