182 lines
5.6 KiB
TypeScript
182 lines
5.6 KiB
TypeScript
import { MusicEntityView } from "@/components/music-entity-view"
|
|
import { Stack, useLocalSearchParams } from "expo-router"
|
|
import { Pressable, StyleSheet, Text, View } from "react-native"
|
|
import { Ionicons } from "@expo/vector-icons"
|
|
|
|
import { CoverImage } from "@/components/cover-image"
|
|
|
|
import { MediaGridList } from "@/components/media-cards"
|
|
import { MediaActionMenu } from "@/components/media-actions-sheet"
|
|
import { CollectionDetailSkeleton } from "@/components/skeletons"
|
|
import { Button } from "@/components/ui/primitives"
|
|
import { contentBottomInset } from "@/components/player"
|
|
import { useFavorites } from "@/contexts/favorites"
|
|
import { usePlaybackActions } from "@/contexts/playback"
|
|
import { useServerConfig } from "@/contexts/server-config"
|
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
|
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import { artistCoverUrl } from "@/lib/urls"
|
|
import { spacing, useThemeColors } from "@/lib/theme"
|
|
|
|
export default function ArtistScreen() {
|
|
const { id } = useLocalSearchParams<{ id: string }>()
|
|
const colors = useThemeColors()
|
|
const { config } = useServerConfig()
|
|
const data = useCachedQuery(
|
|
api.library.browseArtistDetail,
|
|
typeof id === "string" ? { id: id as Id<"artists"> } : "skip"
|
|
)
|
|
const { playArtist, playArtistShuffled } = usePlaybackActions()
|
|
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
|
|
const { handleArtistAction, isArtistFavorite: isArtistFav } =
|
|
useMediaMenuActions()
|
|
|
|
if (data === undefined || !config) {
|
|
return (
|
|
<>
|
|
<Stack.Screen
|
|
options={{
|
|
title: "",
|
|
headerLargeTitle: false,
|
|
}}
|
|
/>
|
|
<CollectionDetailSkeleton round />
|
|
</>
|
|
)
|
|
}
|
|
|
|
if (data === null) {
|
|
return (
|
|
<>
|
|
<Stack.Screen
|
|
options={{
|
|
title: "",
|
|
headerLargeTitle: false,
|
|
}}
|
|
/>
|
|
<View style={[styles.empty, { backgroundColor: colors.background }]}>
|
|
<Text style={{ color: colors.mutedForeground }}>
|
|
Artist not found.
|
|
</Text>
|
|
</View>
|
|
</>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Stack.Screen
|
|
options={{
|
|
title: "",
|
|
headerLargeTitle: false,
|
|
headerRight: () => (
|
|
<MediaActionMenu
|
|
selectedCount={data.albums.length}
|
|
favorited={isArtistFav(data.artist.id)}
|
|
share={{
|
|
type: "artist",
|
|
artistId: data.artist.id,
|
|
title: data.artist.name,
|
|
}}
|
|
onAction={(action) =>
|
|
void handleArtistAction(data.artist, action)
|
|
}
|
|
>
|
|
<Pressable hitSlop={8}>
|
|
<Ionicons
|
|
name="ellipsis-horizontal"
|
|
size={22}
|
|
color={colors.foreground}
|
|
/>
|
|
</Pressable>
|
|
</MediaActionMenu>
|
|
),
|
|
}}
|
|
/>
|
|
<MediaGridList
|
|
content={data.albums}
|
|
paddingBottom={contentBottomInset}
|
|
contentInset={false}
|
|
ListHeaderComponent={
|
|
<MusicEntityView
|
|
kind="artist"
|
|
id={data.artist.id}
|
|
style={styles.hero}
|
|
>
|
|
<CoverImage
|
|
uri={artistCoverUrl(config.serverUrl, data.artist.id)}
|
|
hasCover={data.artist.photo != null}
|
|
style={styles.avatar}
|
|
/>
|
|
<Text style={[styles.title, { color: colors.foreground }]}>
|
|
{data.artist.name}
|
|
</Text>
|
|
<View style={styles.actions}>
|
|
<Pressable
|
|
onPress={() => void toggleArtistFavorite(data.artist.id)}
|
|
hitSlop={8}
|
|
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
|
>
|
|
<Ionicons
|
|
name={
|
|
isArtistFavorite(data.artist.id) ? "star" : "star-outline"
|
|
}
|
|
size={24}
|
|
color={
|
|
isArtistFavorite(data.artist.id)
|
|
? colors.primary
|
|
: colors.foreground
|
|
}
|
|
/>
|
|
</Pressable>
|
|
<Button
|
|
title="Play"
|
|
icon="play"
|
|
onPress={() => void playArtist(data.artist.id)}
|
|
style={styles.playButton}
|
|
/>
|
|
<Pressable
|
|
accessibilityRole="button"
|
|
accessibilityLabel="Shuffle"
|
|
hitSlop={8}
|
|
onPress={() => void playArtistShuffled(data.artist.id)}
|
|
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
|
>
|
|
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
|
</Pressable>
|
|
</View>
|
|
</MusicEntityView>
|
|
}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
empty: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
|
avatar: {
|
|
width: 180,
|
|
height: 180,
|
|
borderRadius: 90,
|
|
},
|
|
title: { fontSize: 28, fontWeight: "800", textAlign: "center" },
|
|
actions: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
gap: spacing.sm,
|
|
marginTop: spacing.sm,
|
|
},
|
|
playButton: { borderRadius: 999, minWidth: 160 },
|
|
iconAction: {
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: 22,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
})
|