1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

First iteration

This commit is contained in:
Nathan G 2023-10-01 17:44:39 -07:00
parent f173824c93
commit 2ffead179a
2 changed files with 197 additions and 154 deletions

View file

@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}

View file

@ -45,6 +45,7 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({ serverId = windo
const [ books, setBooks ] = useState<BaseItemDto[]>([]);
const [ people, setPeople ] = useState<BaseItemDto[]>([]);
const [ collections, setCollections ] = useState<BaseItemDto[]>([]);
const [isLoading, setIsLoading] = useState(false);
const getDefaultParameters = useCallback(() => ({
ParentId: parentId,
@ -112,101 +113,124 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({ serverId = windo
setBooks([]);
setPeople([]);
setCollections([]);
setIsLoading(true);
if (!query) {
setIsLoading(false);
return;
}
const apiClient = ServerConnections.getApiClient(serverId);
const fetchPromises = [];
// Movie libraries
if (!collectionType || isMovies(collectionType)) {
fetchPromises.push(
// Movies row
fetchItems(apiClient, { IncludeItemTypes: 'Movie' })
.then(result => setMovies(result.Items))
.catch(() => setMovies([]));
.catch(() => setMovies([]))
);
}
// TV Show libraries
if (!collectionType || isTVShows(collectionType)) {
fetchPromises.push(
// Shows row
fetchItems(apiClient, { IncludeItemTypes: 'Series' })
.then(result => setShows(result.Items))
.catch(() => setShows([]));
.catch(() => setShows([])),
// Episodes row
fetchItems(apiClient, { IncludeItemTypes: 'Episode' })
.then(result => setEpisodes(result.Items))
.catch(() => setEpisodes([]));
.catch(() => setEpisodes([]))
);
}
// People are included for Movies and TV Shows
if (!collectionType || isMovies(collectionType) || isTVShows(collectionType)) {
fetchPromises.push(
// People row
fetchPeople(apiClient)
.then(result => setPeople(result.Items))
.catch(() => setPeople([]));
.catch(() => setPeople([]))
);
}
// Music libraries
if (!collectionType || isMusic(collectionType)) {
fetchPromises.push(
// Playlists row
fetchItems(apiClient, { IncludeItemTypes: 'Playlist' })
.then(results => setPlaylists(results.Items))
.catch(() => setPlaylists([]));
.catch(() => setPlaylists([])),
// Artists row
fetchArtists(apiClient)
.then(result => setArtists(result.Items))
.catch(() => setArtists([]));
.catch(() => setArtists([])),
// Albums row
fetchItems(apiClient, { IncludeItemTypes: 'MusicAlbum' })
.then(result => setAlbums(result.Items))
.catch(() => setAlbums([]));
.catch(() => setAlbums([])),
// Songs row
fetchItems(apiClient, { IncludeItemTypes: 'Audio' })
.then(result => setSongs(result.Items))
.catch(() => setSongs([]));
.catch(() => setSongs([]))
);
}
// Other libraries do not support in-library search currently
if (!collectionType) {
fetchPromises.push(
// Videos row
fetchItems(apiClient, {
MediaTypes: 'Video',
ExcludeItemTypes: 'Movie,Episode,TvChannel'
})
.then(result => setVideos(result.Items))
.catch(() => setVideos([]));
.catch(() => setVideos([])),
// Programs row
fetchItems(apiClient, { IncludeItemTypes: 'LiveTvProgram' })
.then(result => setPrograms(result.Items))
.catch(() => setPrograms([]));
.catch(() => setPrograms([])),
// Channels row
fetchItems(apiClient, { IncludeItemTypes: 'TvChannel' })
.then(result => setChannels(result.Items))
.catch(() => setChannels([]));
.catch(() => setChannels([])),
// Photo Albums row
fetchItems(apiClient, { IncludeItemTypes: 'PhotoAlbum' })
.then(result => setPhotoAlbums(result.Items))
.catch(() => setPhotoAlbums([]));
.catch(() => setPhotoAlbums([])),
// Photos row
fetchItems(apiClient, { IncludeItemTypes: 'Photo' })
.then(result => setPhotos(result.Items))
.catch(() => setPhotos([]));
.catch(() => setPhotos([])),
// Audio Books row
fetchItems(apiClient, { IncludeItemTypes: 'AudioBook' })
.then(result => setAudioBooks(result.Items))
.catch(() => setAudioBooks([]));
.catch(() => setAudioBooks([])),
// Books row
fetchItems(apiClient, { IncludeItemTypes: 'Book' })
.then(result => setBooks(result.Items))
.catch(() => setBooks([]));
.catch(() => setBooks([])),
// Collections row
fetchItems(apiClient, { IncludeItemTypes: 'BoxSet' })
.then(result => setCollections(result.Items))
.catch(() => setCollections([]));
.catch(() => setCollections([]))
);
}
Promise.all(fetchPromises)
.then(() => {
setIsLoading(false); // Set loading to false when all fetch calls are done
})
.catch((error) => {
console.error('An error occurred while fetching data:', error);
setIsLoading(false); // Set loading to false even if an error occurs
});
}, [collectionType, fetchArtists, fetchItems, fetchPeople, query, serverId]);
const allEmpty = [movies, shows, episodes, videos, programs, channels, playlists, artists, albums, songs, photoAlbums, photos, audioBooks, books, people, collections].every(arr => arr.length === 0);
return (
<div
className={classNames(
@ -216,6 +240,10 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({ serverId = windo
{ 'hide': !query || collectionType === 'livetv' }
)}
>
{isLoading ? (
<div>Loading...</div> // Replace this with your preferred progress indicator
) : (
<>
<SearchResultsRow
title={globalize.translate('Movies')}
items={movies}
@ -303,6 +331,13 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({ serverId = windo
items={people}
cardOptions={{ coverImage: true }}
/>
{allEmpty && !isLoading && (
<div>Sorry, nothing&apos;s here :/</div>
)}
</>
)}
</div>
);
};