Feature/adc/#192 barre de recherche (#201)

* context and react query add to searchView

* handle empty result + back

* #192 - New card components and history fetch + dummy suggestions fetch

* respoonsive design + filters map

* artist details view + translations + SongData mapping fix + items limitation

* history search back and front + cards + fix

* fixed useless history entries

* clean code

* clean code

* fix pr: SearchHistory new type related fixes

* simplified SearchResultComponent (useEffect removed, condition simplified to trigger different 'modes'

* search re-do onPress history cards + scoreView obj map

* clean code API.ts

* fix pr + search history behavior

* added utility function to get song suggestions with artists and fixed error types along the way

* fix in songrow the title didn't shrinked when not enough space on screen

* removed redirect callback from ArtistCard to ArtistResults

* moved the callback from genre card grid to searchresult and implemented history for songs

* SearchBar is now updating input search following stringQuery

* added scroll view to have the complete background

* Added the route props for query in Searchview

* fixed robot test

---------

Co-authored-by: Clément Le Bihan <clement.lebihan773@gmail.com>
This commit is contained in:
Amaury
2023-05-26 10:50:25 +02:00
committed by GitHub
parent 5baf9309c6
commit 97bf7bdac8
26 changed files with 902 additions and 442 deletions
+84 -13
View File
@@ -1,7 +1,9 @@
import Artist from "./models/Artist";
import Album from "./models/Album";
import AuthToken from "./models/AuthToken";
import Chapter from "./models/Chapter";
import Lesson from "./models/Lesson";
import Genre from "./models/Genre";
import LessonHistory from "./models/LessonHistory";
import Song from "./models/Song";
import SongHistory from "./models/SongHistory";
@@ -10,7 +12,7 @@ import Constants from "expo-constants";
import store from "./state/Store";
import { Platform } from "react-native";
import { en } from "./i18n/Translations";
import { QueryClient } from "react-query";
import { useQuery, QueryClient } from "react-query";
import UserSettings from "./models/UserSettings";
import { PartialDeep } from "type-fest";
import SearchHistory from "./models/SearchHistory";
@@ -343,7 +345,51 @@ export default class API {
*/
public static async searchSongs(query: string): Promise<Song[]> {
return API.fetch({
route: `/search/guess/song/${query}`,
route: `/search/songs/${query}`,
});
}
/**
* Search artists by name
* @param query the string used to find the artists
*/
public static async searchArtists(query?: string): Promise<Artist[]> {
return API.fetch({
route: `/search/artists/${query}`,
});
}
/**
* Search Album by name
* @param query the string used to find the album
*/
public static async searchAlbum(query?: string): Promise<Album[]> {
return [
{
id: 1,
name: "Super Trooper",
},
{
id: 2,
name: "Kingdom Heart 365/2 OST",
},
{
id: 3,
name: "The Legend Of Zelda Ocarina Of Time OST",
},
{
id: 4,
name: "Random Access Memories",
},
] as Album[];
}
/**
* Retrieve music genres
*/
public static async searchGenres(query?: string): Promise<Genre[]> {
return API.fetch({
route: `/search/genres/${query}`,
});
}
@@ -363,30 +409,55 @@ export default class API {
/**
* Retrieve the authenticated user's search history
* @param lessonId the id to find the lesson
* @param skip number of entries skipped before returning
* @param take how much do we take to return
* @returns Returns an array of history entries (temporary type any)
*/
public static async getSearchHistory(): Promise<SearchHistory[]> {
const tmp = await this.fetch({
route: "/history/search",
});
public static async getSearchHistory(skip?: number, take?: number): Promise<SearchHistory[]> {
return (await API.fetch({
route: `/history/search?skip=${skip ?? 0}&take=${take ?? 5}`,
method: "GET",
})).map((e: any) => {
return {
id: e.id,
query: e.query,
type: e.type,
userId: e.userId,
timestamp: new Date(e.searchDate),
} as SearchHistory
})
}
return tmp.map((value: any) => ({
query: value.query,
userID: value.userId,
id: value.id,
}));
/**
* Posts a new entry in the user's search history
* @param query is the query itself
* @param type the type of object searched
* @param timestamp the date it's been issued
* @returns nothing
*/
public static async createSearchHistoryEntry(query: string, type: string, timestamp: number): Promise<void> {
return await API.fetch({
route: `/history/search`,
method: "POST",
body: {
query: query,
type: type
},
})
}
/**
* Retrieve the authenticated user's recommendations
* @returns an array of songs
*/
public static async getUserRecommendations(): Promise<Song[]> {
public static async getSongSuggestions(): Promise<Song[]> {
const queryClient = new QueryClient();
return await queryClient.fetchQuery(["API", "allsongs"], API.getAllSongs);
}
/**
* Retrieve the authenticated user's play history
* * @returns an array of songs
*/
public static async getUserPlayHistory(): Promise<SongHistory[]> {
return this.fetch({