From b43c64962acc9e9a1e1a4a08bf0c708d99c85d17 Mon Sep 17 00:00:00 2001 From: danis Date: Sun, 10 Sep 2023 14:48:39 +0200 Subject: [PATCH] favorites search view filter + song query from favorites data --- front/components/SearchResult.tsx | 48 +++++++++++++++++++++++++++++-- front/views/SearchView.tsx | 4 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/front/components/SearchResult.tsx b/front/components/SearchResult.tsx index 274cf54..5bf97e3 100644 --- a/front/components/SearchResult.tsx +++ b/front/components/SearchResult.tsx @@ -19,7 +19,7 @@ import { SearchContext } from '../views/SearchView'; import { useQueries, useQuery } from '../Queries'; import { translate } from '../i18n/i18n'; import API from '../API'; -import LoadingComponent from './Loading'; +import LoadingComponent, { LoadingView } from './Loading'; import ArtistCard from './ArtistCard'; import GenreCard from './GenreCard'; import SongCard from './SongCard'; @@ -299,6 +299,47 @@ const GenreSearchComponent = (props: ItemSearchComponentProps) => { ); }; +type FavoriteComponentProps = { + maxRows?: number; +}; + +const FavoritesComponent = (props: FavoriteComponentProps) => { + const favoritesQuery = useQuery(API.getLikedSongs()); + const songQueries = useQueries( + favoritesQuery.data?.map((favorite) => favorite.songId).map((songId) => API.getSong(songId)) ?? + [] + ); + + const navigation = useNavigation(); + + if (favoritesQuery.isError) { + navigation.navigate('Error'); + return <>; + } + if (!favoritesQuery.data) { + return ; + } + + return ( + + + {translate('songsFilter')} + + + {songQueries.map((songData) => ( + { + API.createSearchHistoryEntry(comp.name, 'song'); //todo + navigation.navigate('Song', { songId: comp.id }); //todo + }} + /> + ))} + + + ); +} + const AllComponent = () => { const screenSize = useBreakpointValue({ base: 'small', md: 'big' }); const isMobileView = screenSize == 'small'; @@ -344,6 +385,8 @@ const FilterSwitch = () => { return ; case 'genre': return ; + case 'favorites': + return ; default: return Something very bad happened: {currentFilter}; } @@ -351,7 +394,8 @@ const FilterSwitch = () => { export const SearchResultComponent = () => { const { stringQuery } = React.useContext(SearchContext); - const shouldOutput = !!stringQuery.trim(); + const {filter} = React.useContext(SearchContext) + const shouldOutput = !!stringQuery.trim() || filter == 'favorites'; return shouldOutput ? ( diff --git a/front/views/SearchView.tsx b/front/views/SearchView.tsx index 386d584..21e7c3c 100644 --- a/front/views/SearchView.tsx +++ b/front/views/SearchView.tsx @@ -13,8 +13,8 @@ import { RouteProps } from '../Navigation'; import LikedSong from '../models/LikedSong'; interface SearchContextType { - filter: 'artist' | 'song' | 'genre' | 'all'; - updateFilter: (newData: 'artist' | 'song' | 'genre' | 'all') => void; + filter: 'artist' | 'song' | 'genre' | 'all' | 'favorites'; + updateFilter: (newData: 'artist' | 'song' | 'genre' | 'all' | 'favorites' s) => void; stringQuery: string; updateStringQuery: (newData: string) => void; songData: Song[];