|
| 1 | +import { useCallback } from 'react' |
| 2 | + |
| 3 | +import { FeedFilter } from '@audius/common/models' |
| 4 | +import { feedPageActions, feedPageSelectors } from '@audius/common/store' |
| 5 | +import { Pressable, View } from 'react-native' |
| 6 | +import { useDispatch, useSelector } from 'react-redux' |
| 7 | + |
| 8 | +import { Flex, Text } from '@audius/harmony-native' |
| 9 | +import { RadioButton, Text as CoreText } from 'app/components/core' |
| 10 | +import { AppDrawer, useDrawerState } from 'app/components/drawer' |
| 11 | +import { makeStyles } from 'app/styles' |
| 12 | + |
| 13 | +export const FEED_FILTER_MODAL = 'FeedFilter' as const |
| 14 | + |
| 15 | +const filterLabels: Record<FeedFilter, string> = { |
| 16 | + [FeedFilter.ALL]: 'All Posts', |
| 17 | + [FeedFilter.ORIGINAL]: 'Original Posts', |
| 18 | + [FeedFilter.REPOST]: 'Reposts' |
| 19 | +} |
| 20 | + |
| 21 | +const filterOptions: FeedFilter[] = [ |
| 22 | + FeedFilter.ALL, |
| 23 | + FeedFilter.ORIGINAL, |
| 24 | + FeedFilter.REPOST |
| 25 | +] |
| 26 | + |
| 27 | +const messages = { |
| 28 | + title: 'Filter Feed', |
| 29 | + sectionTitle: 'Post Type', |
| 30 | + selected: 'Selected' |
| 31 | +} |
| 32 | + |
| 33 | +const useStyles = makeStyles(({ palette, spacing }) => ({ |
| 34 | + grabBar: { |
| 35 | + width: 36, |
| 36 | + height: 4, |
| 37 | + borderRadius: 2, |
| 38 | + backgroundColor: palette.neutralLight6 |
| 39 | + }, |
| 40 | + grabBarContainer: { |
| 41 | + paddingTop: spacing(2), |
| 42 | + paddingBottom: spacing(1), |
| 43 | + alignItems: 'center' |
| 44 | + }, |
| 45 | + content: { |
| 46 | + paddingHorizontal: spacing(4), |
| 47 | + paddingTop: spacing(4), |
| 48 | + paddingBottom: spacing(6) |
| 49 | + }, |
| 50 | + sectionTitle: { |
| 51 | + marginBottom: spacing(2) |
| 52 | + }, |
| 53 | + optionRow: { |
| 54 | + flexDirection: 'row', |
| 55 | + alignItems: 'center', |
| 56 | + justifyContent: 'space-between', |
| 57 | + paddingVertical: spacing(4), |
| 58 | + borderBottomWidth: 1, |
| 59 | + borderBottomColor: palette.neutralLight8 |
| 60 | + } |
| 61 | +})) |
| 62 | + |
| 63 | +export const FeedFilterDrawer = () => { |
| 64 | + const styles = useStyles() |
| 65 | + const dispatch = useDispatch() |
| 66 | + const currentFilter = |
| 67 | + useSelector(feedPageSelectors.getFeedFilter) ?? FeedFilter.ALL |
| 68 | + |
| 69 | + useDrawerState(FEED_FILTER_MODAL) |
| 70 | + |
| 71 | + const handleSelectFilter = useCallback( |
| 72 | + (filter: FeedFilter) => { |
| 73 | + dispatch(feedPageActions.setFeedFilter(filter)) |
| 74 | + }, |
| 75 | + [dispatch] |
| 76 | + ) |
| 77 | + |
| 78 | + const drawerHeader = useCallback( |
| 79 | + (_props: { onClose: () => void }) => ( |
| 80 | + <Flex> |
| 81 | + <View style={[styles.grabBarContainer]}> |
| 82 | + <View style={[styles.grabBar]} /> |
| 83 | + </View> |
| 84 | + <Flex ph='l' pb='l' pt='xs' justifyContent='center' alignItems='center'> |
| 85 | + <Text variant='title' size='l' textAlign='center'> |
| 86 | + {messages.title} |
| 87 | + </Text> |
| 88 | + </Flex> |
| 89 | + </Flex> |
| 90 | + ), |
| 91 | + [styles] |
| 92 | + ) |
| 93 | + |
| 94 | + return ( |
| 95 | + <AppDrawer |
| 96 | + modalName={FEED_FILTER_MODAL} |
| 97 | + drawerHeader={drawerHeader} |
| 98 | + isGestureSupported |
| 99 | + > |
| 100 | + <View style={styles.content}> |
| 101 | + <View style={styles.sectionTitle}> |
| 102 | + <CoreText fontSize='large' weight='demiBold'> |
| 103 | + {messages.sectionTitle} |
| 104 | + </CoreText> |
| 105 | + </View> |
| 106 | + {filterOptions.map((filter) => ( |
| 107 | + <Pressable |
| 108 | + key={filter} |
| 109 | + onPress={() => handleSelectFilter(filter)} |
| 110 | + style={styles.optionRow} |
| 111 | + > |
| 112 | + <Flex direction='row' alignItems='center' gap='m'> |
| 113 | + <RadioButton checked={currentFilter === filter} /> |
| 114 | + <Text |
| 115 | + variant='body' |
| 116 | + size='l' |
| 117 | + color={currentFilter === filter ? 'accent' : 'default'} |
| 118 | + > |
| 119 | + {filterLabels[filter]} |
| 120 | + </Text> |
| 121 | + </Flex> |
| 122 | + {currentFilter === filter ? ( |
| 123 | + <Text variant='body' size='s' color='accent'> |
| 124 | + {messages.selected} |
| 125 | + </Text> |
| 126 | + ) : null} |
| 127 | + </Pressable> |
| 128 | + ))} |
| 129 | + </View> |
| 130 | + </AppDrawer> |
| 131 | + ) |
| 132 | +} |
0 commit comments