diff --git a/src/components/AlbumDescription.tsx b/src/components/AlbumDescription.tsx index dabf4dc..802a7c5 100644 --- a/src/components/AlbumDescription.tsx +++ b/src/components/AlbumDescription.tsx @@ -1,9 +1,10 @@ import React, { useCallback, useState } from 'react'; import { ScrollView, StyleSheet, TouchableOpacity } from 'react-native'; import { Button, Dialog, Portal, Text, useTheme } from 'react-native-paper'; +import type { MainAlbum } from '../types/albumDetail'; export const AlbumDescription = ( - { description }: { description?: string } + { album }: { album: MainAlbum } ) => { const appTheme = useTheme(); const [ @@ -11,6 +12,8 @@ export const AlbumDescription = ( setDialogVisible, ] = useState(false); + const { description } = album; + const showDialog = useCallback(() => { if (description) { setDialogVisible(true); @@ -40,7 +43,7 @@ export const AlbumDescription = ( onDismiss={hideDialog} style={styles.dialog} > - Album Description + {album.name} diff --git a/src/pages/album.tsx b/src/pages/album.tsx index 76a056f..2970d95 100644 --- a/src/pages/album.tsx +++ b/src/pages/album.tsx @@ -17,44 +17,49 @@ import { Main } from '../types/albumDetail'; import { songToTrack } from '../utils/songToTrack'; export function AlbumDetail() { - const insets = useSafeAreaInsets(); - const dispatch = useAppDispatch(); - const { album } = (useRoute().params as { album: HotAlbum }); + const insets = useSafeAreaInsets(); + const dispatch = useAppDispatch(); + const { album } = (useRoute().params as { album: HotAlbum }); - const { data, error } = useSWRInfinite
((index) => - `http://music.163.com/api/album/${album.id}?ext=true&offset=${index * 10}&total=true&limit=10`, - ); + const { data, error } = useSWRInfinite
((index) => + `http://music.163.com/api/album/${album.id}?ext=true&offset=${index * 10}&total=true&limit=10`, + ); - const playAll = async () => { - const tracksData = data?.flatMap(d => d.album.songs) - .map(songToTrack) as TrackType[]; - await dispatch(setQueueAsync(tracksData)); - await TrackPlayer.play(); - }; + const playAll = async () => { + const tracksData = data?.flatMap(d => d.album.songs) + .map(songToTrack) as TrackType[]; + await dispatch(setQueueAsync(tracksData)); + await TrackPlayer.play(); + }; - return ( - - - - {!error ? d.album.songs - ).length || 0} - /> : null} - - - ); + return ( + + + {data && data[0].album && ( + + )} + + {!error && ( + d.album.songs + ).length || 0} + /> + )} + + + ); } const styles = StyleSheet.create({ - container: { - flex: 1, - alignContent: 'center', - }, + container: { + flex: 1, + alignContent: 'center', + }, });