Compare commits

...
11 changed files with 193 additions and 73 deletions

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import type { ConfigContext, ExpoConfig } from "expo/config"
export default ({ config }: ConfigContext): ExpoConfig => {
const variant =
const variant: string =
process.env.APP_VARIANT ?? process.env.EAS_BUILD_PROFILE ?? "production"
if (
variant !== "development" &&
@@ -111,7 +111,9 @@ export default function AlbumScreen() {
songIds={songIds}
palette={palette}
favorited={isSongFavorite(item.track.id)}
onPlay={playFromSong}
onPlay={(songId, ids) =>
playFromSong(songId, ids, `album:${album.id}`)
}
onAction={handleAlbumTrackAction}
/>
) : null
@@ -161,8 +161,9 @@ function PlaylistContent({
const swipeGroup = useSwipeRowGroup()
const handlePlaySong = useCallback(
(song: BrowseSong) => void playFromSong(song.id, songIds),
[playFromSong, songIds]
(song: BrowseSong) =>
void playFromSong(song.id, songIds, `playlist:${playlistId}`),
[playFromSong, songIds, playlistId]
)
const handleSongMenuAction = useCallback(
+71 -33
View File
@@ -1,4 +1,4 @@
import { useEffect, useRef } from "react"
import { useEffect, useRef, type ReactNode } from "react"
import {
Animated,
ScrollView,
@@ -18,6 +18,30 @@ import {
useTwoColumnCardWidth,
} from "@/lib/theme"
/** Match the inset-adjusted lists used once screen data is available. */
function SkeletonContent({
children,
embedded = false,
}: {
children: ReactNode
embedded?: boolean
}) {
const colors = useThemeColors()
if (embedded) return <>{children}</>
return (
<ScrollView
style={{ flex: 1, backgroundColor: colors.background }}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
scrollEnabled={false}
accessibilityLabel="Loading"
>
{children}
</ScrollView>
)
}
export function Skeleton({ style }: { style?: StyleProp<ViewStyle> }) {
const colors = useThemeColors()
const opacity = useRef(new Animated.Value(1)).current
@@ -74,13 +98,21 @@ export function SongRowSkeleton() {
)
}
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
export function SongListSkeleton({
rows = 10,
embedded = false,
}: {
rows?: number
embedded?: boolean
}) {
return (
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
{Array.from({ length: rows }, (_, index) => (
<SongRowSkeleton key={index} />
))}
</View>
<SkeletonContent embedded={embedded}>
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
{Array.from({ length: rows }, (_, index) => (
<SongRowSkeleton key={index} />
))}
</View>
</SkeletonContent>
)
}
@@ -109,24 +141,28 @@ function CardSkeleton({
export function MediaGridSkeleton({
items = 6,
contentInset = true,
embedded = false,
}: {
items?: number
contentInset?: boolean
embedded?: boolean
}) {
const cardWidth = useTwoColumnCardWidth()
return (
<View
accessibilityLabel="Loading"
accessibilityRole="progressbar"
style={[
styles.grid,
contentInset ? styles.gridInset : styles.gridRowInset,
]}
>
{Array.from({ length: items }, (_, index) => (
<CardSkeleton key={index} width={cardWidth} />
))}
</View>
<SkeletonContent embedded={embedded}>
<View
accessibilityLabel="Loading"
accessibilityRole="progressbar"
style={[
styles.grid,
contentInset ? styles.gridInset : styles.gridRowInset,
]}
>
{Array.from({ length: items }, (_, index) => (
<CardSkeleton key={index} width={cardWidth} />
))}
</View>
</SkeletonContent>
)
}
@@ -192,9 +228,9 @@ export function CollectionDetailSkeleton({
</View>
</View>
{round ? (
<MediaGridSkeleton items={4} contentInset={false} />
<MediaGridSkeleton items={4} contentInset={false} embedded />
) : (
<SongListSkeleton rows={8} />
<SongListSkeleton rows={8} embedded />
)}
</ScrollView>
)
@@ -203,17 +239,19 @@ export function CollectionDetailSkeleton({
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
const colors = useThemeColors()
return (
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
{Array.from({ length: rows }, (_, index) => (
<View
key={index}
style={[styles.artistRow, { borderBottomColor: colors.border }]}
>
<Skeleton style={styles.artistAvatar} />
<TextLine width="50%" height={16} />
</View>
))}
</View>
<SkeletonContent>
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
{Array.from({ length: rows }, (_, index) => (
<View
key={index}
style={[styles.artistRow, { borderBottomColor: colors.border }]}
>
<Skeleton style={styles.artistAvatar} />
<TextLine width="50%" height={16} />
</View>
))}
</View>
</SkeletonContent>
)
}
@@ -233,7 +271,7 @@ const styles = StyleSheet.create({
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.md },
gridInset: { padding: spacing.lg },
gridRowInset: { paddingHorizontal: spacing.lg },
carousel: { gap: spacing.md },
carousel: { gap: spacing.md, overflow: "hidden" },
carouselRow: { flexDirection: "row", gap: spacing.md },
home: { padding: spacing.lg, gap: spacing.xl },
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
+52 -13
View File
@@ -87,7 +87,11 @@ type PlaybackContextValue = {
playShuffled: (songIds: Id<"songs">[]) => Promise<void>
addToQueueNext: (songIds: Id<"songs">[]) => Promise<void>
addToQueueLast: (songIds: Id<"songs">[]) => Promise<void>
playFromSong: (songId: Id<"songs">, songIds: Id<"songs">[]) => Promise<void>
playFromSong: (
songId: Id<"songs">,
songIds: Id<"songs">[],
origin?: string
) => Promise<void>
playFromLibrarySong: (
songId: Id<"songs">,
sort: {
@@ -264,11 +268,13 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
const pendingSeekRef = useRef<number | null>(null)
const seekInFlightRef = useRef(false)
const loadRequestIdRef = useRef(0)
const queueOriginRef = useRef<string | undefined>(undefined)
const playRequestRef = useRef(0)
const ignoreTrackChangeTimerRef = useRef<ReturnType<
typeof setTimeout
> | null>(null)
const [queueStartVersion, setQueueStartVersion] = useState(0)
const [isPlaying, setIsPlayingState] = useState(false)
const [currentTime, setCurrentTime] = useState(0)
const [measuredDuration, setDuration] = useState(0)
@@ -348,6 +354,21 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
loadedLoadKeyRef.current = null
}, [])
// A new queue must not inherit the native player's position or a pending seek.
const resetQueuePlayback = useCallback(() => {
loadRequestIdRef.current += 1
destroyPlaylist()
pendingSeekRef.current = null
seekInFlightRef.current = false
progressRestoredForSongRef.current = null
lastSavedProgressRef.current = -1
currentTimeRef.current = 0
setCurrentTime(0)
setDuration(0)
setProgressToRestore(null)
setQueueStartVersion((version) => version + 1)
}, [destroyPlaylist])
const handlePlaylistStatusUpdate = useCallback(
(status: AudioPlaylistStatus) => {
if (!status.isLoaded) return
@@ -565,11 +586,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
if (progressRestoredForSongRef.current === currentSongId) return
progressRestoredForSongRef.current = currentSongId
lastSavedProgressRef.current = -1
pendingSeekRef.current = null
currentTimeRef.current = 0
setCurrentTime(0)
setDuration(0)
setProgressToRestore(store.getState().progressSeconds)
}, [currentSongId, destroyPlaylist, store])
}, [currentSongId, destroyPlaylist, queueStartVersion, store])
useEffect(() => {
if (progressToRestore === null || progressToRestore <= 0) return
@@ -807,6 +829,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
handlePlaybackLoadFailure,
historySyncKey,
queueSyncKey,
queueStartVersion,
repeatEnabled,
scheduleTrackChangeHandling,
userPlaybackKey,
@@ -827,18 +850,19 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
) => playbackQueue.PlaybackQueueState,
recorded: {
playlistId?: Id<"playlists">
origin?: string
entity?: { kind: MusicEntityKind; id: string }
} = {}
) => {
playRequestRef.current += 1
const previousSongId = store.getState().queue[0]
queueOriginRef.current =
recorded.origin ??
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
resetQueuePlayback()
store.update(recipe)
const firstSongId = store.getState().queue[0]
if (!firstSongId) return
if (firstSongId === previousSongId) {
void seekTo(0)
}
setIsPlaying(true)
void (async () => {
const deadline = Date.now() + 20_000
@@ -869,7 +893,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
: { songId: firstSongId }
)
},
[store, seekTo, setIsPlaying, recordPlay]
[store, resetQueuePlayback, setIsPlaying, recordPlay]
)
const playCollection = useCallback(
@@ -878,6 +902,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
shuffled: boolean,
recorded: {
playlistId?: Id<"playlists">
origin?: string
entity?: { kind: MusicEntityKind; id: string }
} = {}
) => {
@@ -942,12 +967,19 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
)
const playFromSong = useCallback(
async (songId: Id<"songs">, songIds: Id<"songs">[]) => {
startPlayback((state) =>
playbackQueue.startQueueFromSong(state, songId, songIds)
async (songId: Id<"songs">, songIds: Id<"songs">[], origin?: string) => {
if (
origin &&
queueOriginRef.current === origin &&
store.getState().queue[0] === songId
)
return
startPlayback(
(state) => playbackQueue.startQueueFromSong(state, songId, songIds),
{ origin }
)
},
[startPlayback]
[startPlayback, store]
)
const playFromLibrarySong = useCallback(
@@ -1017,6 +1049,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
playCollection(loadAlbumSongIds(albumId, songIds), false, {
entity: { kind: "album", id: albumId },
origin: `album:${albumId}`,
}),
[playCollection, loadAlbumSongIds]
)
@@ -1025,6 +1058,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
playCollection(loadAlbumSongIds(albumId, songIds), true, {
entity: { kind: "album", id: albumId },
origin: `album:${albumId}`,
}),
[playCollection, loadAlbumSongIds]
)
@@ -1087,12 +1121,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
async (songIds: Id<"songs">[], shuffled: boolean) => {
if (songIds.length === 0) return
playRequestRef.current += 1
queueOriginRef.current = undefined
resetQueuePlayback()
store.update((state) =>
playbackQueue.startQueue(state, songIds, shuffled)
)
setIsPlaying(false)
},
[store, setIsPlaying]
[store, resetQueuePlayback, setIsPlaying]
)
const startFromSong = useCallback(
@@ -1103,17 +1139,20 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
play: boolean
) => {
playRequestRef.current += 1
queueOriginRef.current = undefined
resetQueuePlayback()
store.update((state) => playbackQueue.setShuffleEnabled(state, shuffled))
store.update((state) =>
playbackQueue.startQueueFromSong(state, songId, songIds)
)
setIsPlaying(play)
},
[store, setIsPlaying]
[store, resetQueuePlayback, setIsPlaying]
)
const clearQueue = useCallback(async () => {
playRequestRef.current += 1
queueOriginRef.current = undefined
store.update(playbackQueue.clearQueue)
setIsPlaying(false)
}, [store, setIsPlaying])
+2 -1
View File
@@ -547,7 +547,8 @@ export function AlbumView({
onPlay={() =>
void playFromSong(
track.id as Id<"songs">,
albumSongIds
albumSongIds,
`album:${album.id}`
)
}
/>
+28 -9
View File
@@ -63,7 +63,11 @@ type PlaybackContextValue = {
playShuffled: (songIds: Id<"songs">[]) => Promise<void>
addToQueueNext: (songIds: Id<"songs">[]) => Promise<void>
addToQueueLast: (songIds: Id<"songs">[]) => Promise<void>
playFromSong: (songId: Id<"songs">, songIds: Id<"songs">[]) => Promise<void>
playFromSong: (
songId: Id<"songs">,
songIds: Id<"songs">[],
origin?: string
) => Promise<void>
playFromLibrarySong: (
songId: Id<"songs">,
sort: {
@@ -1050,6 +1054,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
}
}, [currentSongId, currentSong])
const queueOriginRef = useRef<string | undefined>(undefined)
const playRequestRef = useRef(0)
const startPlayback = useCallback(
@@ -1057,9 +1062,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
recipe: (
state: playbackQueue.PlaybackQueueState
) => playbackQueue.PlaybackQueueState,
recorded: { playlistId?: Id<"playlists"> } = {}
recorded: { playlistId?: Id<"playlists">; origin?: string } = {}
) => {
playRequestRef.current += 1
queueOriginRef.current =
recorded.origin ??
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
const previousSongId = store.getState().queue[0]
store.update(recipe)
const firstSongId = store.getState().queue[0]
@@ -1084,7 +1092,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
async (
songIds: Id<"songs">[] | Promise<Id<"songs">[]>,
shuffled: boolean,
recorded: { playlistId?: Id<"playlists"> } = {}
recorded: { playlistId?: Id<"playlists">; origin?: string } = {}
) => {
const request = ++playRequestRef.current
let resolvedSongIds: Id<"songs">[]
@@ -1149,12 +1157,19 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
)
const playFromSong = useCallback(
async (songId: Id<"songs">, songIds: Id<"songs">[]) => {
startPlayback((state) =>
playbackQueue.startQueueFromSong(state, songId, songIds)
async (songId: Id<"songs">, songIds: Id<"songs">[], origin?: string) => {
if (
origin &&
queueOriginRef.current === origin &&
store.getState().queue[0] === songId
)
return
startPlayback(
(state) => playbackQueue.startQueueFromSong(state, songId, songIds),
{ origin }
)
},
[startPlayback]
[startPlayback, store]
)
const playFromLibrarySong = useCallback(
@@ -1222,13 +1237,17 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
const playAlbum = useCallback(
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
playCollection(loadAlbumSongIds(albumId, songIds), false),
playCollection(loadAlbumSongIds(albumId, songIds), false, {
origin: `album:${albumId}`,
}),
[playCollection, loadAlbumSongIds]
)
const playAlbumShuffled = useCallback(
(albumId: Id<"albums">, songIds?: Id<"songs">[]) =>
playCollection(loadAlbumSongIds(albumId, songIds), true),
playCollection(loadAlbumSongIds(albumId, songIds), true, {
origin: `album:${albumId}`,
}),
[playCollection, loadAlbumSongIds]
)
+13 -9
View File
@@ -76,7 +76,7 @@ export function PlayerBar() {
queueOpen && !isMobile && "right-72"
)}
>
<div className="pointer-events-auto flex w-full max-w-6xl items-center gap-2 rounded-full border border-white/20 bg-[#303033] px-3 py-2 text-white shadow-lg @min-[640px]:gap-5 @min-[640px]:px-5 @min-[640px]:py-3">
<div className="pointer-events-auto flex w-full max-w-6xl items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] @min-[640px]:gap-5 @min-[640px]:px-5 @min-[640px]:py-3 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-1 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
<Button
variant="ghost"
@@ -85,7 +85,9 @@ export function PlayerBar() {
aria-pressed={shuffleEnabled}
className={cn(
"hidden @min-[640px]:inline-flex",
shuffleEnabled ? "text-white" : "text-white/40"
shuffleEnabled
? "text-card-foreground dark:text-white"
: "text-muted-foreground dark:text-white/40"
)}
onClick={() => void toggleShuffle()}
>
@@ -129,7 +131,9 @@ export function PlayerBar() {
aria-pressed={repeatEnabled !== "none"}
className={cn(
"hidden @min-[640px]:inline-flex",
repeatEnabled !== "none" ? "text-white" : "text-white/40"
repeatEnabled !== "none"
? "text-card-foreground dark:text-white"
: "text-muted-foreground dark:text-white/40"
)}
onClick={() => void cycleRepeat()}
>
@@ -141,7 +145,7 @@ export function PlayerBar() {
</Button>
</div>
<div className="relative flex min-w-0 flex-1 items-center gap-2 pb-2 @min-[640px]:gap-3">
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 @min-[640px]:h-16 @min-[640px]:gap-3">
{currentSong ? (
<>
<div className="relative size-9 shrink-0 overflow-hidden rounded @min-[640px]:size-14">
@@ -180,23 +184,23 @@ export function PlayerBar() {
<AudioFormatBadge
format={currentFormat}
iconOnly
backgroundColor="#303033"
backgroundColor="var(--player-background)"
/>
) : null}
</>
) : (
<Image
src="/logo-monochrome.svg"
src="/logo.png"
alt="oTunes"
width={14}
width={24}
height={24}
className="mx-auto my-2 h-6 w-auto opacity-85"
className="mx-auto size-6 opacity-85"
/>
)}
<div className="absolute inset-x-0 -bottom-1">
<Slider
className={cn(
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-white/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-white/30",
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30",
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
)}
min={0}
+5 -1
View File
@@ -697,7 +697,11 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
}}
isNowPlaying={currentSong?.id === song.id}
onPlay={() =>
void playFromSong(song.id as Id<"songs">, playlistSongIds)
void playFromSong(
song.id as Id<"songs">,
playlistSongIds,
`playlist:${playlist.id}`
)
}
/>
))
+5 -1
View File
@@ -64,7 +64,11 @@ export function startQueueFromSong(
songIds: Id<"songs">[]
): PlaybackQueueState {
const index = songIds.indexOf(songId)
const rest = index === -1 ? [] : songIds.slice(index + 1)
const rest = state.shuffleEnabled
? uniqueSongIds(songIds).filter((id) => id !== songId)
: index === -1
? []
: songIds.slice(index + 1)
return {
...state,
queue: [songId, ...(state.shuffleEnabled ? shuffleArray(rest) : rest)],
+10 -2
View File
@@ -433,7 +433,11 @@ export const playFromSong = mutation({
}
const index = songIds.indexOf(songId)
const rest = index === -1 ? [] : songIds.slice(index + 1)
const rest = user.shuffleEnabled
? uniqueSongIds(songIds).filter((id) => id !== songId)
: index === -1
? []
: songIds.slice(index + 1)
const queueRest = user.shuffleEnabled ? shuffleArray(rest) : rest
await setQueueState(ctx, userId, {
@@ -588,7 +592,11 @@ export const playFromLibrarySong = mutation({
const songIds = await getSortedLibrarySongIds(ctx, sortKey, sortDirection)
const index = songIds.indexOf(songId)
const rest = index === -1 ? [] : songIds.slice(index + 1)
const rest = user.shuffleEnabled
? uniqueSongIds(songIds).filter((id) => id !== songId)
: index === -1
? []
: songIds.slice(index + 1)
const queueRest = user.shuffleEnabled ? shuffleArray(rest) : rest
await setQueueState(ctx, userId, {