diff --git a/server/constants/discover.ts b/server/constants/discover.ts index a19f07422e..fda0682243 100644 --- a/server/constants/discover.ts +++ b/server/constants/discover.ts @@ -20,6 +20,8 @@ export enum DiscoverSliderType { TMDB_SEARCH, TMDB_STUDIO, TMDB_NETWORK, + TMDB_MOVIE_STREAMING_SERVICES, + TMDB_TV_STREAMING_SERVICES, } export const defaultSliders: Partial[] = [ diff --git a/src/components/Discover/CreateSlider/index.tsx b/src/components/Discover/CreateSlider/index.tsx index 24b9d3fdc2..40d26fff36 100644 --- a/src/components/Discover/CreateSlider/index.tsx +++ b/src/components/Discover/CreateSlider/index.tsx @@ -2,6 +2,7 @@ import Button from '@app/components/Common/Button'; import Tooltip from '@app/components/Common/Tooltip'; import { sliderTitles } from '@app/components/Discover/constants'; import MediaSlider from '@app/components/MediaSlider'; +import { WatchProviderSelector } from '@app/components/Selector'; import { encodeURIExtraParams } from '@app/hooks/useDiscover'; import type { TmdbCompanySearchResponse, @@ -55,7 +56,7 @@ type CreateOption = { dataUrl: string; params?: string; titlePlaceholderText: string; - dataPlaceholderText: string; + dataPlaceholderText?: string; }; const CreateSlider = ({ onCreate, slider }: CreateSliderProps) => { @@ -276,6 +277,20 @@ const CreateSlider = ({ onCreate, slider }: CreateSliderProps) => { titlePlaceholderText: intl.formatMessage(messages.slidernameplaceholder), dataPlaceholderText: intl.formatMessage(messages.providetmdbsearch), }, + { + type: DiscoverSliderType.TMDB_MOVIE_STREAMING_SERVICES, + title: intl.formatMessage(sliderTitles.tmdbmoviestreamingservices), + dataUrl: '/api/v1/discover/movies', + params: 'watchRegion=$regionValue&watchProviders=$providersValue', + titlePlaceholderText: intl.formatMessage(messages.slidernameplaceholder), + }, + { + type: DiscoverSliderType.TMDB_TV_STREAMING_SERVICES, + title: intl.formatMessage(sliderTitles.tmdbtvstreamingservices), + dataUrl: '/api/v1/discover/tv', + params: 'watchRegion=$regionValue&watchProviders=$providersValue', + titlePlaceholderText: intl.formatMessage(messages.slidernameplaceholder), + }, ]; return ( @@ -417,6 +432,40 @@ const CreateSlider = ({ onCreate, slider }: CreateSliderProps) => { /> ); break; + case DiscoverSliderType.TMDB_MOVIE_STREAMING_SERVICES: + dataInput = ( + Number(v)) ?? [] + } + onChange={(region, providers) => { + setFieldValue('data', `${region},${providers.join('|')}`); + }} + /> + ); + break; + case DiscoverSliderType.TMDB_TV_STREAMING_SERVICES: + dataInput = ( + Number(v)) ?? [] + } + onChange={(region, providers) => { + setFieldValue('data', `${region},${providers.join('|')}`); + }} + /> + ); + break; default: dataInput = ( { '$value', encodeURIExtraParams(values.data) )} - extraParams={activeOption.params?.replace( - '$value', - encodeURIExtraParams(values.data) - )} + extraParams={ + activeOption.type === + DiscoverSliderType.TMDB_MOVIE_STREAMING_SERVICES || + activeOption.type === + DiscoverSliderType.TMDB_TV_STREAMING_SERVICES + ? activeOption.params + ?.replace( + '$regionValue', + encodeURIExtraParams(values?.data.split(',')[0]) + ) + .replace( + '$providersValue', + encodeURIExtraParams(values?.data.split(',')[1]) + ) + : activeOption.params?.replace( + '$value', + encodeURIExtraParams(values.data) + ) + } onNewTitles={updateResultCount} /> diff --git a/src/components/Discover/DiscoverSliderEdit/index.tsx b/src/components/Discover/DiscoverSliderEdit/index.tsx index 970a9887a6..9a0f3aa76c 100644 --- a/src/components/Discover/DiscoverSliderEdit/index.tsx +++ b/src/components/Discover/DiscoverSliderEdit/index.tsx @@ -164,6 +164,10 @@ const DiscoverSliderEdit = ({ return intl.formatMessage(sliderTitles.tmdbnetwork); case DiscoverSliderType.TMDB_SEARCH: return intl.formatMessage(sliderTitles.tmdbsearch); + case DiscoverSliderType.TMDB_MOVIE_STREAMING_SERVICES: + return intl.formatMessage(sliderTitles.tmdbmoviestreamingservices); + case DiscoverSliderType.TMDB_TV_STREAMING_SERVICES: + return intl.formatMessage(sliderTitles.tmdbtvstreamingservices); default: return 'Unknown Slider'; } @@ -195,7 +199,9 @@ const DiscoverSliderEdit = ({ className={`${slider.data ? 'mb-4' : 'mb-0'} flex space-x-2 md:mb-0`} > -
{getSliderTitle(slider)}
+
+ {getSliderTitle(slider)} +
{ /> ); break; + case DiscoverSliderType.TMDB_MOVIE_STREAMING_SERVICES: + sliderComponent = ( + + ); + break; + case DiscoverSliderType.TMDB_TV_STREAMING_SERVICES: + sliderComponent = ( + + ); + break; } if (isEditing) { diff --git a/src/components/Selector/index.tsx b/src/components/Selector/index.tsx index 3b863fd72c..8a21d3fbea 100644 --- a/src/components/Selector/index.tsx +++ b/src/components/Selector/index.tsx @@ -305,7 +305,9 @@ export const WatchProviderSelector = ({ useEffect(() => { onChange(watchRegion, activeProvider); - }, [activeProvider, watchRegion, onChange]); + // removed onChange as a dependency as we only need to call it when the value(s) change + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [activeProvider, watchRegion]); const orderedData = useMemo(() => { if (!data) { @@ -344,7 +346,7 @@ export const WatchProviderSelector = ({ ) : (
-
+
{initialProviders.map((provider) => { const isActive = activeProvider.includes(provider.id); return ( @@ -353,7 +355,7 @@ export const WatchProviderSelector = ({ key={`prodiver-${provider.id}`} >
{showMore && otherProviders.length > 0 && ( -
+
{otherProviders.map((provider) => { const isActive = activeProvider.includes(provider.id); return ( @@ -395,7 +397,7 @@ export const WatchProviderSelector = ({ key={`prodiver-${provider.id}`} >