From 181e5e41b8b32c7e51459e1246c7e1365dedea4d Mon Sep 17 00:00:00 2001 From: Harshith Mohan Date: Wed, 22 May 2024 16:02:06 +0530 Subject: [PATCH 01/28] Refactor `SelectEpisodeList` to remove deprecations (#910) --- src/components/Input/SelectEpisodeList.tsx | 238 +++++++----------- .../UnrecognizedUtilityTabs/LinkFilesTab.tsx | 3 +- 2 files changed, 86 insertions(+), 155 deletions(-) diff --git a/src/components/Input/SelectEpisodeList.tsx b/src/components/Input/SelectEpisodeList.tsx index ada90a3f1..1378ba8b2 100644 --- a/src/components/Input/SelectEpisodeList.tsx +++ b/src/components/Input/SelectEpisodeList.tsx @@ -1,6 +1,5 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react'; -import ReactDOM from 'react-dom'; -import { Listbox } from '@headlessui/react'; +import React, { useEffect, useState } from 'react'; +import { Listbox, ListboxButton, ListboxOption, ListboxOptions, Transition } from '@headlessui/react'; import { mdiChevronDown, mdiChevronUp, mdiMagnify } from '@mdi/js'; import { Icon } from '@mdi/react'; import cx from 'classnames'; @@ -8,37 +7,10 @@ import { find, toInteger } from 'lodash'; import { EpisodeTypeEnum } from '@/core/types/api/episode'; import getEpisodePrefix from '@/core/utilities/getEpisodePrefix'; +import useEventCallback from '@/hooks/useEventCallback'; import Input from './Input'; -function getOffsetTop(rect: DOMRect, vertical: string | number) { - let offset = 0; - - if (typeof vertical === 'number') { - offset = vertical; - } else if (vertical === 'center') { - offset = rect.height / 2; - } else if (vertical === 'bottom') { - offset = rect.height; - } - - return offset; -} - -function getOffsetLeft(rect: DOMRect, horizontal: string | number) { - let offset = 0; - - if (typeof horizontal === 'number') { - offset = horizontal; - } else if (horizontal === 'center') { - offset = rect.width / 2; - } else if (horizontal === 'right') { - offset = rect.width; - } - - return offset; -} - type Option = { label: string; value: number; @@ -50,159 +22,119 @@ type Option = { type Props = { options: Option[]; value: number; - onChange: (optionValue: number, label: string) => void; - className?: string; - emptyValue?: string; + onChange: (optionValue: number) => void; disabled?: boolean; rowIdx: number; }; -const SelectOption = (option: Option & { divider: boolean }) => ( - ( +
- +
{getEpisodePrefix(option.type) + option.number}
|
{option.label}
- - {option.AirDate} +
+
{option.AirDate}
-
+ +); + +const SelectButton = ({ open, rowIdx, selected }: { open: boolean, rowIdx: number, selected: Option }) => ( + +
+ {!selected?.label ? 'Select episode' : ( + <> + {selected.number} +  -  + {selected.label} + {selected?.type !== EpisodeTypeEnum.Normal && ( + + {selected.type} + + )} + + )} +
+
+ +
+
); const SelectEpisodeList = React.memo(( - { className, disabled = false, emptyValue = '', onChange, options, rowIdx, value }: Props, + { disabled = false, onChange, options, rowIdx, value }: Props, ) => { const [epFilter, setEpFilter] = useState(0); const [selected, setSelected] = useState