Skip to content

Commit

Permalink
fix: linter problems
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Apr 5, 2024
1 parent 8fca777 commit 7130c0e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
10 changes: 5 additions & 5 deletions src/generic/Loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Spinner } from '@openedx/paragon';
import { FormattedMessage } from '@edx/frontend-platform/i18n';

export const LoadingSpinner = ({ size}) => (
export const LoadingSpinner = ({ size }) => (
<Spinner
animation="border"
role="status"
Expand All @@ -21,11 +21,11 @@ export const LoadingSpinner = ({ size}) => (

LoadingSpinner.defaultProps = {
size: undefined,
}
};

LoadingSpinner.prototype = {
size: PropTypes.string
}
LoadingSpinner.propTypes = {
size: PropTypes.string,
};

const Loading = () => (
<div className="d-flex justify-content-center align-items-center flex-column vh-100">
Expand Down
86 changes: 43 additions & 43 deletions src/studio-home/tabs-section/courses-tab/courses-filters/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useCallback } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { SearchField } from '@openedx/paragon';
import debounce from 'lodash.debounce';
import { debounce } from 'lodash';

import { getStudioHomeCoursesParams } from '../../../data/selectors';
import { updateStudioHomeCoursesCustomParams } from '../../../data/slice';
Expand All @@ -12,16 +12,16 @@ import CoursesTypesFilterMenu from './courses-types-filter-menu';
import CoursesOrderFilterMenu from './courses-order-filter-menu';
import './index.scss';

/*regex to check if a string has only whitespace
/* regex to check if a string has only whitespace
example " "
*/
const regexOnlyWhiteSpaces = /^\s+$/;

const CoursesFilters = ({
dispatch,
locationValue,
const CoursesFilters = ({
dispatch,
locationValue,
onSubmitSearchField,
isLoading
isLoading,
}) => {
const studioHomeCoursesParams = useSelector(getStudioHomeCoursesParams);
const {
Expand Down Expand Up @@ -90,51 +90,51 @@ const CoursesFilters = ({

const handleSearchCourses = (searchValueDebounced) => {
const valueFormatted = searchValueDebounced.trim();
const searchValueRequest = valueFormatted.length > 0 ? valueFormatted : undefined;
const filterParams = {
search: searchValueRequest,
activeOnly,
archivedOnly,
order,
};
const hasOnlySpaces = regexOnlyWhiteSpaces.test(searchValueDebounced);

if (searchValueRequest && valueFormatted !== search && !hasOnlySpaces && !cleanFilters) {
dispatch(updateStudioHomeCoursesCustomParams({
currentPage: 1,
isFiltered: true,
cleanFilters: false,
...filterParams,
}));
dispatch(fetchStudioHomeData(locationValue, false, { page: 1, ...filterParams }, true));
}

setInputSearchValue(searchValueDebounced);
const searchValueRequest = valueFormatted.length > 0 ? valueFormatted : undefined;
const filterParams = {
search: searchValueRequest,
activeOnly,
archivedOnly,
order,
};
const hasOnlySpaces = regexOnlyWhiteSpaces.test(searchValueDebounced);

if (searchValueRequest && valueFormatted !== search && !hasOnlySpaces && !cleanFilters) {
dispatch(updateStudioHomeCoursesCustomParams({
currentPage: 1,
isFiltered: true,
cleanFilters: false,
...filterParams,
}));

dispatch(fetchStudioHomeData(locationValue, false, { page: 1, ...filterParams }, true));
}

setInputSearchValue(searchValueDebounced);
};

const handleSearchCoursesDebounced = useCallback(
debounce((value) => handleSearchCourses(value), 400),
[]
[],
);

return (
<div className="d-flex">
<div className="d-flex flex-row">
<SearchField
onSubmit={onSubmitSearchField}
onChange={handleSearchCoursesDebounced}
value={cleanFilters ? '' : inputSearchValue}
className="mr-4"
data-testid="input-filter-courses-search"
placeholder="Search"
onClear={handleClearSearchInput}
/>
{isLoading && (
<span className="search-field-loading">
<LoadingSpinner size="sm" />
</span>)
}
<SearchField
onSubmit={onSubmitSearchField}
onChange={handleSearchCoursesDebounced}
value={cleanFilters ? '' : inputSearchValue}
className="mr-4"
data-testid="input-filter-courses-search"
placeholder="Search"
onClear={handleClearSearchInput}
/>
{isLoading && (
<span className="search-field-loading">
<LoadingSpinner size="sm" />
</span>
)}
</div>

<CoursesTypesFilterMenu onItemMenuSelected={handleMenuFilterItemSelected} />
Expand All @@ -153,7 +153,7 @@ CoursesFilters.propTypes = {
dispatch: PropTypes.func.isRequired,
locationValue: PropTypes.string,
onSubmitSearchField: PropTypes.func,
isProcessing: PropTypes.bool,
isLoading: PropTypes.bool,
};

export default CoursesFilters;
2 changes: 1 addition & 1 deletion src/studio-home/tabs-section/courses-tab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const CoursesTab = ({
/>
) : (
<div className="courses-tab-container">
{/*isShowProcessing && <ProcessingCourses />*/}
{isShowProcessing && !isEnabledPagination && <ProcessingCourses />}
{isEnabledPagination && (
<div className="d-flex flex-row justify-content-between my-4">
<CoursesFilters dispatch={dispatch} locationValue={locationValue} isLoading={isLoading} />
Expand Down

0 comments on commit 7130c0e

Please sign in to comment.