1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #3433 from dmitrylyzo/types-react

[TypeScript] Disable implicit any
This commit is contained in:
Bill Thornton 2022-02-25 15:17:32 -05:00 committed by GitHub
commit bb46b32402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 883 additions and 254 deletions

View file

@ -31,20 +31,20 @@ const createInputElement = () => ({
const normalizeInput = (value = '') => value.trim();
type SearchFieldsProps = {
onSearch?: () => void
onSearch?: (query: string) => void
};
// eslint-disable-next-line @typescript-eslint/no-empty-function
const SearchFields: FunctionComponent<SearchFieldsProps> = ({ onSearch = () => {} }: SearchFieldsProps) => {
const element = useRef(null);
const element = useRef<HTMLDivElement>(null);
const getSearchInput = () => element?.current?.querySelector('.searchfields-txtSearch');
const getSearchInput = () => element?.current?.querySelector<HTMLInputElement>('.searchfields-txtSearch');
const debouncedOnSearch = useMemo(() => debounce(onSearch, 400), [onSearch]);
useEffect(() => {
getSearchInput()?.addEventListener('input', e => {
debouncedOnSearch(normalizeInput(e.target?.value));
debouncedOnSearch(normalizeInput((e.target as HTMLInputElement).value));
});
getSearchInput()?.focus();
@ -53,10 +53,15 @@ const SearchFields: FunctionComponent<SearchFieldsProps> = ({ onSearch = () => {
};
}, [debouncedOnSearch]);
const onAlphaPicked = e => {
const value = e.detail.value;
const onAlphaPicked = (e: Event) => {
const value = (e as CustomEvent).detail.value;
const searchInput = getSearchInput();
if (!searchInput) {
console.error('Unexpected null reference');
return;
}
if (value === 'backspace') {
const currentValue = searchInput.value;
searchInput.value = currentValue.length ? currentValue.substring(0, currentValue.length - 1) : '';