Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(speaker-stats): prevent search from closing when enter pressed and from keeping previous state (#10597)

Gabriel Borlea40844afb60b2
diff --git a/react/features/speaker-stats/actionTypes.js b/react/features/speaker-stats/actionTypes.js
index 5d8ce6b57a..f61549bb18 100644
--- a/react/features/speaker-stats/actionTypes.js
+++ b/react/features/speaker-stats/actionTypes.js
@@ -38,3 +38,12 @@ export const UPDATE_STATS = 'UPDATE_STATS';
*/
export const INIT_REORDER_STATS = 'INIT_REORDER_STATS';
+/**
+ * Action type to reset the search criteria.
+ *
+ * {
+ * type: RESET_SEARCH_CRITERIA
+ * }
+ */
+export const RESET_SEARCH_CRITERIA = 'RESET_SEARCH_CRITERIA'
+
diff --git a/react/features/speaker-stats/actions.any.js b/react/features/speaker-stats/actions.any.js
index 956b0ed3a3..a0be70b153 100644
--- a/react/features/speaker-stats/actions.any.js
+++ b/react/features/speaker-stats/actions.any.js
@@ -4,7 +4,8 @@ import {
INIT_SEARCH,
INIT_UPDATE_STATS,
UPDATE_STATS,
- INIT_REORDER_STATS
+ INIT_REORDER_STATS,
+ RESET_SEARCH_CRITERIA
} from './actionTypes';
/**
@@ -56,3 +57,14 @@ export function initReorderStats() {
type: INIT_REORDER_STATS
};
}
+
+/**
+ * Resets the search criteria.
+ *
+ * @returns {Object}
+ */
+export function resetSearchCriteria() {
+ return {
+ type: RESET_SEARCH_CRITERIA
+ };
+}
diff --git a/react/features/speaker-stats/components/web/SpeakerStats.js b/react/features/speaker-stats/components/web/SpeakerStats.js
index 2b195baf8a..c5d78d225f 100644
--- a/react/features/speaker-stats/components/web/SpeakerStats.js
+++ b/react/features/speaker-stats/components/web/SpeakerStats.js
@@ -7,7 +7,7 @@ import { Dialog } from '../../../base/dialog';
import { translate } from '../../../base/i18n';
import { connect } from '../../../base/redux';
import { escapeRegexp } from '../../../base/util';
-import { initSearch } from '../../actions';
+import { initSearch, resetSearchCriteria } from '../../actions';
import SpeakerStatsLabels from './SpeakerStatsLabels';
import SpeakerStatsList from './SpeakerStatsList';
@@ -65,6 +65,16 @@ class SpeakerStats extends Component<Props> {
this._onSearch = this._onSearch.bind(this);
}
+ /**
+ * Resets the search criteria when component will unmount.
+ *
+ * @private
+ * @returns {void}
+ */
+ componentWillUnmount() {
+ this.props.dispatch(resetSearchCriteria());
+ }
+
/**
* Implements React's {@link Component#render()}.
*
diff --git a/react/features/speaker-stats/components/web/SpeakerStatsSearch.js b/react/features/speaker-stats/components/web/SpeakerStatsSearch.js
index 0c2a2a5988..016e014842 100644
--- a/react/features/speaker-stats/components/web/SpeakerStatsSearch.js
+++ b/react/features/speaker-stats/components/web/SpeakerStatsSearch.js
@@ -54,6 +54,11 @@ function SpeakerStatsSearch({ onSearch }: Props) {
onSearch && onSearch(value);
}, []);
const disableSpeakerStatsSearch = useSelector(isSpeakerStatsSearchDisabled);
+ const preventDismiss = useCallback((evt: KeyboardEvent) => {
+ if (evt.key === 'Enter') {
+ evt.preventDefault();
+ }
+ }, []);
if (disableSpeakerStatsSearch) {
return null;
@@ -67,6 +72,7 @@ function SpeakerStatsSearch({ onSearch }: Props) {
compact = { true }
name = 'speakerStatsSearch'
onChange = { onChange }
+ onKeyPress = { preventDismiss }
placeholder = { t('speakerStats.search') }
shouldFitContainer = { false }
type = 'text'
diff --git a/react/features/speaker-stats/reducer.js b/react/features/speaker-stats/reducer.js
index 707cc81f80..fb136ef783 100644
--- a/react/features/speaker-stats/reducer.js
+++ b/react/features/speaker-stats/reducer.js
@@ -7,7 +7,8 @@ import { ReducerRegistry } from '../base/redux';
import {
INIT_SEARCH,
UPDATE_STATS,
- INIT_REORDER_STATS
+ INIT_REORDER_STATS,
+ RESET_SEARCH_CRITERIA
} from './actionTypes';
/**
@@ -30,6 +31,8 @@ ReducerRegistry.register('features/speaker-stats', (state = _getInitialState(),
return _updateStats(state, action);
case INIT_REORDER_STATS:
return _initReorderStats(state);
+ case RESET_SEARCH_CRITERIA:
+ return _updateCriteria(state, { criteria: null });
}
return state;