- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library) - Move Convex backend to @otunes/convex for web and mobile reuse - Update web app imports and API routes to use shared package
271 lines
7.1 KiB
TypeScript
271 lines
7.1 KiB
TypeScript
import { Ionicons } from "@expo/vector-icons"
|
|
import { Image } from "expo-image"
|
|
import { useRouter } from "expo-router"
|
|
import { Pressable, StyleSheet, Text, View } from "react-native"
|
|
|
|
import { usePlayback } from "@/contexts/playback"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
import type { BrowseSong } from "@otunes/convex/types"
|
|
import { formatDuration } from "@/lib/format"
|
|
import { albumCoverUrl } from "@/lib/urls"
|
|
import { playerBarHeight, spacing, useThemeColors } from "@/lib/theme"
|
|
|
|
export function PlayerBar() {
|
|
const router = useRouter()
|
|
const colors = useThemeColors()
|
|
const { config } = useServerConfig()
|
|
const {
|
|
currentSong,
|
|
isPlaying,
|
|
shuffleEnabled,
|
|
repeatEnabled,
|
|
currentTime,
|
|
duration,
|
|
queueSongIds,
|
|
setIsPlaying,
|
|
seekTo,
|
|
toggleShuffle,
|
|
cycleRepeat,
|
|
skipNext,
|
|
skipPrevious,
|
|
} = usePlayback()
|
|
|
|
const hasQueue = queueSongIds.length > 0
|
|
|
|
return (
|
|
<View style={[styles.container, { backgroundColor: colors.card, borderColor: colors.border }]}>
|
|
<Pressable
|
|
style={styles.songArea}
|
|
onPress={() => router.push("/queue")}
|
|
disabled={!currentSong}
|
|
>
|
|
{currentSong && config ? (
|
|
<>
|
|
<Image
|
|
source={{ uri: albumCoverUrl(config.serverUrl, currentSong.album.id) }}
|
|
style={styles.artwork}
|
|
contentFit="cover"
|
|
/>
|
|
<View style={styles.meta}>
|
|
<Text style={[styles.songTitle, { color: colors.foreground }]} numberOfLines={1}>
|
|
{currentSong.title}
|
|
</Text>
|
|
<Text style={[styles.artistName, { color: colors.mutedForeground }]} numberOfLines={1}>
|
|
{currentSong.artist.name}
|
|
</Text>
|
|
</View>
|
|
</>
|
|
) : (
|
|
<Text style={[styles.placeholder, { color: colors.mutedForeground }]}>oTunes</Text>
|
|
)}
|
|
</Pressable>
|
|
|
|
<View style={styles.controls}>
|
|
<Pressable onPress={() => void toggleShuffle()} hitSlop={8}>
|
|
<Ionicons
|
|
name="shuffle"
|
|
size={18}
|
|
color={shuffleEnabled ? colors.primary : colors.mutedForeground}
|
|
/>
|
|
</Pressable>
|
|
<Pressable disabled={!hasQueue} onPress={() => void skipPrevious()} hitSlop={8}>
|
|
<Ionicons name="play-skip-back" size={22} color={colors.foreground} />
|
|
</Pressable>
|
|
<Pressable
|
|
disabled={!hasQueue}
|
|
onPress={() => setIsPlaying(!isPlaying)}
|
|
style={[styles.playButton, { backgroundColor: colors.primary }]}
|
|
>
|
|
<Ionicons
|
|
name={isPlaying ? "pause" : "play"}
|
|
size={20}
|
|
color={colors.primaryForeground}
|
|
/>
|
|
</Pressable>
|
|
<Pressable disabled={!hasQueue} onPress={() => void skipNext()} hitSlop={8}>
|
|
<Ionicons name="play-skip-forward" size={22} color={colors.foreground} />
|
|
</Pressable>
|
|
<Pressable onPress={() => void cycleRepeat()} hitSlop={8}>
|
|
<Ionicons
|
|
name={repeatEnabled === "once" ? "repeat-outline" : "repeat"}
|
|
size={18}
|
|
color={repeatEnabled !== "none" ? colors.primary : colors.mutedForeground}
|
|
/>
|
|
</Pressable>
|
|
</View>
|
|
|
|
{currentSong ? (
|
|
<View style={styles.progressRow}>
|
|
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
|
{formatDuration(currentTime)}
|
|
</Text>
|
|
<Pressable
|
|
style={[styles.progressTrack, { backgroundColor: colors.muted }]}
|
|
onPress={(event) => {
|
|
const { locationX } = event.nativeEvent
|
|
const width = event.currentTarget as unknown as { offsetWidth?: number }
|
|
const trackWidth = 200
|
|
const ratio = Math.min(1, Math.max(0, locationX / trackWidth))
|
|
void seekTo(ratio * duration)
|
|
}}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.progressFill,
|
|
{
|
|
backgroundColor: colors.primary,
|
|
width: `${duration > 0 ? (currentTime / duration) * 100 : 0}%`,
|
|
},
|
|
]}
|
|
/>
|
|
</Pressable>
|
|
<Text style={[styles.time, { color: colors.mutedForeground }]}>
|
|
{formatDuration(duration)}
|
|
</Text>
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
)
|
|
}
|
|
|
|
export function SongRow({
|
|
song,
|
|
onPress,
|
|
onLongPress,
|
|
trailing,
|
|
}: {
|
|
song: BrowseSong
|
|
onPress?: () => void
|
|
onLongPress?: () => void
|
|
trailing?: React.ReactNode
|
|
}) {
|
|
const { config } = useServerConfig()
|
|
const colors = useThemeColors()
|
|
if (!config) return null
|
|
|
|
return (
|
|
<Pressable
|
|
style={[styles.row, { borderBottomColor: colors.border }]}
|
|
onPress={onPress}
|
|
onLongPress={onLongPress}
|
|
>
|
|
<Image
|
|
source={{ uri: albumCoverUrl(config.serverUrl, song.album.id) }}
|
|
style={styles.rowArtwork}
|
|
contentFit="cover"
|
|
/>
|
|
<View style={styles.rowMeta}>
|
|
<Text style={[styles.rowTitle, { color: colors.foreground }]} numberOfLines={1}>
|
|
{song.title}
|
|
</Text>
|
|
<Text style={[styles.rowSubtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
|
{song.artist.name} · {song.album.title}
|
|
</Text>
|
|
</View>
|
|
<Text style={[styles.duration, { color: colors.mutedForeground }]}>
|
|
{formatDuration(song.durationSeconds)}
|
|
</Text>
|
|
{trailing}
|
|
</Pressable>
|
|
)
|
|
}
|
|
|
|
export const contentBottomInset = playerBarHeight + spacing.lg
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
borderTopWidth: StyleSheet.hairlineWidth,
|
|
paddingHorizontal: spacing.md,
|
|
paddingTop: spacing.sm,
|
|
paddingBottom: spacing.md,
|
|
gap: spacing.sm,
|
|
},
|
|
songArea: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: spacing.sm,
|
|
minHeight: 40,
|
|
},
|
|
artwork: {
|
|
width: 40,
|
|
height: 40,
|
|
borderRadius: 6,
|
|
},
|
|
meta: {
|
|
flex: 1,
|
|
minWidth: 0,
|
|
},
|
|
songTitle: {
|
|
fontSize: 14,
|
|
fontWeight: "600",
|
|
},
|
|
artistName: {
|
|
fontSize: 12,
|
|
},
|
|
placeholder: {
|
|
fontSize: 14,
|
|
fontWeight: "600",
|
|
},
|
|
controls: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
gap: spacing.lg,
|
|
},
|
|
playButton: {
|
|
width: 40,
|
|
height: 40,
|
|
borderRadius: 20,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
progressRow: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: spacing.sm,
|
|
},
|
|
time: {
|
|
fontSize: 11,
|
|
width: 36,
|
|
textAlign: "center",
|
|
},
|
|
progressTrack: {
|
|
flex: 1,
|
|
height: 4,
|
|
borderRadius: 2,
|
|
overflow: "hidden",
|
|
},
|
|
progressFill: {
|
|
height: "100%",
|
|
},
|
|
row: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: spacing.sm,
|
|
paddingVertical: spacing.sm,
|
|
paddingHorizontal: spacing.lg,
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
},
|
|
rowArtwork: {
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: 6,
|
|
},
|
|
rowMeta: {
|
|
flex: 1,
|
|
minWidth: 0,
|
|
},
|
|
rowTitle: {
|
|
fontSize: 15,
|
|
fontWeight: "500",
|
|
},
|
|
rowSubtitle: {
|
|
fontSize: 13,
|
|
marginTop: 2,
|
|
},
|
|
duration: {
|
|
fontSize: 12,
|
|
marginRight: spacing.xs,
|
|
},
|
|
})
|