Skip to content

Commit

Permalink
fix: sort menu collapse after filter selection (#645)
Browse files Browse the repository at this point in the history
* fix: sort menu collapse after filter selection

* refactor: filter menu collapse logic

---------

Co-authored-by: Awais Ansari <[email protected]>
  • Loading branch information
sundasnoreen12 and awais-ansari authored Jan 17, 2024
1 parent 5df51f2 commit ffb3864
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/components/FilterBar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/forbid-prop-types */
import React, { useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import PropTypes from 'prop-types';

import { capitalize, toString } from 'lodash';
Expand Down Expand Up @@ -93,10 +93,15 @@ const FilterBar = ({
},
];

const handleFilterToggle = useCallback((event) => {
onFilterChange(event);
setOpen(false);
}, [onFilterChange]);

return (
<Collapsible.Advanced
open={isOpen}
onToggle={() => setOpen(!isOpen)}
onToggle={setOpen}
className="filter-bar collapsible-card-lg border-0"
>
<Collapsible.Trigger className="collapsible-trigger border-0">
Expand Down Expand Up @@ -126,7 +131,7 @@ const FilterBar = ({
name={value.name}
className="d-flex flex-column list-group list-group-flush"
value={selectedFilters[value.name]}
onChange={onFilterChange}
onChange={handleFilterToggle}
>
{value.filters.map(filterName => {
const element = allFilters.find(obj => obj.id === filterName);
Expand Down Expand Up @@ -159,7 +164,7 @@ const FilterBar = ({
name="cohort"
className="d-flex flex-column list-group list-group-flush w-100"
value={selectedFilters.cohort}
onChange={onFilterChange}
onChange={handleFilterToggle}
>
<ActionItem
id="all-groups"
Expand Down
7 changes: 2 additions & 5 deletions src/discussions/learners/learner/LearnerFilterBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ const LearnerFilterBar = () => {
},
);
}
setOpen(false);
}, []);

const handleOnToggle = useCallback(() => {
setOpen(!isOpen);
}, [isOpen]);

return (
<Collapsible.Advanced
open={isOpen}
onToggle={handleOnToggle}
onToggle={setOpen}
className="filter-bar collapsible-card-lg border-0"
>
<Collapsible.Trigger className="collapsible-trigger border-0">
Expand Down
7 changes: 2 additions & 5 deletions src/discussions/posts/post-filter-bar/PostFilterBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ const PostFilterBar = () => {
}

sendTrackEvent('edx.forum.filter.content', filterContentEventProperties);
setOpen(false);
}, [currentFilters, currentSorting, dispatch, selectedCohort]);

const handleToggle = useCallback(() => {
setOpen(!isOpen);
}, [isOpen]);

useEffect(() => {
if (userHasModerationPrivileges && isEmpty(cohorts)) {
dispatch(fetchCourseCohorts(courseId));
Expand Down Expand Up @@ -183,7 +180,7 @@ const PostFilterBar = () => {
return (
<Collapsible.Advanced
open={isOpen}
onToggle={handleToggle}
onToggle={setOpen}
className="filter-bar collapsible-card-lg border-0"
>
<Collapsible.Trigger className="collapsible-trigger border-0">
Expand Down

0 comments on commit ffb3864

Please sign in to comment.