import Button from '@app/components/Common/Button'; import MultiRangeSlider from '@app/components/Common/MultiRangeSlider'; import SlideOver from '@app/components/Common/SlideOver'; import type { FilterOptions } from '@app/components/Discover/constants'; import { countActiveFilters } from '@app/components/Discover/constants'; import LanguageSelector from '@app/components/LanguageSelector'; import { CompanySelector, GenreSelector, KeywordSelector, } from '@app/components/Selector'; import useSettings from '@app/hooks/useSettings'; import { useBatchUpdateQueryParams, useUpdateQueryParams, } from '@app/hooks/useUpdateQueryParams'; import { XCircleIcon } from '@heroicons/react/24/outline'; import { defineMessages, useIntl } from 'react-intl'; import Datepicker from 'react-tailwindcss-datepicker-sct'; const messages = defineMessages({ filters: 'Filters', activefilters: '{count, plural, one {# Active Filter} other {# Active Filters}}', releaseDate: 'Release Date', firstAirDate: 'First Air Date', from: 'From', to: 'To', studio: 'Studio', genres: 'Genres', keywords: 'Keywords', originalLanguage: 'Original Language', runtimeText: '{minValue}-{maxValue} minute runtime', ratingText: 'Ratings between {minValue} and {maxValue}', clearfilters: 'Clear Active Filters', tmdbuserscore: 'TMDB User Score', runtime: 'Runtime', }); type FilterSlideoverProps = { show: boolean; onClose: () => void; type: 'movie' | 'tv'; currentFilters: FilterOptions; }; const FilterSlideover = ({ show, onClose, type, currentFilters, }: FilterSlideoverProps) => { const intl = useIntl(); const { currentSettings } = useSettings(); const updateQueryParams = useUpdateQueryParams({}); const batchUpdateQueryParams = useBatchUpdateQueryParams({}); const dateGte = type === 'movie' ? 'primaryReleaseDateGte' : 'firstAirDateGte'; const dateLte = type === 'movie' ? 'primaryReleaseDateLte' : 'firstAirDateLte'; return ( onClose()} >
{intl.formatMessage( type === 'movie' ? messages.releaseDate : messages.firstAirDate )}
{intl.formatMessage(messages.from)}
{ updateQueryParams( dateGte, value?.startDate ? (value.startDate as string) : undefined ); }} inputName="fromdate" useRange={false} asSingle containerClassName="datepicker-wrapper" inputClassName="pr-1 sm:pr-4" />
{intl.formatMessage(messages.to)}
{ updateQueryParams( dateLte, value?.startDate ? (value.startDate as string) : undefined ); }} inputName="todate" useRange={false} asSingle containerClassName="datepicker-wrapper" inputClassName="pr-1 sm:pr-4" />
{type === 'movie' && ( <> {intl.formatMessage(messages.studio)} { updateQueryParams('studio', value?.value.toString()); }} /> )} {intl.formatMessage(messages.genres)} { updateQueryParams('genre', value?.map((v) => v.value).join(',')); }} /> {intl.formatMessage(messages.keywords)} { updateQueryParams('keywords', value?.map((v) => v.value).join(',')); }} /> {intl.formatMessage(messages.originalLanguage)} { updateQueryParams('language', value); }} /> {intl.formatMessage(messages.runtime)}
{ updateQueryParams( 'withRuntimeGte', min !== 0 && Number(currentFilters.withRuntimeLte) !== 400 ? min.toString() : undefined ); }} onUpdateMax={(max) => { updateQueryParams( 'withRuntimeLte', max !== 400 && Number(currentFilters.withRuntimeGte) !== 0 ? max.toString() : undefined ); }} defaultMaxValue={ currentFilters.withRuntimeLte ? Number(currentFilters.withRuntimeLte) : undefined } defaultMinValue={ currentFilters.withRuntimeGte ? Number(currentFilters.withRuntimeGte) : undefined } subText={intl.formatMessage(messages.runtimeText, { minValue: currentFilters.withRuntimeGte ?? 0, maxValue: currentFilters.withRuntimeLte ?? 400, })} />
{intl.formatMessage(messages.tmdbuserscore)}
{ updateQueryParams( 'voteAverageGte', min !== 1 && Number(currentFilters.voteAverageLte) !== 10 ? min.toString() : undefined ); }} onUpdateMax={(max) => { updateQueryParams( 'voteAverageLte', max !== 10 && Number(currentFilters.voteAverageGte) !== 1 ? max.toString() : undefined ); }} subText={intl.formatMessage(messages.ratingText, { minValue: currentFilters.voteAverageGte ?? 1, maxValue: currentFilters.voteAverageLte ?? 10, })} />
); }; export default FilterSlideover;