@@ -10,7 +10,7 @@ import type {
1010 StationMenuType ,
1111} from './types'
1212import size from 'lodash/size'
13- import { ListSectionHeader , ListSeparator } from '@frogpond/lists'
13+ import { ListSectionHeader , ListSeparator , largeListProps } from '@frogpond/lists'
1414import type { FilterType } from '@frogpond/filter'
1515import { applyFiltersToItem } from '@frogpond/filter'
1616import { NoticeView } from '@frogpond/notice'
@@ -62,6 +62,12 @@ const areSpecialsFiltered = (
6262const isSpecialsFilter = ( f : FilterType < MenuItemType > ) : boolean =>
6363 f . enabled && f . type === 'toggle' && f . spec . label === 'Only Show Specials'
6464
65+ const areDietsFiltered = ( filters : Array < FilterType < MenuItemType > > ) : boolean =>
66+ Boolean ( filters . find ( isDietsFilter ) )
67+
68+ const isDietsFilter = ( f : FilterType < MenuItemType > ) : boolean =>
69+ f . enabled && f . type === 'list' && f . spec . title === 'Dietary Restrictions'
70+
6571const groupMenuData = ( args : {
6672 filters : Array < FilterType < MenuItemType > >
6773 stations : Array < StationMenuType >
@@ -70,13 +76,23 @@ const groupMenuData = (args: {
7076} ) : { title : string ; data : Array < MenuItemType > } [ ] => {
7177 const { applyFilters, foodItems, stations, filters} = args
7278
79+ const dietsFilterEnabled = areDietsFiltered ( filters )
80+
7381 const dereferenceMenuItems = ( menu : StationMenuType ) =>
7482 menu . items
7583 // Dereference each menu item
7684 . map ( ( id ) => foodItems [ id ] )
7785 // Ensure that the referenced menu items exist,
7886 // and apply the selected filters to the items in the menu
79- . filter ( ( item ) => item && applyFilters ( filters , item ) )
87+ . filter ( ( item ) => {
88+ // Ensure that items with dietary data are the only
89+ // items being shown when a diet filter is enabled
90+ if ( dietsFilterEnabled ) {
91+ return ! item ?. cor_icon ?. entries && applyFilters ( filters , item )
92+ }
93+
94+ return item && applyFilters ( filters , item )
95+ } )
8096
8197 const stationMenusByLabel : [ string , MenuItemType [ ] ] [ ] = stations . map (
8298 ( menu : StationMenuType ) => [ menu . label , dereferenceMenuItems ( menu ) ] ,
@@ -185,7 +201,7 @@ export function FancyMenu(props: Props): JSX.Element {
185201 } }
186202 sections = { groupedMenuData }
187203 style = { styles . inner }
188- windowSize = { 5 }
204+ { ... largeListProps }
189205 />
190206 )
191207}
0 commit comments