-
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.
feat(series): reorganizing series hooks
- Loading branch information
1 parent
b46603a
commit 6c7523f
Showing
18 changed files
with
206 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,6 @@ | |
|
||
@include responsive.desktop-only() { | ||
padding-left: 24px; | ||
overflow-y: scroll; | ||
} | ||
} | ||
|
||
|
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
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,18 +1,30 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useQuery } from 'react-query'; | ||
|
||
import type { PlaylistItem } from '#types/playlist'; | ||
import type { EpisodeMetadata, Series } from '#types/series'; | ||
import { getNextItem } from '#src/utils/series'; | ||
import { SERIES_CACHE_TIME } from '#src/config'; | ||
|
||
export const useNextEpisode = ({ series, episodeMetadata }: { series: Series | undefined; episodeMetadata: EpisodeMetadata | undefined }) => { | ||
const [nextItem, setNextItem] = useState<PlaylistItem | undefined>(undefined); | ||
useEffect(() => { | ||
async function fetchData() { | ||
export const useNextEpisode = ({ | ||
series, | ||
episodeMetadata, | ||
episodeId, | ||
}: { | ||
series: Series | undefined; | ||
episodeMetadata: EpisodeMetadata | undefined; | ||
episodeId: string | null; | ||
}) => { | ||
const { isLoading, data } = useQuery( | ||
['next-episode', series?.series_id, episodeId], | ||
async () => { | ||
const item = await getNextItem(series, episodeMetadata); | ||
setNextItem(item); | ||
} | ||
fetchData(); | ||
}, [series, episodeMetadata]); | ||
|
||
return nextItem; | ||
return item; | ||
}, | ||
{ staleTime: SERIES_CACHE_TIME, cacheTime: SERIES_CACHE_TIME }, | ||
); | ||
|
||
return { | ||
isLoading, | ||
data, | ||
}; | ||
}; |
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,34 @@ | ||
import { useQuery, UseQueryResult } from 'react-query'; | ||
|
||
import type { Series } from '#types/series'; | ||
import { getSeries } from '#src/services/api.service'; | ||
import type { ApiError } from '#src/utils/api'; | ||
import { SERIES_CACHE_TIME } from '#src/config'; | ||
|
||
export const useSeries = ( | ||
seriesId: string | undefined, | ||
): { | ||
data: Series | undefined; | ||
error: ApiError | null; | ||
isLoading: boolean; | ||
} => { | ||
// Try to get new series flow data | ||
const { data, isLoading, error }: UseQueryResult<Series, ApiError> = useQuery( | ||
['series', seriesId], | ||
async () => { | ||
const series = await getSeries(seriesId || ''); | ||
|
||
return series; | ||
}, | ||
{ | ||
enabled: !!seriesId, | ||
staleTime: SERIES_CACHE_TIME, | ||
cacheTime: SERIES_CACHE_TIME, | ||
// Don't retry when we got a not found error from either series or media item request (prevent unneeded requests) | ||
// Both errors mean that old series flow should be used | ||
retry: (failureCount, error: ApiError) => error.code !== 404 && failureCount < 2, | ||
}, | ||
); | ||
|
||
return { data, isLoading, error }; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import { getSeriesByMediaIds } from '#src/services/api.service'; | ||
import { SERIES_CACHE_TIME } from '#src/config'; | ||
|
||
export const useSeriesLookup = (mediaId: string | undefined) => { | ||
const { isLoading, data } = useQuery( | ||
['seriesLookup', mediaId], | ||
async () => { | ||
if (!mediaId) { | ||
return; | ||
} | ||
|
||
// get all series for the given media id | ||
const data = await getSeriesByMediaIds([mediaId]); | ||
// get first series for the requested episode | ||
const firstSeries = data?.[mediaId]?.[0]; | ||
|
||
return firstSeries; | ||
}, | ||
// 8 hours | ||
{ staleTime: SERIES_CACHE_TIME, cacheTime: SERIES_CACHE_TIME, enabled: !!mediaId }, | ||
); | ||
|
||
return { | ||
isLoading, | ||
data, | ||
}; | ||
}; |
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
Oops, something went wrong.