Skip to content

Commit

Permalink
refactor: hasAll checking function
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 11, 2024
1 parent fd519de commit 04a0e60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/components/layout/dialogs/filters/Advanced.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { ENABLED_ALL, XXS_XXL } from '@assets/constants'
import { useTranslateById } from '@hooks/useTranslateById'
import { STANDARD_BACKUP, applyToAll } from '@services/filtering/applyToAll'
import { checkIfHasAll } from '@services/functions/hasAll'

import { StringFilter } from './StringFilter'
import SliderTile from './SliderTile'
Expand Down Expand Up @@ -188,13 +189,7 @@ export default function AdvancedFilter() {
/>
)}
{category === 'pokestops' && <QuestConditionSelector id={id} />}
{category === 'pokemon' ||
(category === 'pokestops' &&
!(
id.startsWith('l') ||
id.startsWith('i') ||
id.startsWith('f')
)) ? (
{checkIfHasAll(category, id) ? (
<DualBoolToggle
items={ENABLED_ALL}
field={`filters.${category}.filter.${id}`}
Expand Down
8 changes: 3 additions & 5 deletions src/components/layout/drawer/SelectorItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useTranslateById } from '@hooks/useTranslateById'
import { useMemory } from '@hooks/useMemory'
import { useLayoutStore } from '@hooks/useLayoutStore'
import { useStorage, useDeepStore } from '@hooks/useStorage'
import { checkIfHasAll } from '@services/functions/hasAll'

import { Img } from '../general/Img'
import { ColoredTile } from '../general/ColoredTile'
import { useWebhookStore } from '../dialogs/webhooks/store'
Expand Down Expand Up @@ -116,11 +118,7 @@ export function SelectorItem({
const url = useMemory((s) => s.Icons.getIconById(id))
const easyMode = useStorage((s) => !!s.filters[category]?.easyMode)

const hasAll =
category === 'pokemon' ||
(category === 'pokestops' &&
!(id.startsWith('l') || id.startsWith('i') || id.startsWith('f'))) ||
(id.startsWith('t') && id !== 't0-0')
const hasAll = checkIfHasAll(category, id)
const color = filter?.enabled
? filter?.all || easyMode || !hasAll
? 'success.main'
Expand Down
20 changes: 20 additions & 0 deletions src/services/functions/hasAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check

/**
* @param {string} category
* @param {string} id
* @returns {boolean}
*/
export function checkIfHasAll(category, id) {
return (
category === 'pokemon' ||
(category === 'pokestops' &&
!(
id.startsWith('l') ||
id.startsWith('i') ||
id.startsWith('f') ||
id.startsWith('a')
)) ||
(id.startsWith('t') && id !== 't0-0')
)
}

0 comments on commit 04a0e60

Please sign in to comment.