2024-06-01 18:42:01 -04:00
|
|
|
import React, { type ChangeEvent, type FC, useCallback, useRef } from 'react';
|
2025-02-27 15:53:20 +03:00
|
|
|
import AlphaPicker from '../../../../../components/alphaPicker/AlphaPickerComponent';
|
2024-02-13 01:09:08 -05:00
|
|
|
import Input from 'elements/emby-input/Input';
|
2025-02-27 15:53:20 +03:00
|
|
|
import globalize from '../../../../../lib/globalize';
|
|
|
|
import layoutManager from '../../../../../components/layoutManager';
|
|
|
|
import browser from '../../../../../scripts/browser';
|
2021-06-01 15:15:51 -04:00
|
|
|
import 'material-design-icons-iconfont';
|
2025-02-27 15:53:20 +03:00
|
|
|
import 'styles/flexstyles.scss';
|
2021-06-01 15:15:51 -04:00
|
|
|
import './searchfields.scss';
|
2021-05-28 15:58:41 -04:00
|
|
|
|
2024-06-11 00:23:57 +03:00
|
|
|
interface SearchFieldsProps {
|
2023-10-19 10:22:34 -07:00
|
|
|
query: string,
|
2022-02-15 23:45:52 +03:00
|
|
|
onSearch?: (query: string) => void
|
2024-06-11 00:23:57 +03:00
|
|
|
}
|
2021-06-11 14:49:57 +02:00
|
|
|
|
2024-02-13 01:09:08 -05:00
|
|
|
const SearchFields: FC<SearchFieldsProps> = ({
|
|
|
|
onSearch = () => { /* no-op */ },
|
|
|
|
query
|
2024-06-11 00:23:57 +03:00
|
|
|
}) => {
|
2024-06-01 18:42:01 -04:00
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
2022-12-16 16:02:11 -05:00
|
|
|
const onAlphaPicked = useCallback((e: Event) => {
|
2022-02-18 14:27:39 +03:00
|
|
|
const value = (e as CustomEvent).detail.value;
|
2024-06-01 18:42:01 -04:00
|
|
|
const inputValue = inputRef.current?.value || '';
|
2022-02-16 21:52:06 +03:00
|
|
|
|
2021-06-01 15:15:51 -04:00
|
|
|
if (value === 'backspace') {
|
2024-07-15 22:15:52 +03:00
|
|
|
onSearch(inputValue.length ? inputValue.substring(0, inputValue.length - 1) : '');
|
2021-06-01 15:15:51 -04:00
|
|
|
} else {
|
2024-06-01 18:42:01 -04:00
|
|
|
onSearch(inputValue + value);
|
2021-05-28 15:58:41 -04:00
|
|
|
}
|
2024-06-01 18:42:01 -04:00
|
|
|
}, [onSearch]);
|
2021-06-01 15:15:51 -04:00
|
|
|
|
2024-02-13 01:09:08 -05:00
|
|
|
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
onSearch(e.target.value);
|
|
|
|
}, [ onSearch ]);
|
2021-05-28 15:58:41 -04:00
|
|
|
|
|
|
|
return (
|
2024-02-13 01:09:08 -05:00
|
|
|
<div className='padded-left padded-right searchFields'>
|
2021-06-01 15:15:51 -04:00
|
|
|
<div className='searchFieldsInner flex align-items-center justify-content-center'>
|
2022-02-24 20:15:24 +03:00
|
|
|
<span className='searchfields-icon material-icons search' aria-hidden='true' />
|
2021-06-01 15:15:51 -04:00
|
|
|
<div
|
|
|
|
className='inputContainer flex-grow'
|
|
|
|
style={{ marginBottom: 0 }}
|
2024-02-13 01:09:08 -05:00
|
|
|
>
|
|
|
|
<Input
|
2024-06-01 18:42:01 -04:00
|
|
|
ref={inputRef}
|
2024-02-13 01:09:08 -05:00
|
|
|
id='searchTextInput'
|
|
|
|
className='searchfields-txtSearch'
|
|
|
|
type='text'
|
|
|
|
data-keyboard='true'
|
|
|
|
placeholder={globalize.translate('Search')}
|
|
|
|
autoComplete='off'
|
|
|
|
maxLength={40}
|
|
|
|
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
|
|
autoFocus
|
|
|
|
value={query}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-06-01 15:15:51 -04:00
|
|
|
</div>
|
2023-03-29 00:38:22 -04:00
|
|
|
{layoutManager.tv && !browser.tv
|
|
|
|
&& <AlphaPicker onAlphaPicked={onAlphaPicked} />
|
2021-06-01 15:15:51 -04:00
|
|
|
}
|
|
|
|
</div>
|
2021-05-28 15:58:41 -04:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-06-01 15:19:02 -04:00
|
|
|
export default SearchFields;
|