-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- we still support old approach with series as media items - new Switcher component added to check whether new api can be used - SeriesNew component now uses new api to show series - dev host content-portal added to test demo features - dev config added for dev-api - fixed player bahaviour to automatically play next series episode if needed - docs updates - (!) we use features.favoritesList to get media items (temporary)
- Loading branch information
“Anton
committed
Jun 30, 2022
1 parent
606dab4
commit 29e8599
Showing
20 changed files
with
653 additions
and
96 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import type { RouteComponentProps } from 'react-router-dom'; | ||
|
||
import { useSeriesData } from '#src/hooks/useSeries'; | ||
import Series from '#src/screens/Series/Series'; | ||
import SeriesNew from '#src/screens/SeriesNew/SeriesNew'; | ||
import LoadingOverlay from '#src/components/LoadingOverlay/LoadingOverlay'; | ||
|
||
type Params = { | ||
id: string; | ||
}; | ||
|
||
const SeriesSwitcher = (params: RouteComponentProps<Params>): JSX.Element => { | ||
const seriesId = params.match.params.id; | ||
|
||
const { isLoading, isFetching, error } = useSeriesData(seriesId); | ||
|
||
if (isLoading || isFetching) return <LoadingOverlay />; | ||
|
||
// In case we have not found series using id, we assume it is a v2.0 seriesId | ||
if (error?.code === 404) return <Series {...params} />; | ||
|
||
return <SeriesNew {...params} />; | ||
}; | ||
|
||
export default SeriesSwitcher; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useQuery, UseQueryResult } from 'react-query'; | ||
|
||
import { getSeries } from '#src/services/series.service'; | ||
import { getMediaByWatchlist } from '#src/services/api.service'; | ||
import { enrichMediaItems } from '#src/utils/series'; | ||
import type { Season, Series } from '#types/series'; | ||
import type { PlaylistItem } from '#types/playlist'; | ||
import type { ApiError } from '#src/utils/api'; | ||
|
||
export const useSeriesData = (id: string, season?: number): UseQueryResult<Series | undefined, ApiError> => | ||
useQuery(`series-${id}`, async () => getSeries(id, { season }), { | ||
staleTime: Infinity, | ||
retry: 0, | ||
}); | ||
|
||
export const useSeriesMediaItems = ( | ||
seriesId: string, | ||
watchlistId: string | null | undefined, | ||
): UseQueryResult<{ mediaItems: PlaylistItem[]; series: Series }, ApiError> => | ||
useQuery( | ||
`series-watchlist-${seriesId}`, | ||
async () => { | ||
if (!watchlistId) { | ||
throw Error('Please set features.favoritesList property'); | ||
} | ||
|
||
const series = await getSeries(seriesId); | ||
const mediaIds = (series?.seasons || []).reduce((acc: string[], season: Season) => { | ||
const ids = season.episodes.map((el) => el.media_id); | ||
return [...acc, ...ids]; | ||
}, []); | ||
|
||
const mediaItems = await getMediaByWatchlist(watchlistId, mediaIds); | ||
|
||
return { series, mediaItems: enrichMediaItems(series, mediaItems) }; | ||
}, | ||
{ | ||
staleTime: Infinity, | ||
retry: 0, | ||
}, | ||
); |
Oops, something went wrong.