[IMP] lint, prettier, tsc
This commit is contained in:
committed by
Clément Le Bihan
parent
5ef3885f72
commit
13050e52f9
+48
-46
@@ -22,71 +22,73 @@ import { useLikeSongMutation } from '../utils/likeSongMutation';
|
|||||||
import Song from '../models/Song';
|
import Song from '../models/Song';
|
||||||
|
|
||||||
type MusicListCCProps = {
|
type MusicListCCProps = {
|
||||||
data: Song[] | undefined;
|
data: Song[] | undefined;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MusicListCC = ({ data, isLoading, refetch }: MusicListCCProps) => {
|
const MusicListCC = ({ data, isLoading, refetch }: MusicListCCProps) => {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const { mutateAsync } = useLikeSongMutation();
|
const { mutateAsync } = useLikeSongMutation();
|
||||||
const user = useQuery(API.getUserInfo);
|
const user = useQuery(API.getUserInfo);
|
||||||
|
|
||||||
const musics = (data ?? [])
|
const musics = (data ?? []).map((song) => {
|
||||||
.map((song) => {
|
|
||||||
const isLiked = song.likedByUsers?.some(({ userId }) => userId === user.data?.id) ?? false;
|
const isLiked = song.likedByUsers?.some(({ userId }) => userId === user.data?.id) ?? false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
artist: song.artist!.name,
|
artist: song.artist!.name,
|
||||||
song: song.name,
|
song: song.name,
|
||||||
image: song.cover,
|
image: song.cover,
|
||||||
lastScore: song.lastScore,
|
lastScore: song.lastScore,
|
||||||
bestScore: song.bestScore,
|
bestScore: song.bestScore,
|
||||||
liked: isLiked,
|
liked: isLiked,
|
||||||
onLike: (state: boolean) => {
|
onLike: (state: boolean) => {
|
||||||
mutateAsync({ songId: song.id, like: state }).then(() => refetch());
|
mutateAsync({ songId: song.id, like: state }).then(() => refetch());
|
||||||
},
|
},
|
||||||
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <LoadingView />;
|
return <LoadingView />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <MusicList initialMusics={musics} musicsPerPage={25} />;
|
||||||
<MusicList
|
|
||||||
initialMusics={musics}
|
|
||||||
musicsPerPage={25}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const FavoritesMusic = () => {
|
const FavoritesMusic = () => {
|
||||||
const likedSongs = useQuery(API.getLikedSongs(['artist', 'SongHistory', 'likedByUsers']));
|
const likedSongs = useQuery(API.getLikedSongs(['artist', 'SongHistory', 'likedByUsers']));
|
||||||
return <MusicListCC
|
return (
|
||||||
data={likedSongs.data?.map(x => x.song)}
|
<MusicListCC
|
||||||
isLoading={likedSongs.isLoading}
|
data={likedSongs.data?.map((x) => x.song)}
|
||||||
refetch={likedSongs.refetch}
|
isLoading={likedSongs.isLoading}
|
||||||
/>
|
refetch={likedSongs.refetch}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RecentlyPlayedMusic = () => {
|
const RecentlyPlayedMusic = () => {
|
||||||
const playHistory = useQuery(API.getUserPlayHistory(['artist', 'SongHistory', 'likedByUsers']));
|
const playHistory = useQuery(API.getUserPlayHistory(['artist', 'SongHistory', 'likedByUsers']));
|
||||||
return <MusicListCC
|
return (
|
||||||
data={playHistory.data?.filter(x => x.song !== undefined).map(x => x.song) as Song[]}
|
<MusicListCC
|
||||||
isLoading={playHistory.isLoading}
|
data={
|
||||||
refetch={playHistory.refetch}
|
playHistory.data?.filter((x) => x.song !== undefined).map((x) => x.song) as Song[]
|
||||||
/>
|
}
|
||||||
|
isLoading={playHistory.isLoading}
|
||||||
|
refetch={playHistory.refetch}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const StepUpMusic = () => {
|
const StepUpMusic = () => {
|
||||||
const nextStep = useQuery(API.getSongSuggestions(['artist', 'SongHistory', 'likedByUsers']));
|
const nextStep = useQuery(API.getSongSuggestions(['artist', 'SongHistory', 'likedByUsers']));
|
||||||
return <MusicListCC
|
return (
|
||||||
data={nextStep.data ?? []}
|
<MusicListCC
|
||||||
isLoading={nextStep.isLoading}
|
data={nextStep.data ?? []}
|
||||||
refetch={nextStep.refetch}
|
isLoading={nextStep.isLoading}
|
||||||
/>
|
refetch={nextStep.refetch}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderScene = SceneMap({
|
const renderScene = SceneMap({
|
||||||
|
|||||||
Reference in New Issue
Block a user