Skip to content

Commit

Permalink
Merge pull request #541 from DmytroAlipov/fix-discussion-search-palm
Browse files Browse the repository at this point in the history
Fix bug with a repeated search query  for Palm
  • Loading branch information
edx-requirements-bot authored Jul 12, 2023
2 parents 5ca61b9 + dcb0f9e commit 4a1e77b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/Search.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import React, { useContext, useEffect, useState } from 'react';

import camelCase from 'lodash/camelCase';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -14,6 +14,7 @@ import postsMessages from '../discussions/posts/post-actions-bar/messages';
import { setFilter as setTopicFilter } from '../discussions/topics/data/slices';

const Search = ({ intl }) => {
const [previousSearchValue, setPreviousSearchValue] = useState('');
const dispatch = useDispatch();
const { page } = useContext(DiscussionContext);
const postSearch = useSelector(({ threads }) => threads.filters.search);
Expand All @@ -35,14 +36,15 @@ const Search = ({ intl }) => {
dispatch(setSearchQuery(''));
dispatch(setTopicFilter(''));
dispatch(setUsernameSearch(''));
setPreviousSearchValue('');
};

const onChange = (query) => {
searchValue = query;
};

const onSubmit = (query) => {
if (query === '') {
if (query === '' || query === previousSearchValue) {
return;
}
if (isPostSearch) {
Expand All @@ -52,6 +54,7 @@ const Search = ({ intl }) => {
} else if (page === 'learners') {
dispatch(setUsernameSearch(query));
}
setPreviousSearchValue(query);
};

useEffect(() => onClear(), [page]);
Expand Down

0 comments on commit 4a1e77b

Please sign in to comment.