Skip to content

Commit b628157

Browse files
authored
Fix mobile trending filter (#13794)
1 parent e8c4683 commit b628157

5 files changed

Lines changed: 58 additions & 20 deletions

File tree

Lines changed: 1 addition & 1 deletion
Loading

packages/mobile/src/components/core/Screen/ScreenHeaderButton.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ type ScreenHeaderButtonProps = Omit<SelectablePillProps, 'type'>
88
export const ScreenHeaderButton = (props: ScreenHeaderButtonProps) => {
99
return (
1010
<View>
11-
<SelectablePill type='button' isSelected isControlled {...props} />
11+
<SelectablePill
12+
{...({
13+
type: 'button',
14+
isSelected: true,
15+
isControlled: true,
16+
...props
17+
} as SelectablePillProps)}
18+
/>
1219
</View>
1320
)
1421
}

packages/mobile/src/harmony-native/components/input/SelectablePill/SelectablePill.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const SelectablePill = (props: SelectablePillProps) => {
2727
const {
2828
type,
2929
icon: Icon,
30-
label,
3130
size = 'small',
3231
isSelected: isSelectedProp,
3332
isControlled,
@@ -38,8 +37,15 @@ export const SelectablePill = (props: SelectablePillProps) => {
3837
style: styleProp,
3938
fullWidth,
4039
disableUnselectAnimation,
40+
'aria-label': ariaLabel,
41+
accessibilityLabel: accessibilityLabelProp,
4142
...other
4243
} = props
44+
45+
const label = 'label' in props ? props.label : undefined
46+
const isIconOnly = !('label' in props) && !!Icon
47+
const displayLabel = label
48+
const a11yLabel = ariaLabel ?? accessibilityLabelProp
4349
const {
4450
color,
4551
motion,
@@ -153,6 +159,7 @@ export const SelectablePill = (props: SelectablePillProps) => {
153159
onTouchCancel={handleTouchCancel}
154160
onPress={handlePress}
155161
hitSlop={DEFAULT_HIT_SLOP}
162+
accessibilityLabel={isIconOnly ? a11yLabel : undefined}
156163
style={[
157164
css({ alignSelf: 'flex-start', borderRadius: cornerRadius['2xl'] }),
158165
styleProp
@@ -178,19 +185,24 @@ export const SelectablePill = (props: SelectablePillProps) => {
178185
style={[animatedRootStyles, fullWidth ? { width: '100%' } : undefined]}
179186
{...other}
180187
>
181-
{size !== 'small' && Icon ? (
188+
{(isIconOnly || (size !== 'small' && Icon)) && Icon ? (
182189
<Icon
183190
size='s'
184191
color={isSelected || isPressing ? 'white' : 'default'}
185192
/>
186193
) : null}
187-
<AnimatedText
188-
numberOfLines={1}
189-
variant='body'
190-
style={[animatedTextStyles, { lineHeight: typography.lineHeight.m }]}
191-
>
192-
{label}
193-
</AnimatedText>
194+
{displayLabel != null ? (
195+
<AnimatedText
196+
numberOfLines={1}
197+
variant='body'
198+
style={[
199+
animatedTextStyles,
200+
{ lineHeight: typography.lineHeight.m }
201+
]}
202+
>
203+
{displayLabel}
204+
</AnimatedText>
205+
) : null}
194206
</AnimatedFlex>
195207
</Pressable>
196208
)

packages/mobile/src/harmony-native/components/input/SelectablePill/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@ import type { PressableProps, ViewProps } from 'react-native'
22

33
import type { IconComponent } from 'app/harmony-native/icons'
44

5-
export type SelectablePillProps = {
5+
type BaseSelectablePillProps = {
66
type: 'button' | 'checkbox' | 'radio'
77
size?: 'small' | 'large'
88
isSelected?: boolean
99
isControlled?: boolean
10-
label: string
1110
value?: string
1211
icon?: IconComponent
1312
onChange?: (value: string, isSelected?: boolean) => void
1413
fullWidth?: boolean
1514
disableUnselectAnimation?: boolean
15+
'aria-label'?: string
16+
accessibilityLabel?: string
1617
} & Pick<PressableProps, 'disabled' | 'onPress'> &
1718
ViewProps
19+
20+
export type SelectablePillProps = BaseSelectablePillProps &
21+
(
22+
| { label: string; icon?: IconComponent }
23+
| { icon: IconComponent; label?: never }
24+
)

packages/mobile/src/screens/trending-screen/TrendingHeader.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import type { ComponentType } from 'react'
22

3+
import { TimeRange } from '@audius/common/models'
34
import type { Modals, TrendingCategory } from '@audius/common/store'
45
import {
56
modalsActions,
67
trendingPageActions,
78
trendingPageLineupActions,
89
trendingPageSelectors
910
} from '@audius/common/store'
11+
import { ALL_GENRES } from '@audius/common/utils'
1012
import type { ViewStyle } from 'react-native'
1113
import { ScrollView, View } from 'react-native'
1214
import type { SvgProps } from 'react-native-svg'
1315
import { useDispatch, useSelector } from 'react-redux'
1416

1517
import {
1618
Flex,
17-
IconButton,
1819
IconLeading,
1920
SelectablePill,
2021
useTheme
@@ -87,6 +88,12 @@ export const TrendingHeader = (props: TrendingHeaderProps) => {
8788
const { spacing } = useTheme()
8889
const dispatch = useDispatch()
8990
const category = useSelector(getTrendingCategory) ?? 'tracks'
91+
const timeRange = useSelector(trendingPageSelectors.getTrendingTimeRange)
92+
const genre = useSelector(trendingPageSelectors.getTrendingGenre)
93+
94+
const hasActiveFilters =
95+
(timeRange ?? TimeRange.WEEK) !== TimeRange.WEEK ||
96+
(genre ?? ALL_GENRES) !== ALL_GENRES
9097

9198
const handleOpenFilter = () => {
9299
dispatch(setVisibility({ modal: filterModal, visible: true }))
@@ -116,12 +123,17 @@ export const TrendingHeader = (props: TrendingHeaderProps) => {
116123
</GradientText>
117124
</View>
118125
{category === 'tracks' ? (
119-
<IconButton
120-
icon={IconLeading}
121-
size='s'
122-
onPress={handleOpenFilter}
123-
aria-label='Open filter'
124-
/>
126+
<Flex>
127+
<SelectablePill
128+
type='button'
129+
icon={IconLeading}
130+
size='large'
131+
isSelected={hasActiveFilters}
132+
isControlled
133+
onPress={handleOpenFilter}
134+
accessibilityLabel='Open filter'
135+
/>
136+
</Flex>
125137
) : null}
126138
</View>
127139
<ScrollView

0 commit comments

Comments
 (0)