Front: DiscoveryView: USe Like status

This commit is contained in:
Arthur Jamet
2023-12-19 15:29:15 +01:00
committed by Clément Le Bihan
parent 60988dd599
commit 962cf58e77
3 changed files with 20 additions and 7 deletions
+18 -6
View File
@@ -1,8 +1,12 @@
import Song from '../../models/Song';
import React from 'react';
import { Image, View } from 'react-native';
import { Pressable, Text, PresenceTransition, Icon, useBreakpointValue } from 'native-base';
import { Pressable, Text, IconButton, PresenceTransition, Icon, useBreakpointValue } from 'native-base';
import { Ionicons } from '@expo/vector-icons';
import { useQuery } from '../../Queries';
import API from '../../API';
import { MaterialIcons } from '@expo/vector-icons';
import { useLikeSongMutation } from '../../utils/likeSongMutation';
type SongCardInfoProps = {
song: Song;
@@ -16,6 +20,9 @@ const SongCardInfo = (props: SongCardInfoProps) => {
const [isPlayHovered, setIsPlayHovered] = React.useState(false);
const [isHovered, setIsHovered] = React.useState(false);
const [isSlided, setIsSlided] = React.useState(false);
const user = useQuery(API.getUserInfo);
const isLiked = (props.song.likedByUsers ?? []).filter(({ userId }) => userId === user.data?.id).length > 0;
const { mutate } = useLikeSongMutation();
const CardDims = {
height: isPhone ? 160 : 200,
@@ -185,13 +192,18 @@ const SongCardInfo = (props: SongCardInfoProps) => {
{props.song.artist?.name}
</Text>
</View>
<Ionicons
style={{
flexShrink: 0,
}}
name="bookmark-outline"
<IconButton
variant={'ghost'}
borderRadius={'full'}
size={17}
color="#6075F9"
onPress={async () => {
mutate({ songId: props.song.id, like: !isLiked });
}}
_icon={{
as: MaterialIcons,
name: isLiked ? 'favorite' : 'favorite-outline',
}}
/>
</View>
</View>
+1
View File
@@ -30,6 +30,7 @@ export const SongValidator = yup
artist: yup.lazy(() => ArtistValidator.default(undefined)).optional(),
album: yup.lazy(() => AlbumValidator.default(undefined)).optional(),
genre: yup.lazy(() => GenreValidator.default(undefined)).optional(),
likedByUsers: yup.lazy(() => yup.array(yup.object({ userId: yup.number().required() })).default(undefined)).optional(),
})
.concat(ModelValidator)
.transform((song: Song) => ({
+1 -1
View File
@@ -10,7 +10,7 @@ import GoldenRatio from '../../components/V2/GoldenRatio';
// eslint-disable-next-line @typescript-eslint/ban-types
const HomeView = (props: RouteProps<{}>) => {
const suggestionsQuery = useQuery(API.getSongSuggestions(['artist', 'SongHistory']));
const suggestionsQuery = useQuery(API.getSongSuggestions(['artist', 'SongHistory', 'likedByUsers']));
const navigation = useNavigation();
const screenSize = useBreakpointValue({ base: 'small', md: 'big' });
const isPhone = screenSize === 'small';