107 lines
2.4 KiB
TypeScript
107 lines
2.4 KiB
TypeScript
import { CoverImage } from "@/components/cover-image"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
import type { BrowseSong } from "@otunes/convex/types"
|
|
import { formatDuration } from "@/lib/format"
|
|
import { albumCoverUrl } from "@/lib/urls"
|
|
import {
|
|
miniPlayerHeight,
|
|
spacing,
|
|
tabBarHeight,
|
|
useThemeColors,
|
|
} from "@/lib/theme"
|
|
import { Pressable, StyleSheet, Text, View } from "react-native"
|
|
|
|
import {
|
|
MediaContextMenu,
|
|
type MediaMenuConfig,
|
|
} from "@/components/media-context-menu"
|
|
|
|
export function SongRow({
|
|
song,
|
|
onPress,
|
|
contextMenu,
|
|
trailing,
|
|
}: {
|
|
song: BrowseSong
|
|
onPress?: () => void
|
|
contextMenu?: Omit<MediaMenuConfig, "onAction"> & {
|
|
onAction: MediaMenuConfig["onAction"]
|
|
}
|
|
trailing?: React.ReactNode
|
|
}) {
|
|
const { config } = useServerConfig()
|
|
const colors = useThemeColors()
|
|
if (!config) return null
|
|
|
|
const row = (
|
|
<Pressable
|
|
style={[styles.row, { borderBottomColor: colors.border }]}
|
|
onPress={onPress}
|
|
>
|
|
<CoverImage
|
|
uri={albumCoverUrl(config.serverUrl, song.album.id)}
|
|
hasCover={song.album.cover != null}
|
|
style={styles.rowArtwork}
|
|
/>
|
|
<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>
|
|
)
|
|
|
|
if (!contextMenu) {
|
|
return row
|
|
}
|
|
|
|
return (
|
|
<MediaContextMenu {...contextMenu}>
|
|
{row}
|
|
</MediaContextMenu>
|
|
)
|
|
}
|
|
|
|
export const tabContentBottomInset = spacing.lg
|
|
export const contentBottomInset = miniPlayerHeight + spacing.lg
|
|
|
|
const styles = StyleSheet.create({
|
|
row: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: spacing.md,
|
|
minHeight: 64,
|
|
paddingVertical: 10,
|
|
paddingHorizontal: spacing.lg,
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
},
|
|
rowArtwork: {
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: 6,
|
|
},
|
|
rowMeta: {
|
|
flex: 1,
|
|
minWidth: 0,
|
|
},
|
|
rowTitle: {
|
|
fontSize: 16,
|
|
fontWeight: "500",
|
|
},
|
|
rowSubtitle: {
|
|
fontSize: 14,
|
|
marginTop: 3,
|
|
},
|
|
duration: {
|
|
fontSize: 12,
|
|
marginRight: spacing.xs,
|
|
},
|
|
})
|