Compare commits
No files matched your search
@@ -4,7 +4,6 @@ import { Stack } from "expo-router"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
@@ -23,10 +22,18 @@ export default function HomeLayout() {
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@ 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"
|
||||
@@ -57,9 +56,7 @@ export default function HomeScreen() {
|
||||
(result) => result.status === "LoadingFirstPage" && !result.isCached
|
||||
)
|
||||
if (isLoading) {
|
||||
return (
|
||||
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
|
||||
)
|
||||
return <HomeSkeleton title="Home" />
|
||||
}
|
||||
|
||||
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
|
||||
@@ -76,12 +73,7 @@ export default function HomeScreen() {
|
||||
]}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
>
|
||||
<ScreenTitle
|
||||
title="Home"
|
||||
scrollY={scrollY}
|
||||
accessory={<ProfileHeaderButton />}
|
||||
style={styles.title}
|
||||
/>
|
||||
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} />
|
||||
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
|
||||
</Animated.ScrollView>
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@ import { Stack } from "expo-router"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
@@ -27,10 +26,18 @@ export default function LibraryLayout() {
|
||||
title:
|
||||
tabStackScreenTitles[route.name] ??
|
||||
(tabletLayout ? "Recently Added" : "Library"),
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ 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"
|
||||
@@ -129,7 +128,6 @@ export default function LibraryScreen() {
|
||||
return (
|
||||
<MediaGridSkeleton
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
contentInset={false}
|
||||
header={listHeader}
|
||||
/>
|
||||
@@ -139,7 +137,6 @@ export default function LibraryScreen() {
|
||||
return (
|
||||
<MediaGridList
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
content={results}
|
||||
paddingBottom={tabContentBottomInset}
|
||||
contentInset={false}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Stack } from "expo-router"
|
||||
import { ProfileHeaderButton } from "@/components/profile-header-button"
|
||||
import {
|
||||
inlineTitleOptions,
|
||||
showHeaderProfile,
|
||||
tabStackScreenTitles,
|
||||
useStackScreenOptions,
|
||||
} from "@/lib/navigation"
|
||||
@@ -23,10 +22,18 @@ export default function SearchLayout() {
|
||||
...baseOptions,
|
||||
...inlineTitleOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
// iOS shows the profile button inline with the screen title instead.
|
||||
headerRight: showHeaderProfile(route.name)
|
||||
? () => <ProfileHeaderButton />
|
||||
: undefined,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ 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, type ReactNode } from "react"
|
||||
import { memo, useCallback, type ReactElement } from "react"
|
||||
import {
|
||||
FlatList,
|
||||
Platform,
|
||||
@@ -302,7 +302,6 @@ export function MediaGridList({
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
content: MediaItem[]
|
||||
paddingBottom: number
|
||||
@@ -311,7 +310,6 @@ export function MediaGridList({
|
||||
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 } =
|
||||
@@ -336,7 +334,6 @@ export function MediaGridList({
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
contentInset={contentInset}
|
||||
title={title}
|
||||
titleAccessory={titleAccessory}
|
||||
renderCard={renderTabletCard}
|
||||
/>
|
||||
)
|
||||
@@ -347,7 +344,6 @@ export function MediaGridList({
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={scrollY}
|
||||
accessory={titleAccessory}
|
||||
// Inset grids already pad the whole list horizontally.
|
||||
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
|
||||
/>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { useHeaderHeight } from "expo-router/react-navigation"
|
||||
import type { Component, ReactNode } from "react"
|
||||
import type { Component } from "react"
|
||||
import {
|
||||
Platform,
|
||||
StyleSheet,
|
||||
Text,
|
||||
type ScrollViewInstance,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
type TextStyle,
|
||||
} from "react-native"
|
||||
import Animated, {
|
||||
useAnimatedRef,
|
||||
@@ -34,20 +33,17 @@ export function useScreenTitleScroll<
|
||||
* 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.
|
||||
* pull-down. Android keeps its native header title, 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>
|
||||
style?: StyleProp<TextStyle>
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
// At rest the scroll offset is minus the automatic header inset, so any
|
||||
@@ -64,34 +60,25 @@ export function ScreenTitle({
|
||||
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>
|
||||
<Animated.Text
|
||||
accessibilityRole="header"
|
||||
numberOfLines={2}
|
||||
style={[styles.title, { color: colors.foreground }, style, pinStyle]}
|
||||
>
|
||||
{title}
|
||||
</Animated.Text>
|
||||
)
|
||||
}
|
||||
|
||||
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
|
||||
const styles = StyleSheet.create({
|
||||
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,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingTop: 3,
|
||||
paddingBottom: 8,
|
||||
},
|
||||
})
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
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"
|
||||
@@ -87,12 +86,7 @@ function SearchResultsBody({
|
||||
)
|
||||
|
||||
if (isSearching) {
|
||||
return (
|
||||
<SongListSkeleton
|
||||
title={title}
|
||||
titleAccessory={<ProfileHeaderButton />}
|
||||
/>
|
||||
)
|
||||
return <SongListSkeleton title={title} />
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -107,11 +101,7 @@ function SearchResultsBody({
|
||||
keyboardShouldPersistTaps="handled"
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={scrollY}
|
||||
accessory={<ProfileHeaderButton />}
|
||||
/>
|
||||
<ScreenTitle title={title} scrollY={scrollY} />
|
||||
{hasQuery && !hasResults ? (
|
||||
<View style={styles.empty}>
|
||||
<Text
|
||||
|
||||
@@ -155,15 +155,13 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
|
||||
export function SongListSkeleton({
|
||||
rows = 10,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
rows?: number
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
{title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
|
||||
{title ? <ScreenTitle title={title} /> : null}
|
||||
<SongRows rows={rows} />
|
||||
</SkeletonScreen>
|
||||
)
|
||||
@@ -245,7 +243,6 @@ export function MediaGridSkeleton({
|
||||
contentInset = true,
|
||||
header,
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
items?: number
|
||||
contentInset?: boolean
|
||||
@@ -253,7 +250,6 @@ export function MediaGridSkeleton({
|
||||
header?: ReactNode
|
||||
/** The loaded list's `ScreenTitle`, which replaces its top inset. */
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
@@ -263,7 +259,7 @@ export function MediaGridSkeleton({
|
||||
header={
|
||||
title ? (
|
||||
<>
|
||||
<MediaGridTitle title={title} accessory={titleAccessory} />
|
||||
<MediaGridTitle title={title} />
|
||||
{header}
|
||||
</>
|
||||
) : (
|
||||
@@ -275,18 +271,11 @@ export function MediaGridSkeleton({
|
||||
)
|
||||
}
|
||||
|
||||
function MediaGridTitle({
|
||||
title,
|
||||
accessory,
|
||||
}: {
|
||||
title: string
|
||||
accessory?: ReactNode
|
||||
}) {
|
||||
function MediaGridTitle({ title }: { title: string }) {
|
||||
const { horizontalPadding } = useMediaGridLayout()
|
||||
return (
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
accessory={accessory}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
)
|
||||
@@ -305,21 +294,11 @@ export function CarouselSkeleton() {
|
||||
)
|
||||
}
|
||||
|
||||
export function HomeSkeleton({
|
||||
title,
|
||||
titleAccessory,
|
||||
}: {
|
||||
title: string
|
||||
titleAccessory?: ReactNode
|
||||
}) {
|
||||
export function HomeSkeleton({ title }: { title: string }) {
|
||||
return (
|
||||
<SkeletonScreen>
|
||||
<View style={styles.home}>
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
accessory={titleAccessory}
|
||||
style={styles.homeTitle}
|
||||
/>
|
||||
<ScreenTitle title={title} style={styles.homeTitle} />
|
||||
<CarouselSkeleton />
|
||||
<CarouselSkeleton />
|
||||
</View>
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
type ReactElement,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import {
|
||||
type ScrollViewInstance,
|
||||
@@ -32,7 +31,6 @@ type GridProps = {
|
||||
contentInset?: boolean
|
||||
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
|
||||
title?: string
|
||||
titleAccessory?: ReactNode
|
||||
renderCard: (item: MediaItem, width: number) => ReactElement
|
||||
}
|
||||
|
||||
@@ -47,7 +45,6 @@ export function TabletMediaGrid({
|
||||
ListHeaderComponent,
|
||||
contentInset = true,
|
||||
title,
|
||||
titleAccessory,
|
||||
renderCard,
|
||||
}: GridProps) {
|
||||
const colors = useThemeColors()
|
||||
@@ -129,7 +126,6 @@ export function TabletMediaGrid({
|
||||
<ScreenTitle
|
||||
title={title}
|
||||
scrollY={titleScrollY}
|
||||
accessory={titleAccessory}
|
||||
style={{ paddingHorizontal: horizontalPadding }}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -24,11 +24,6 @@ export const tabStackScreenTitles: Record<string, string> = {
|
||||
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 {
|
||||
|
||||
@@ -114,7 +114,6 @@ export function AlbumView({
|
||||
}) {
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
isAlbumFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleAlbumFavorite,
|
||||
@@ -155,7 +154,6 @@ export function AlbumView({
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
} = useTrackSelection(album.tracks, validHighlightedSongId)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -415,7 +413,6 @@ export function AlbumView({
|
||||
isFavorite={isSongFavorite(track.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={album.artist.id}
|
||||
selectionFavorited={selectionFavorited}
|
||||
isNowPlaying={currentSongId === track.id}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
|
||||
@@ -37,8 +37,7 @@ type FavoritesContextValue = {
|
||||
) => Promise<boolean>
|
||||
toggleAlbumFavorite: (albumId: Id<"albums">) => Promise<void>
|
||||
toggleArtistFavorite: (artistId: Id<"artists">) => Promise<void>
|
||||
/** True when `songIds` is non-empty and every song is favorited. */
|
||||
areSongsFavorite: (songIds: Iterable<string>) => boolean
|
||||
favoriteSongs: (songIds: Id<"songs">[]) => Promise<void>
|
||||
}
|
||||
|
||||
const FavoritesContext = React.createContext<FavoritesContextValue | null>(null)
|
||||
@@ -131,16 +130,26 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
[songIds, favoriteSong, unfavoriteSong]
|
||||
)
|
||||
|
||||
const areSongsFavorite = React.useCallback(
|
||||
(ids: Iterable<string>) => {
|
||||
let any = false
|
||||
for (const id of ids) {
|
||||
if (!songIds.has(id)) return false
|
||||
any = true
|
||||
const favoriteSongs = React.useCallback(
|
||||
async (ids: Id<"songs">[]) => {
|
||||
const unique = [...new Set(ids)]
|
||||
if (unique.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await favoriteSongsMutation({ songIds: unique })
|
||||
toast.success(
|
||||
unique.length > 1
|
||||
? `Favorited ${unique.length} songs`
|
||||
: "Added to favorites"
|
||||
)
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error ? error.message : "Failed to update favorites"
|
||||
)
|
||||
}
|
||||
return any
|
||||
},
|
||||
[songIds]
|
||||
[favoriteSongsMutation]
|
||||
)
|
||||
|
||||
const toggleSongsFavorite = React.useCallback(
|
||||
@@ -223,7 +232,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
}),
|
||||
[
|
||||
isSongFavorite,
|
||||
@@ -233,7 +242,7 @@ export function FavoritesProvider({ children }: { children: React.ReactNode }) {
|
||||
toggleSongsFavorite,
|
||||
toggleAlbumFavorite,
|
||||
toggleArtistFavorite,
|
||||
areSongsFavorite,
|
||||
favoriteSongs,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ export function OtherDownloadsView() {
|
||||
[songs]
|
||||
)
|
||||
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromSong, playInOrder, playShuffled } = usePlaybackActions()
|
||||
const {
|
||||
selectedIds,
|
||||
@@ -63,7 +62,6 @@ export function OtherDownloadsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
@@ -142,7 +140,6 @@ export function OtherDownloadsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -74,12 +74,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
currentUser === undefined
|
||||
? playlist.isOwner
|
||||
: currentUser?._id === playlist.owner.id
|
||||
const {
|
||||
isSongFavorite,
|
||||
areSongsFavorite,
|
||||
toggleSongFavorite,
|
||||
toggleSongsFavorite,
|
||||
} = useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite, toggleSongsFavorite } =
|
||||
useFavorites()
|
||||
const currentSongId = useCurrentSongId()
|
||||
const {
|
||||
playInOrder,
|
||||
@@ -147,7 +143,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
@@ -470,7 +465,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
onAction={handlePlaylistMediaAction}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
showFavorite={!isFavorites}
|
||||
favorited={areSongsFavorite(playlistSongIds)}
|
||||
downloaded={playlistDownloaded}
|
||||
trackRowTrigger={false}
|
||||
triggerVariant="secondary"
|
||||
@@ -528,7 +522,6 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
||||
selectionPosition={selectionPositions[index]}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
||||
downloadCollection={downloadRef}
|
||||
showFavoriteInMenu={!isFavorites}
|
||||
|
||||
@@ -244,7 +244,7 @@ export function QueuePanel() {
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(selectionItems)
|
||||
const { isSongFavorite, areSongsFavorite } = useFavorites()
|
||||
const { isSongFavorite } = useFavorites()
|
||||
const { runSongsAction } = useMediaActions()
|
||||
|
||||
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||
@@ -268,11 +268,6 @@ export function QueuePanel() {
|
||||
),
|
||||
[selectableQueue, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(
|
||||
selectableQueue.flatMap((item) =>
|
||||
item.song && selectedIds.has(item.selectionId) ? [item.song.id] : []
|
||||
)
|
||||
)
|
||||
|
||||
const handleMediaAction = React.useCallback(
|
||||
(action: MediaContextAction, selectionId: string) => {
|
||||
@@ -458,7 +453,6 @@ export function QueuePanel() {
|
||||
isFavorite={isSongFavorite(item.song.id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
removeLabel="Remove from Queue"
|
||||
selectionPosition={selectionPositions[index]}
|
||||
isDragging={draggingIndices.has(index)}
|
||||
|
||||
@@ -47,8 +47,7 @@ const SONGS_PAGE_SIZE = 50
|
||||
const estimateSongRowSize = () => 56
|
||||
|
||||
export function SongsView() {
|
||||
const { isSongFavorite, areSongsFavorite, toggleSongFavorite } =
|
||||
useFavorites()
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { playFromLibrarySong } = usePlaybackActions()
|
||||
const [sortKey, setSortKey] = useState<SortKey>("title")
|
||||
const [sortDirection, setSortDirection] = useState<SortDirection>("asc")
|
||||
@@ -99,7 +98,6 @@ export function SongsView() {
|
||||
() => stationArtistId(songs, selectedIds),
|
||||
[songs, selectedIds]
|
||||
)
|
||||
const selectionFavorited = areSongsFavorite(selectedIds)
|
||||
|
||||
const selectionPositions = useMemo(
|
||||
() =>
|
||||
@@ -224,7 +222,6 @@ export function SongsView() {
|
||||
isFavorite={isSongFavorite(songs[index].id)}
|
||||
selectedCount={selectedCount}
|
||||
selectionStationArtistId={selectedStationArtistId}
|
||||
selectionFavorited={selectionFavorited}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={handleRowSelect}
|
||||
onPlay={handleRowPlay}
|
||||
|
||||
@@ -68,8 +68,6 @@ export type TrackRowProps = {
|
||||
selectedCount?: number
|
||||
/** Station artist for the selection when this row is selected. */
|
||||
selectionStationArtistId?: string
|
||||
/** Whether every selected song is favorited, when this row is selected. */
|
||||
selectionFavorited?: boolean
|
||||
playlistLabel?: string
|
||||
showFavoriteInMenu?: boolean
|
||||
/** Adds a destructive menu item calling `onRemove`. */
|
||||
@@ -270,7 +268,6 @@ function TrackRowComponent({
|
||||
isDragging = false,
|
||||
selectedCount = 0,
|
||||
selectionStationArtistId,
|
||||
selectionFavorited,
|
||||
playlistLabel,
|
||||
showFavoriteInMenu = true,
|
||||
removeLabel,
|
||||
@@ -348,10 +345,7 @@ function TrackRowComponent({
|
||||
onAction: (action) => onMediaAction(action, rowId),
|
||||
playlistLabel,
|
||||
showFavorite: showFavoriteInMenu,
|
||||
favorited:
|
||||
inRange && selectedCount > 0
|
||||
? (selectionFavorited ?? isFavorite)
|
||||
: isFavorite,
|
||||
favorited: isFavorite,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
|
||||
@@ -26,8 +26,7 @@ function songsTitle(songIds: readonly string[]) {
|
||||
|
||||
export function useMediaActions() {
|
||||
const { openAddToPlaylist, openAddArtistToPlaylist } = useAddToPlaylist()
|
||||
const { areSongsFavorite, toggleSongsFavorite, toggleArtistFavorite } =
|
||||
useFavorites()
|
||||
const { favoriteSongs, toggleArtistFavorite } = useFavorites()
|
||||
const { runQueueAction, createStation } = useQueueMediaActions()
|
||||
const convex = useConvex()
|
||||
const cacheScope = useCacheScope()
|
||||
@@ -45,8 +44,7 @@ export function useMediaActions() {
|
||||
if (stationArtist) void createStation(stationArtist)
|
||||
break
|
||||
case "favorite":
|
||||
// Unfavorite only when every song already is, matching the menu label.
|
||||
void toggleSongsFavorite(songIds, areSongsFavorite(songIds))
|
||||
void favoriteSongs(songIds)
|
||||
break
|
||||
case "playlist":
|
||||
openAddToPlaylist(songIds)
|
||||
@@ -75,8 +73,7 @@ export function useMediaActions() {
|
||||
},
|
||||
[
|
||||
createStation,
|
||||
areSongsFavorite,
|
||||
toggleSongsFavorite,
|
||||
favoriteSongs,
|
||||
openAddToPlaylist,
|
||||
runQueueAction,
|
||||
requestDownload,
|
||||
|
||||
Reference in new issue
Block a user