Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/mobile/src/screens/search-screen/SearchFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'
import { useMemo, useState, useEffect } from 'react'

import type { Genre } from '@audius/common/utils'
import {
Expand Down Expand Up @@ -48,12 +48,25 @@ export const GenreFilter = () => {
setGenre(value)
}

const options = useMemo(() => {
// Freeform/custom genres (e.g. "Hyperpop Fusion") aren't in the predefined
// GENRES list. Without a matching option the FilterButton can't resolve a
// label and the active chip falls back to the generic "Genre" text, leaving
// no indication of what's actually being filtered. Add the current genre as
// an option so it renders as a selected chip.
if (genre && !genreOptions.some((option) => option.value === genre)) {
return [{ label: genre, value: genre }, ...genreOptions]
}

return genreOptions
}, [genre])

return (
<FilterButton
label={messages.genre}
value={genre}
onChange={handleGenreChange}
options={genreOptions}
options={options}
size='small'
/>
)
Expand Down
25 changes: 20 additions & 5 deletions packages/web/src/pages/search-page/SearchFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement, useCallback, useState } from 'react'
import { ReactElement, useCallback, useMemo, useState } from 'react'

import {
GENRES,
Expand Down Expand Up @@ -55,6 +55,24 @@ const GenreFilter = () => {
updateGenreParams(value)
}

const options = useMemo(() => {
const genreOptions = GENRES.map((genre) => ({
label: genre,
value: convertGenreLabelToValue(genre)
}))

// Freeform/custom genres (e.g. "Hyperpop Fusion") aren't in the predefined
// GENRES list. Without a matching option the FilterButton can't resolve a
// label and the active chip falls back to the generic "Genre" text, leaving
// no indication of what's actually being filtered. Add the current genre as
// an option so it renders as a selected chip.
if (genre && !genreOptions.some((option) => option.value === genre)) {
return [{ label: genre, value: genre }, ...genreOptions]
}

return genreOptions
}, [genre])

return (
<FilterButton
label={messages.genre}
Expand All @@ -65,10 +83,7 @@ const GenreFilter = () => {
}}
value={genre}
onChange={handleGenreChange}
options={GENRES.map((genre) => ({
label: genre,
value: convertGenreLabelToValue(genre)
}))}
options={options}
showFilterInput
filterInputProps={{ label: messages.genreFilterLabel }}
/>
Expand Down
Loading