- 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
148 lines
5.5 KiB
TypeScript
148 lines
5.5 KiB
TypeScript
import { useQuery } from "convex/react"
|
|
import { Image } from "expo-image"
|
|
import { useLocalSearchParams } from "expo-router"
|
|
import { useState } from "react"
|
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"
|
|
import { SafeAreaView } from "react-native-safe-area-context"
|
|
import { Ionicons } from "@expo/vector-icons"
|
|
|
|
import { AlbumCard, ContentCarousel } from "@/components/media-cards"
|
|
import { MediaActionsSheet, type MediaAction } from "@/components/media-actions-sheet"
|
|
import { ScreenHeader } from "@/components/screen-header"
|
|
import { Button, LoadingView } from "@/components/ui/primitives"
|
|
import { contentBottomInset } from "@/components/player"
|
|
import { useAddToPlaylist } from "@/contexts/add-to-playlist"
|
|
import { useFavorites } from "@/contexts/favorites"
|
|
import { usePlayback } from "@/contexts/playback"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import type { BrowseAlbum } from "@otunes/convex/types"
|
|
import { artistCoverUrl } from "@/lib/urls"
|
|
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
|
|
|
export default function ArtistScreen() {
|
|
const { id } = useLocalSearchParams<{ id: string }>()
|
|
const colors = useThemeColors()
|
|
const { config } = useServerConfig()
|
|
const data = useQuery(api.library.browseArtistDetail, { id: id as Id<"artists"> })
|
|
const { playArtist, playArtistShuffled } = usePlayback()
|
|
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
|
|
const { openAddArtistToPlaylist } = useAddToPlaylist()
|
|
const [actionsOpen, setActionsOpen] = useState(false)
|
|
|
|
if (data === undefined || !config) {
|
|
return (
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
|
<ScreenHeader title="Artist" />
|
|
<LoadingView />
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
if (data === null) {
|
|
return (
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
|
<ScreenHeader title="Artist" />
|
|
<View style={styles.empty}>
|
|
<Text style={{ color: colors.mutedForeground }}>Artist not found.</Text>
|
|
</View>
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
function handleAction(action: MediaAction) {
|
|
if (!data) return
|
|
switch (action) {
|
|
case "playlist":
|
|
void openAddArtistToPlaylist(data.artist.id)
|
|
break
|
|
case "favorite":
|
|
void toggleArtistFavorite(data.artist.id)
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]} edges={["top"]}>
|
|
<ScreenHeader
|
|
title={data.artist.name}
|
|
right={
|
|
<Pressable onPress={() => setActionsOpen(true)} hitSlop={8}>
|
|
<Ionicons name="ellipsis-horizontal" size={22} color={colors.foreground} />
|
|
</Pressable>
|
|
}
|
|
/>
|
|
<ScrollView contentContainerStyle={{ paddingBottom: contentBottomInset }}>
|
|
<View style={styles.hero}>
|
|
<Image
|
|
source={{ uri: artistCoverUrl(config.serverUrl, data.artist.id) }}
|
|
style={styles.avatar}
|
|
contentFit="cover"
|
|
/>
|
|
<Text style={[styles.title, { color: colors.foreground }]}>{data.artist.name}</Text>
|
|
<View style={styles.actions}>
|
|
<Button title="Play" onPress={() => void playArtist(data.artist.id)} />
|
|
<Button title="Shuffle" variant="secondary" onPress={() => void playArtistShuffled(data.artist.id)} />
|
|
<Pressable onPress={() => void toggleArtistFavorite(data.artist.id)} hitSlop={8}>
|
|
<Ionicons
|
|
name={isArtistFavorite(data.artist.id) ? "star" : "star-outline"}
|
|
size={24}
|
|
color={isArtistFavorite(data.artist.id) ? colors.primary : colors.foreground}
|
|
/>
|
|
</Pressable>
|
|
</View>
|
|
</View>
|
|
|
|
{data.recentlyPlayed.length > 0 ? (
|
|
<View style={styles.section}>
|
|
<ContentCarousel title="Recently Played" content={data.recentlyPlayed} />
|
|
</View>
|
|
) : null}
|
|
|
|
{data.recentlyAdded.length > 0 ? (
|
|
<View style={styles.section}>
|
|
<ContentCarousel title="Recently Added" content={data.recentlyAdded} />
|
|
</View>
|
|
) : null}
|
|
|
|
<View style={styles.section}>
|
|
<Text style={[styles.sectionTitle, { color: colors.foreground }]}>Albums</Text>
|
|
<View style={styles.grid}>
|
|
{data.albums.map((album: BrowseAlbum) => (
|
|
<AlbumCard key={album.id} album={album} />
|
|
))}
|
|
</View>
|
|
</View>
|
|
</ScrollView>
|
|
|
|
<MediaActionsSheet
|
|
visible={actionsOpen}
|
|
title={data.artist.name}
|
|
favorited={isArtistFavorite(data.artist.id)}
|
|
onClose={() => setActionsOpen(false)}
|
|
onAction={handleAction}
|
|
/>
|
|
</SafeAreaView>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
safe: { flex: 1 },
|
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
|
avatar: {
|
|
width: 180,
|
|
height: 180,
|
|
borderRadius: 90,
|
|
backgroundColor: "#ddd",
|
|
},
|
|
title: { fontSize: 28, fontWeight: "800", textAlign: "center" },
|
|
actions: { flexDirection: "row", alignItems: "center", gap: spacing.sm, marginTop: spacing.sm },
|
|
section: { padding: spacing.lg, gap: spacing.md },
|
|
sectionTitle: { fontSize: 20, fontWeight: "700" },
|
|
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.lg },
|
|
})
|