-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from Arthi-chaud/front/enhance-search-experience
Search across multiple resources
- Loading branch information
Showing
14 changed files
with
631 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 0 additions & 157 deletions
157
front/src/components/infinite/selectable-infinite-view.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Meelo is a music server and application to enjoy your personal music files anywhere, anytime you want. | ||
* Copyright (C) 2023 | ||
* | ||
* Meelo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Meelo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { NextRouter, useRouter } from "next/router"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
/** | ||
* Utilitary to update router when using tabs | ||
* @param getTabValueFromRouter how to get the tab value from the router state | ||
* @param defaultTab the default tab | ||
* @param otherTabs the other tabs | ||
*/ | ||
export const useTabRouter = <TabValue extends string>( | ||
getTabValueFromRouter: ( | ||
router: NextRouter, | ||
) => string | string[] | undefined, | ||
// This should persist the tab change in the router | ||
urlOnTabChange: (newTab: TabValue) => string, | ||
defaultTab: TabValue, | ||
...otherTabs: TabValue[] | ||
) => { | ||
const router = useRouter(); | ||
const { t } = useTranslation(); | ||
const tabs = useMemo( | ||
() => [defaultTab, ...otherTabs], | ||
[defaultTab, otherTabs], | ||
); | ||
const getTabFromQuery = () => | ||
tabs.find( | ||
(availableTab) => | ||
availableTab.toLowerCase() == | ||
getTabValueFromRouter(router)?.toString().toLowerCase(), | ||
); | ||
const [selectedTab, selectTab] = useState<TabValue>( | ||
getTabFromQuery() ?? defaultTab, | ||
); | ||
|
||
//Handle going back in history | ||
useEffect(() => { | ||
const tabFromQuery = getTabFromQuery(); | ||
const newTab = tabFromQuery ?? defaultTab; | ||
if (newTab !== selectedTab) { | ||
selectTab(tabFromQuery ?? defaultTab); | ||
} | ||
}, [router.asPath]); | ||
useEffect(() => { | ||
router.push(urlOnTabChange(selectedTab), undefined, { | ||
shallow: true, | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selectedTab]); | ||
|
||
return { selectedTab, selectTab }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Meelo is a music server and application to enjoy your personal music files anywhere, anytime you want. | ||
* Copyright (C) 2023 | ||
* | ||
* Meelo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Meelo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { RequireExactlyOne } from "type-fest"; | ||
import { SongWithRelations } from "./song"; | ||
import { ArtistWithRelations } from "./artist"; | ||
import { AlbumWithRelations } from "./album"; | ||
|
||
export type SearchResult = RequireExactlyOne<{ | ||
song: SongWithRelations<"artist" | "featuring" | "illustration" | "master">; | ||
album: AlbumWithRelations<"artist" | "illustration">; | ||
artist: ArtistWithRelations<"illustration">; | ||
}>; | ||
|
||
export const SearchResultTransformer = ( | ||
results: unknown, | ||
): Promise<SearchResult[]> => { | ||
if (!Array.isArray(results)) { | ||
throw new Error("Search result is not an array"); | ||
} | ||
return Promise.all( | ||
results.map(async (result) => { | ||
if ("groupId" in result) { | ||
return { | ||
song: await SongWithRelations([ | ||
"artist", | ||
"featuring", | ||
"illustration", | ||
"master", | ||
] as const).validate(result), | ||
}; | ||
} else if ("masterId" in result) { | ||
return { | ||
album: await AlbumWithRelations([ | ||
"artist", | ||
"illustration", | ||
] as const).validate(result), | ||
}; | ||
} | ||
return { | ||
artist: await ArtistWithRelations([ | ||
"illustration", | ||
] as const).validate(result), | ||
}; | ||
}), | ||
); | ||
}; |
Oops, something went wrong.