// @flow import React from 'react'; import { View, TouchableOpacity, Text } from 'react-native'; // import CheckBox from 'react-native-checkbox'; import { Checkbox } from 'react-native-material-ui'; import Modal from './Modal'; import { withFilter } from '../enhancers/filterEnhancers'; import typeof FilterRecord from '../records/FilterRecord'; import { CATEGORIES, type Category } from '../constants/CategoryConstants'; import { getCategoryText } from '../helpers/CategoryHelpers'; import OrderbyPicker, { type Orderby } from './OrderbyPicker'; import RadiusPicker from './RadiusPicker'; import { compose, withHandlers, withState, onlyUpdateForKeys } from 'recompose'; import theme from '../ui-theme'; const { palette } = theme; type Props = { isVisible: boolean, onClose: () => void, filter: FilterRecord, setFilter: (f: FilterRecord) => void, currentFilter: FilterRecord, setCurrentFilter: (currentFilter: FilterRecord) => void, toggleCategory: (category: Category, isChecked: boolean) => () => void, applyChanges: () => void, updateOrderby: (orderby: Orderby) => void, updateRadius: (radius: number) => void, }; const FilterModal = (props: Props) => { const { isVisible, onClose, currentFilter: { orderby, categories, radius }, toggleCategory, applyChanges, updateOrderby, updateRadius, } = props; return ( Filters {CATEGORIES.map((category: Category) => { const isChecked = categories.has(category); return ( {getCategoryText(category)} ); })} Sort By Search Radius Cancel Apply ); }; export default compose( withFilter, withState('currentFilter', 'setCurrentFilter', (props: Props) => props.filter), withHandlers({ toggleCategory: ({ currentFilter, setCurrentFilter }: Props) => ( category: Category, isChecked: boolean ) => () => { setCurrentFilter( currentFilter.update('categories', categories => { return isChecked ? categories.delete(category) : categories.add(category); }) ); }, updateOrderby: ({ currentFilter, setCurrentFilter }: Props) => (orderby: Orderby) => { setCurrentFilter(currentFilter.set('orderby', orderby)); }, updateRadius: ({ currentFilter, setCurrentFilter }: Props) => (radius: number) => { setCurrentFilter(currentFilter.set('radius', radius)); }, applyChanges: ({ onClose, currentFilter, setFilter }: Props) => () => { setFilter(currentFilter); onClose(); }, }), onlyUpdateForKeys(['isVisible', 'currentFilter']) )(FilterModal);