-
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.
- Loading branch information
1 parent
8975649
commit 5982c9a
Showing
25 changed files
with
388 additions
and
342 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
; This is a basic Blender demo | ||
defaultConfigSource = gnnuzabk | ||
defaultConfigSource = ehon8mco | ||
; When developing, switching between configs is useful for test and debug | ||
UNSAFE_allowAnyConfigSource = true |
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 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,39 @@ | ||
import { UseQueryResult, useQuery } from 'react-query'; | ||
|
||
import { getSeriesByMediaIds } from '#src/services/api.service'; | ||
import type { ApiError } from '#src/utils/api'; | ||
import type { Series, EpisodeMetadata } from '#types/series'; | ||
import type { PlaylistItem } from '#types/playlist'; | ||
|
||
// Get `episodeNumber` and `seasonNumber` for the new series flow | ||
export const useEpisodeMetadata = ( | ||
episode: PlaylistItem, | ||
series: Series | undefined, | ||
options: { enabled: boolean }, | ||
): { isLoading: boolean; data: EpisodeMetadata | undefined } => { | ||
const oldFlowMetadata = { episodeNumber: episode?.episodeNumber || '0', seasonNumber: episode?.seasonNumber || '0' }; | ||
|
||
const { isLoading, data }: UseQueryResult<EpisodeMetadata | undefined, ApiError | null> = useQuery( | ||
['episodeId', episode.mediaid], | ||
async () => { | ||
if (!episode.mediaid) { | ||
throw Error('No episode id provided'); | ||
} | ||
|
||
const seriesDictionary = await getSeriesByMediaIds([episode.mediaid]); | ||
// Get an item details of the associated series (we need its episode and season) | ||
const { season_number, episode_number } = (seriesDictionary?.[episode.mediaid] || []).find((el) => el.series_id === series?.series_id) || {}; | ||
// Add seriesId to work with watch history | ||
return { episodeNumber: String(episode_number || 0), seasonNumber: String(season_number || 0), seriesId: series?.series_id }; | ||
}, | ||
{ | ||
// Only enable this query when having new series flow | ||
enabled: options.enabled, | ||
}, | ||
); | ||
|
||
return { | ||
isLoading, | ||
data: isLoading || !options.enabled ? data : series ? data : oldFlowMetadata, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,95 +1,64 @@ | ||
import { UseInfiniteQueryResult, useInfiniteQuery } from 'react-query'; | ||
import { useInfiniteQuery } from 'react-query'; | ||
|
||
import { getEpisodes, getSeasonWithEpisodes } from '#src/services/api.service'; | ||
import type { EpisodesWithPagination } from '#types/series'; | ||
import type { ApiError } from '#src/utils/api'; | ||
import type { Pagination } from '#types/pagination'; | ||
|
||
// 1 hour | ||
const CACHE_TIME = 60 * 1000 * 60; | ||
|
||
// Get episodes from a selected series using pagination | ||
export const useSeriesEpisodes = (seriesId: string | undefined, isNewSeriesFlow: boolean): UseInfiniteQueryResult<EpisodesWithPagination, ApiError | null> => { | ||
return useInfiniteQuery( | ||
[seriesId, 'episodes'], | ||
async ({ pageParam = 0 }) => { | ||
const episodes = await getEpisodes(seriesId || '', pageParam); | ||
|
||
return episodes; | ||
}, | ||
{ | ||
getNextPageParam: (lastPage) => { | ||
const { page, page_limit, total } = lastPage.pagination; | ||
const getNextPageParam = (pagination: Pagination) => { | ||
const { page, page_limit, total } = pagination; | ||
|
||
// In case there are no more episodes in a season to fetch | ||
if (page_limit * page >= total) { | ||
return undefined; | ||
} | ||
// In case there are no more episodes in a season to fetch | ||
if (page_limit * page >= total) { | ||
return undefined; | ||
} | ||
|
||
return page; | ||
}, | ||
enabled: isNewSeriesFlow, | ||
// 1 hour | ||
staleTime: CACHE_TIME, | ||
cacheTime: CACHE_TIME, | ||
}, | ||
); | ||
return page; | ||
}; | ||
|
||
// Get episodes from a selected season using pagination | ||
const useSeasonEpisodes = ( | ||
isNewSeriesFlow: boolean, | ||
export const useEpisodes = ( | ||
seriesId: string | undefined, | ||
seasonNumber: number, | ||
): UseInfiniteQueryResult<EpisodesWithPagination, ApiError | null> => { | ||
return useInfiniteQuery( | ||
[seriesId, 'season', seasonNumber], | ||
seasonNumber: string | undefined, | ||
options: { enabled: boolean }, | ||
): { | ||
data: EpisodesWithPagination[]; | ||
hasNextPage: boolean; | ||
fetchNextPage: (params?: { pageParam?: number }) => void; | ||
isLoading: boolean; | ||
} => { | ||
const { | ||
data, | ||
fetchNextPage, | ||
isLoading, | ||
hasNextPage = false, | ||
} = useInfiniteQuery( | ||
[seriesId, seasonNumber], | ||
async ({ pageParam = 0 }) => { | ||
const season = await getSeasonWithEpisodes(seriesId || '', seasonNumber, pageParam); | ||
if (Number(seasonNumber)) { | ||
// Get episodes from a selected season using pagination | ||
const season = await getSeasonWithEpisodes(seriesId || '', Number(seasonNumber), pageParam); | ||
|
||
return { pagination: season.pagination, episodes: season.episodes }; | ||
return { pagination: season.pagination, episodes: season.episodes }; | ||
} else { | ||
// Get episodes from a selected series using pagination | ||
const data = await getEpisodes(seriesId || '', pageParam); | ||
return data; | ||
} | ||
}, | ||
{ | ||
getNextPageParam: (lastPage) => { | ||
const { page, page_limit, total } = lastPage.pagination; | ||
|
||
// In case there are no more episodes in a season to fetch | ||
if (page_limit * page >= total) { | ||
return undefined; | ||
} | ||
|
||
return page; | ||
}, | ||
enabled: isNewSeriesFlow, | ||
// 1 hour | ||
getNextPageParam: (lastPage) => getNextPageParam(lastPage?.pagination), | ||
enabled: options.enabled, | ||
staleTime: CACHE_TIME, | ||
cacheTime: CACHE_TIME, | ||
}, | ||
); | ||
}; | ||
|
||
export const useEpisodes = ( | ||
seriesId: string | undefined, | ||
isNewSeriesFlow: boolean, | ||
filter: string | undefined, | ||
): { data: EpisodesWithPagination[]; hasNextPage: boolean; fetchNextPage: () => void } => { | ||
const { | ||
data: episodesData, | ||
fetchNextPage: fetchNextSeriesEpisodes, | ||
hasNextPage: hasNextEpisodesPage = false, | ||
} = useSeriesEpisodes(seriesId, isNewSeriesFlow && !filter); | ||
|
||
const { | ||
data: seasonEpisodesData, | ||
fetchNextPage: fetchNextSeasonEpisodes, | ||
hasNextPage: hasNextSeasonEpisodesPage = false, | ||
} = useSeasonEpisodes(isNewSeriesFlow && !!filter, seriesId, Number(filter)); | ||
|
||
if (!filter) { | ||
return { data: episodesData?.pages || [], fetchNextPage: fetchNextSeriesEpisodes, hasNextPage: hasNextEpisodesPage }; | ||
} | ||
|
||
return { | ||
data: seasonEpisodesData?.pages || [], | ||
fetchNextPage: fetchNextSeasonEpisodes, | ||
hasNextPage: hasNextSeasonEpisodesPage, | ||
data: data?.pages || [], | ||
isLoading, | ||
fetchNextPage, | ||
hasNextPage, | ||
}; | ||
}; |
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,28 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import type { Playlist, PlaylistItem } from '#types/playlist'; | ||
import type { EpisodeMetadata, Series } from '#types/series'; | ||
import { getNextItem } from '#src/utils/series'; | ||
|
||
export const useNextEpisode = ({ | ||
episode, | ||
seriesPlaylist, | ||
series, | ||
episodeMetadata, | ||
}: { | ||
episode: PlaylistItem | undefined; | ||
seriesPlaylist: Playlist; | ||
series: Series | undefined; | ||
episodeMetadata: EpisodeMetadata | undefined; | ||
}) => { | ||
const [nextItem, setNextItem] = useState<PlaylistItem | undefined>(undefined); | ||
useEffect(() => { | ||
async function fetchData() { | ||
const item = await getNextItem(episode, seriesPlaylist, series, episodeMetadata); | ||
setNextItem(item); | ||
} | ||
fetchData(); | ||
}, [episode, seriesPlaylist, series, episodeMetadata]); | ||
|
||
return nextItem; | ||
}; |
Oops, something went wrong.