Skip to content

Commit

Permalink
(BSR) feat(cheatcodes): change filter > searchValue in CheatcodesMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeneston-pass committed Jan 7, 2025
1 parent 93c7d06 commit b625df8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/cheatcodes/hooks/filterAndSortCheatcodesButtons.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { CheatcodesButtonsWithSubscreensProps } from 'cheatcodes/types'

const isMatching = (filter: string, str?: string): boolean =>
(str ?? '').toLowerCase().includes(filter.toLowerCase())
const isMatching = (searchValue: string, str?: string): boolean =>
(str ?? '').toLowerCase().includes(searchValue.toLowerCase())

export const filterAndSortCheatcodesButtons = (
filter: string,
searchValue: string,
buttons: CheatcodesButtonsWithSubscreensProps[]
): CheatcodesButtonsWithSubscreensProps[] =>
buttons
.filter((button) => button.title || button.screen)
.map((button): CheatcodesButtonsWithSubscreensProps | null => {
const filteredSubscreens = button.subscreens?.filter(
(subscreen) => isMatching(filter, subscreen.title) || isMatching(filter, subscreen.screen)
(subscreen) =>
isMatching(searchValue, subscreen.title) || isMatching(searchValue, subscreen.screen)
)
const isButtonMatching =
isMatching(filter, button.title) ||
isMatching(filter, button.screen) ||
isMatching(searchValue, button.title) ||
isMatching(searchValue, button.screen) ||
(filteredSubscreens && filteredSubscreens.length > 0)
return isButtonMatching ? { ...button, subscreens: filter ? filteredSubscreens : [] } : null
return isButtonMatching
? { ...button, subscreens: searchValue ? filteredSubscreens : [] }
: null
})
.filter((button): button is CheatcodesButtonsWithSubscreensProps => button !== null)
.sort((a, b) =>
Expand Down
12 changes: 6 additions & 6 deletions src/cheatcodes/pages/CheatcodesMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { SNACK_BAR_TIME_OUT, useSnackBarContext } from 'ui/components/snackBar/S
import { getSpacing } from 'ui/theme'

export function CheatcodesMenu(): React.JSX.Element {
const [filter, setFilter] = useState('')
const resetSearch = () => setFilter('')
const [searchValue, setSearchValue] = useState('')
const resetSearch = () => setSearchValue('')

const { showInfoSnackBar } = useSnackBarContext()
const onPressSentry = () => {
Expand Down Expand Up @@ -79,15 +79,15 @@ export function CheatcodesMenu(): React.JSX.Element {

if (screenError) throw screenError

const filteredFeaturesButtons = filterAndSortCheatcodesButtons(filter, featuresButtons)
const filteredOtherButtons = filterAndSortCheatcodesButtons(filter, otherButtons)
const filteredFeaturesButtons = filterAndSortCheatcodesButtons(searchValue, featuresButtons)
const filteredOtherButtons = filterAndSortCheatcodesButtons(searchValue, otherButtons)

return (
<CheatcodesTemplateScreen title="Cheatcodes">
<StyledSearchInput
placeholder="Rechercher..."
value={filter}
onChangeText={setFilter}
value={searchValue}
onChangeText={setSearchValue}
onPressRightIcon={resetSearch}
/>
<StyledView>
Expand Down

0 comments on commit b625df8

Please sign in to comment.