2021-08-13 16:10:05 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2021-08-13 16:10:05 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
import Icon from '../../../base/icons/components/Icon';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { IconSearch } from '../../../base/icons/svg';
|
2022-10-19 08:42:54 +00:00
|
|
|
import { getFieldValue } from '../../../base/react/functions';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { withPixelLineHeight } from '../../../base/styles/functions.web';
|
2021-12-28 14:35:21 +00:00
|
|
|
import { MOBILE_BREAKPOINT } from '../../constants';
|
2021-11-10 17:49:53 +00:00
|
|
|
import { isSpeakerStatsSearchDisabled } from '../../functions';
|
2021-08-13 16:10:05 +00:00
|
|
|
|
2022-11-15 07:50:22 +00:00
|
|
|
const useStyles = makeStyles()(theme => {
|
2021-08-13 16:10:05 +00:00
|
|
|
return {
|
2021-12-28 14:35:21 +00:00
|
|
|
speakerStatsSearchContainer: {
|
|
|
|
position: 'relative'
|
|
|
|
},
|
|
|
|
searchIcon: {
|
|
|
|
display: 'none',
|
|
|
|
[theme.breakpoints.down(MOBILE_BREAKPOINT)]: {
|
|
|
|
display: 'block',
|
|
|
|
position: 'absolute',
|
|
|
|
color: theme.palette.text03,
|
|
|
|
left: 16,
|
|
|
|
top: 13,
|
|
|
|
width: 20,
|
|
|
|
height: 20
|
|
|
|
}
|
|
|
|
},
|
2021-08-13 16:10:05 +00:00
|
|
|
speakerStatsSearch: {
|
2021-12-28 14:35:21 +00:00
|
|
|
backgroundColor: theme.palette.field01,
|
|
|
|
border: '1px solid',
|
|
|
|
borderRadius: 6,
|
2022-07-12 12:28:20 +00:00
|
|
|
borderColor: theme.palette.ui05,
|
2021-12-28 14:35:21 +00:00
|
|
|
color: theme.palette.text01,
|
|
|
|
padding: '10px 16px',
|
|
|
|
width: '100%',
|
|
|
|
height: 40,
|
|
|
|
'&::placeholder': {
|
|
|
|
color: theme.palette.text03,
|
2022-09-13 07:36:00 +00:00
|
|
|
...withPixelLineHeight(theme.typography.bodyShortRegular)
|
2021-12-28 14:35:21 +00:00
|
|
|
},
|
|
|
|
[theme.breakpoints.down(MOBILE_BREAKPOINT)]: {
|
|
|
|
height: 48,
|
|
|
|
padding: '13px 16px 13px 44px',
|
|
|
|
'&::placeholder': {
|
2022-09-13 07:36:00 +00:00
|
|
|
...withPixelLineHeight(theme.typography.bodyShortRegular)
|
2021-12-28 14:35:21 +00:00
|
|
|
}
|
2021-11-17 07:46:12 +00:00
|
|
|
}
|
2021-08-13 16:10:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link SpeakerStatsSearch}.
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
interface IProps {
|
2021-08-13 16:10:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The function to initiate the change in the speaker stats table.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onSearch: Function;
|
2021-08-13 16:10:05 +00:00
|
|
|
|
2022-11-03 08:35:51 +00:00
|
|
|
}
|
2021-08-13 16:10:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* React component for display an individual user's speaker stats.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2022-11-03 08:35:51 +00:00
|
|
|
function SpeakerStatsSearch({ onSearch }: IProps) {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes, theme } = useStyles();
|
2021-08-13 16:10:05 +00:00
|
|
|
const { t } = useTranslation();
|
2021-12-28 14:35:21 +00:00
|
|
|
const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
|
2021-08-13 16:10:05 +00:00
|
|
|
const [ searchValue, setSearchValue ] = useState<string>('');
|
2021-12-28 14:35:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for the onChange event of the field.
|
|
|
|
*
|
|
|
|
* @param {Object} evt - The static event.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
const onChange = useCallback((evt: React.ChangeEvent<HTMLInputElement>) => {
|
2021-08-13 16:10:05 +00:00
|
|
|
const value = getFieldValue(evt);
|
|
|
|
|
|
|
|
setSearchValue(value);
|
2022-09-08 09:52:36 +00:00
|
|
|
onSearch?.(value);
|
2021-08-13 16:10:05 +00:00
|
|
|
}, []);
|
2022-08-25 11:35:19 +00:00
|
|
|
const preventDismiss = useCallback((evt: React.KeyboardEvent) => {
|
2021-12-13 14:11:07 +00:00
|
|
|
if (evt.key === 'Enter') {
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
}, []);
|
2021-08-13 16:10:05 +00:00
|
|
|
|
|
|
|
if (disableSpeakerStatsSearch) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-12-28 14:35:21 +00:00
|
|
|
<div className = { classes.speakerStatsSearchContainer }>
|
|
|
|
<Icon
|
|
|
|
className = { classes.searchIcon }
|
2022-09-13 07:36:00 +00:00
|
|
|
color = { theme.palette.icon03 }
|
2021-12-28 14:35:21 +00:00
|
|
|
src = { IconSearch } />
|
|
|
|
<input
|
2021-08-13 16:10:05 +00:00
|
|
|
autoComplete = 'off'
|
|
|
|
autoFocus = { false }
|
2021-12-28 14:35:21 +00:00
|
|
|
className = { classes.speakerStatsSearch }
|
|
|
|
id = 'speaker-stats-search'
|
2021-08-13 16:10:05 +00:00
|
|
|
name = 'speakerStatsSearch'
|
|
|
|
onChange = { onChange }
|
2021-12-13 14:11:07 +00:00
|
|
|
onKeyPress = { preventDismiss }
|
2021-08-13 16:10:05 +00:00
|
|
|
placeholder = { t('speakerStats.search') }
|
2021-12-28 14:35:21 +00:00
|
|
|
tabIndex = { 0 }
|
2021-08-13 16:10:05 +00:00
|
|
|
value = { searchValue } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SpeakerStatsSearch;
|