- 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
152 lines
4.1 KiB
TypeScript
152 lines
4.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 { useServerConfig } from "@/contexts/server-config"
|
|
import type { BrowseAlbum, BrowseArtist, PlaylistSummary } from "@otunes/convex/types"
|
|
import { albumCoverUrl, artistCoverUrl, playlistCoverUrl } from "@/lib/urls"
|
|
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
|
|
|
function CoverImage({ uri, size, rounded }: { uri: string; size: number; rounded?: boolean }) {
|
|
const colors = useThemeColors()
|
|
return (
|
|
<Image
|
|
source={{ uri }}
|
|
style={[
|
|
{ width: size, height: size, borderRadius: rounded ? size / 2 : radius.md },
|
|
{ backgroundColor: colors.muted },
|
|
]}
|
|
contentFit="cover"
|
|
transition={150}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export function AlbumCard({ album }: { album: BrowseAlbum }) {
|
|
const router = useRouter()
|
|
const { config } = useServerConfig()
|
|
const colors = useThemeColors()
|
|
if (!config) return null
|
|
|
|
return (
|
|
<Pressable
|
|
style={styles.card}
|
|
onPress={() => router.push(`/album/${album.id}`)}
|
|
>
|
|
<CoverImage uri={albumCoverUrl(config.serverUrl, album.id)} size={140} />
|
|
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
|
{album.title}
|
|
</Text>
|
|
<Text style={[styles.subtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
|
{album.artist.name}
|
|
</Text>
|
|
</Pressable>
|
|
)
|
|
}
|
|
|
|
export function ArtistCard({ artist }: { artist: BrowseArtist }) {
|
|
const router = useRouter()
|
|
const { config } = useServerConfig()
|
|
const colors = useThemeColors()
|
|
if (!config) return null
|
|
|
|
return (
|
|
<Pressable
|
|
style={styles.card}
|
|
onPress={() => router.push(`/artist/${artist.id}`)}
|
|
>
|
|
<CoverImage uri={artistCoverUrl(config.serverUrl, artist.id)} size={140} rounded />
|
|
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
|
{artist.name}
|
|
</Text>
|
|
</Pressable>
|
|
)
|
|
}
|
|
|
|
export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
|
const router = useRouter()
|
|
const { config } = useServerConfig()
|
|
const colors = useThemeColors()
|
|
if (!config) return null
|
|
|
|
return (
|
|
<Pressable
|
|
style={styles.card}
|
|
onPress={() => router.push(`/playlist/${playlist.id}`)}
|
|
>
|
|
<CoverImage uri={playlistCoverUrl(config.serverUrl, playlist.id)} size={140} />
|
|
<Text style={[styles.title, { color: colors.foreground }]} numberOfLines={2}>
|
|
{playlist.title}
|
|
</Text>
|
|
<Text style={[styles.subtitle, { color: colors.mutedForeground }]} numberOfLines={1}>
|
|
{playlist.owner}
|
|
</Text>
|
|
</Pressable>
|
|
)
|
|
}
|
|
|
|
export function ContentCarousel({
|
|
title,
|
|
href,
|
|
content,
|
|
}: {
|
|
title: string
|
|
href?: string
|
|
content: (BrowseAlbum | BrowseArtist | PlaylistSummary)[]
|
|
}) {
|
|
const router = useRouter()
|
|
const colors = useThemeColors()
|
|
|
|
return (
|
|
<View style={styles.section}>
|
|
<Pressable
|
|
disabled={!href}
|
|
onPress={() => href && router.push(href as never)}
|
|
style={styles.sectionHeader}
|
|
>
|
|
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>{title}</Text>
|
|
{href ? <Ionicons name="chevron-forward" size={18} color={colors.mutedForeground} /> : null}
|
|
</Pressable>
|
|
<View style={styles.grid}>
|
|
{content.map((item) => {
|
|
if ("owner" in item) return <PlaylistCard key={item.id} playlist={item} />
|
|
if ("artist" in item) return <AlbumCard key={item.id} album={item} />
|
|
return <ArtistCard key={item.id} artist={item} />
|
|
})}
|
|
</View>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
card: {
|
|
width: 140,
|
|
gap: spacing.xs,
|
|
},
|
|
title: {
|
|
fontSize: 14,
|
|
fontWeight: "600",
|
|
},
|
|
subtitle: {
|
|
fontSize: 12,
|
|
},
|
|
section: {
|
|
gap: spacing.md,
|
|
},
|
|
sectionHeader: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: spacing.xs,
|
|
},
|
|
sectionTitle: {
|
|
fontSize: 20,
|
|
fontWeight: "700",
|
|
},
|
|
grid: {
|
|
flexDirection: "row",
|
|
flexWrap: "wrap",
|
|
gap: spacing.lg,
|
|
},
|
|
})
|