From af14b403a78000a9a0df355edd83270513349180 Mon Sep 17 00:00:00 2001 From: fudgeu Date: Tue, 19 Nov 2024 17:38:19 -0500 Subject: [PATCH] Fix widget filtering logic - Widget filtering now includes widgets that are featured - Initial issue stemmed from a couple of closely related bugs that worked together to exclude featured widgets --- src/components/catalog.jsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/catalog.jsx b/src/components/catalog.jsx index 2fde7a3e7..2b1d33d3e 100644 --- a/src/components/catalog.jsx +++ b/src/components/catalog.jsx @@ -39,17 +39,17 @@ const Catalog = ({widgets = [], isLoading = true}) => { const [filteredWidgets, isFiltered] = useMemo(() => { let isFiltered = false - // in_catalog widgets are already being rendered via featured widgets - // append remaining widgets that are playable but not in_catalog + // create initial set of widgets to filter from - only including playable widgets let results = widgets.filter(w => { - return parseInt(w.is_playable) == 1 && parseInt(w.in_catalog) == 0 + return parseInt(w.is_playable) === 1 }) + // filters are active, only match active filters if(state.activeFilters.length){ isFiltered = true // find widgets that have all the active filters - results = widgets.filter(w => { + results = results.filter(w => { const {features, supported_data, accessibility_keyboard, accessibility_reader} = w.meta_data return state.activeFilters.every(f =>{ if (features.includes(f) || supported_data.includes(f)) return true @@ -68,6 +68,12 @@ const Catalog = ({widgets = [], isLoading = true}) => { results = results.filter(w => re.test(w.name)) } + // if there are no filters set, take out the featured widgets (those with in_catalog = 1) + // when no filter is present, a featured section appears already showing featured widgets + if (!isFiltered) { + results = results.filter(w => parseInt(w.in_catalog) !== 1) + } + return [results, isFiltered] }, [widgets, state.searchText, state.activeFilters]) @@ -262,25 +268,28 @@ const Catalog = ({widgets = [], isLoading = true}) => { className={`filter-toggle desktop-only ${state.showingFilters ? 'close-mode' : ''}`} aria-label={state.showingFilters ? 'Feature filters drawer open' : 'Filter catalog by features'} onClick={ filterLinkClickHandler }> - Feature + Feature + + Accessibility +
{setState({...state, searchText: e.target.value})}} type='text'/>
+ fillRule='evenodd' + />
{ searchCloseRender }
- +