Hide player bar when queue is empty (#4)
- Stop showing the mini player when there is no queued track - Reset playback state to 0 and paused at end of queue - Keep the current song in queue history when skipping the last track --------- Co-authored-by: Rem Helper <remhelper@abunchofknowitalls.com> Reviewed-on: https://git.abunchofknowitalls.com/joshuafhiggins/otunes/pulls/4
This commit was merged in pull request #4.
This commit is contained in:
1 parent
e4ea3b8990
commit
22a60ccb4c
6 files changed
+71
-9
No files matched your search
@@ -4,6 +4,7 @@ import { DynamicColorIOS, Platform, useColorScheme } from "react-native"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { TabBottomAccessory } from "@/components/mini-player"
|
||||
import { usePlayback } from "@/contexts/playback"
|
||||
import { appleMusic, colors } from "@/lib/theme"
|
||||
|
||||
function useRouterTheme() {
|
||||
@@ -75,6 +76,8 @@ function useNativeTabColors() {
|
||||
export default function TabsLayout() {
|
||||
const routerTheme = useRouterTheme()
|
||||
const tabColors = useNativeTabColors()
|
||||
const { currentSong, queueSongIds } = usePlayback()
|
||||
const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0)
|
||||
|
||||
return (
|
||||
<ThemeProvider value={routerTheme}>
|
||||
@@ -90,9 +93,11 @@ export default function TabsLayout() {
|
||||
tintColor={appleMusic.pink}
|
||||
minimizeBehavior="onScrollDown"
|
||||
>
|
||||
<NativeTabs.BottomAccessory>
|
||||
<TabBottomAccessory />
|
||||
</NativeTabs.BottomAccessory>
|
||||
{showBottomAccessory ? (
|
||||
<NativeTabs.BottomAccessory>
|
||||
<TabBottomAccessory />
|
||||
</NativeTabs.BottomAccessory>
|
||||
) : null}
|
||||
|
||||
<NativeTabs.Trigger name="home" disableTransparentOnScrollEdge>
|
||||
<NativeTabs.Trigger.Icon sf="house.fill" md="home" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { usePaginatedQuery, useQuery } from "convex/react"
|
||||
import { Stack } from "expo-router"
|
||||
import { Stack, useRouter } from "expo-router"
|
||||
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { Button, LoadingView } from "@/components/ui/primitives"
|
||||
@@ -12,6 +12,7 @@ import { spacing, useThemeColors } from "@/lib/theme"
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
export default function QueueScreen() {
|
||||
const router = useRouter()
|
||||
const colors = useThemeColors()
|
||||
const {
|
||||
queueSongIds,
|
||||
@@ -42,6 +43,18 @@ export default function QueueScreen() {
|
||||
void reorderQueue(next)
|
||||
}
|
||||
|
||||
function handleClearQueue() {
|
||||
if (router.canGoBack()) {
|
||||
router.back()
|
||||
setTimeout(() => {
|
||||
void clearQueue()
|
||||
}, 0)
|
||||
return
|
||||
}
|
||||
|
||||
void clearQueue()
|
||||
}
|
||||
|
||||
if (queueSongs === undefined) {
|
||||
return <LoadingView />
|
||||
}
|
||||
@@ -52,7 +65,7 @@ export default function QueueScreen() {
|
||||
options={{
|
||||
headerRight: () =>
|
||||
queueSongIds.length > 0 ? (
|
||||
<Button title="Clear" variant="ghost" onPress={() => void clearQueue()} />
|
||||
<Button title="Clear" variant="ghost" onPress={handleClearQueue} />
|
||||
) : null,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -3,6 +3,7 @@ import Slider from "@react-native-community/slider"
|
||||
import { BlurView } from "expo-blur"
|
||||
import { useRouter } from "expo-router"
|
||||
import * as Haptics from "expo-haptics"
|
||||
import { useEffect, useRef } from "react"
|
||||
import {
|
||||
Platform,
|
||||
Pressable,
|
||||
@@ -26,6 +27,7 @@ import { appleMusic, radius, spacing, usePlayerTheme } from "@/lib/theme"
|
||||
|
||||
export default function PlayerScreen() {
|
||||
const router = useRouter()
|
||||
const hadSongRef = useRef(false)
|
||||
const { push } = useAppNavigation()
|
||||
const insets = useSafeAreaInsets()
|
||||
const player = usePlayerTheme()
|
||||
@@ -50,6 +52,17 @@ export default function PlayerScreen() {
|
||||
skipPrevious,
|
||||
} = usePlayback()
|
||||
|
||||
useEffect(() => {
|
||||
if (currentSong) {
|
||||
hadSongRef.current = true
|
||||
return
|
||||
}
|
||||
|
||||
if (hadSongRef.current) {
|
||||
router.back()
|
||||
}
|
||||
}, [currentSong, router])
|
||||
|
||||
if (!currentSong || !config) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -236,7 +236,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlayingState(true)
|
||||
return
|
||||
}
|
||||
|
||||
autoPlayNextRef.current = false
|
||||
isPlayingRef.current = false
|
||||
void playerRef.current?.seekTo(0)
|
||||
currentTimeRef.current = 0
|
||||
setCurrentTime(0)
|
||||
setIsPlayingState(false)
|
||||
})
|
||||
.catch(() => {
|
||||
autoPlayNextRef.current = false
|
||||
@@ -655,7 +663,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
await skipToQueueIndexMutation({ index })
|
||||
},
|
||||
skipNext: async () => {
|
||||
const isFinishingQueue = repeatEnabled === "none" && queueLength <= 1
|
||||
if (isFinishingQueue) {
|
||||
setIsPlaying(false)
|
||||
await seekTo(0)
|
||||
}
|
||||
await skipNextMutation()
|
||||
if (isFinishingQueue) {
|
||||
await seekTo(0)
|
||||
}
|
||||
},
|
||||
skipPrevious: async () => {
|
||||
if (currentTime > PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS) {
|
||||
|
||||
@@ -790,7 +790,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
autoPlayNextRef.current = true
|
||||
isPlayingRef.current = true
|
||||
setIsPlaying(true)
|
||||
return
|
||||
}
|
||||
|
||||
autoPlayNextRef.current = false
|
||||
isPlayingRef.current = false
|
||||
audio.currentTime = 0
|
||||
setCurrentTime(0)
|
||||
setIsPlaying(false)
|
||||
})
|
||||
.catch(() => {
|
||||
autoPlayNextRef.current = false
|
||||
@@ -1066,7 +1073,16 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
await skipToQueueIndexMutation({ index })
|
||||
},
|
||||
skipNext: async () => {
|
||||
const isFinishingQueue =
|
||||
repeatEnabled === "none" && queueSongIds.length <= 1
|
||||
if (isFinishingQueue) {
|
||||
setIsPlaying(false)
|
||||
seekTo(0)
|
||||
}
|
||||
await skipNextMutation()
|
||||
if (isFinishingQueue) {
|
||||
seekTo(0)
|
||||
}
|
||||
},
|
||||
skipPrevious: async () => {
|
||||
if (currentTime > PREVIOUS_TRACK_RESTART_THRESHOLD_SECONDS) {
|
||||
|
||||
@@ -511,17 +511,16 @@ export const skipNext = mutation({
|
||||
return
|
||||
}
|
||||
|
||||
const history = appendToQueueHistory(user.queueHistory ?? [], current)
|
||||
|
||||
if (rest.length === 0) {
|
||||
await ctx.db.patch(userId, {
|
||||
songQueue: [],
|
||||
queueHistory: history,
|
||||
songQueue: [current],
|
||||
currentSongProgress: 0,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const history = appendToQueueHistory(user.queueHistory ?? [], current)
|
||||
|
||||
await ctx.db.patch(userId, {
|
||||
songQueue: rest,
|
||||
queueHistory: history,
|
||||
|
||||
Reference in new issue
Block a user