Skip to content

Commit

Permalink
Add FilterTypes.Switch support to plugin filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Soopyboo32 committed Oct 8, 2024
1 parent 9c68260 commit aba1657
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/screens/BrowseSourceScreen/components/FilterBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getValueFor } from './filterUtils';
import { getString } from '@strings/translations';
import { ThemeColors } from '@theme/types';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { SwitchItem } from '@components';

const insertOrRemoveIntoArray = (array: string[], val: string): string[] =>
array.indexOf(val) > -1 ? array.filter(ele => ele !== val) : [...array, val];
Expand Down Expand Up @@ -56,6 +57,27 @@ const FilterItem: React.FC<FilterItemProps> = ({
setFalse: closeCard,
} = useBoolean();
const { width: screenWidth } = useWindowDimensions();
if (filter.type === FilterTypes.Switch) {
const value = getValueFor<(typeof filter)['type']>(
filter,
selectedFilters[filterKey],
);
return (
<View style={styles.switchContainer}>
<SwitchItem
theme={theme}
label={filter.label}
onPress={() => {
setSelectedFilters(prevState => ({
...prevState,
[filterKey]: { value: !value, type: FilterTypes.Switch },
}));
}}
value={value}
/>
</View>
);
}
if (filter.type === FilterTypes.Picker) {
const value = getValueFor<(typeof filter)['type']>(
filter,
Expand Down Expand Up @@ -344,6 +366,13 @@ const styles = StyleSheet.create({
paddingBottom: 8,
paddingTop: 8,
},
switchContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
marginVertical: 8,
paddingHorizontal: 24,
},
pickerContainer: {
flex: 1,
flexDirection: 'row',
Expand Down

0 comments on commit aba1657

Please sign in to comment.