Skip to content

Commit

Permalink
feat: literal easy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 3, 2024
1 parent ee1010b commit 5298676
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 47 deletions.
3 changes: 2 additions & 1 deletion packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -704,5 +704,6 @@
"granted": "granted",
"global_respects_selected": "Global Respects Selected",
"set_all": "Set All",
"only_show_available": "Only Show Available"
"only_show_available": "Only Show Available",
"easy_mode": "Easy Mode"
}
2 changes: 2 additions & 0 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@
},
"pokemon": {
"enabled": false,
"easyMode": false,
"onlyShowAvailable": true,
"legacyFilter": false,
"allPokemon": false,
"globalValues": {
Expand Down
2 changes: 2 additions & 0 deletions server/src/services/filters/builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ function buildDefaultFilters(perms, database) {
perms.pokemon && database.models.Pokemon
? {
enabled: defaultFilters.pokemon.enabled,
easyMode: defaultFilters.pokemon.easyMode,
onlyShowAvailable: defaultFilters.pokemon.onlyShowAvailable,
legacy:
pokemonReducer && config.getSafe('map.misc.enableMapJsFilter')
? defaultFilters.pokemon.legacyFilter
Expand Down
5 changes: 3 additions & 2 deletions src/components/QueryData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const userSettingsCategory = (category) => {

const trimFilters = (requestedFilters, userSettings, category, onlyAreas) => {
const { filters: staticFilters } = useStatic.getState()
const easyMode = !!requestedFilters?.easyMode
const trimmed = {
onlyLegacy: userSettings?.legacyFilter,
onlyLinkGlobal: userSettings?.linkGlobalAndAdvanced,
onlyLinkGlobal: userSettings?.linkGlobalAndAdvanced || easyMode,
onlyAllPvp: userSettings?.showAllPvpRanks,
onlyAreas: onlyAreas || [],
}
Expand All @@ -57,7 +58,7 @@ const trimFilters = (requestedFilters, userSettings, category, onlyAreas) => {
const [id, specifics] = filter

if (specifics && specifics.enabled && staticFilters[category]?.filter[id]) {
trimmed[id] = specifics
trimmed[id] = easyMode ? { ...specifics, all: true } : specifics
}
})
return trimmed
Expand Down
92 changes: 48 additions & 44 deletions src/components/layout/drawer/Pokemon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IconButton,
Dialog,
ButtonGroup,
Collapse,
} from '@mui/material'
import { useTranslation } from 'react-i18next'
import { VirtuosoGrid } from 'react-virtuoso'
Expand Down Expand Up @@ -44,7 +45,6 @@ function AvailableSelector() {
tempFilters: filters.standard,
})
const [open, setOpen] = React.useState(false)
const [showAvailable, setShowAvailable] = React.useState(false)

const onClose = (e, id, filter) => () => {
if (e !== undefined) {
Expand Down Expand Up @@ -98,40 +98,39 @@ function AvailableSelector() {

const items = React.useMemo(
() =>
showAvailable
filters.onlyShowAvailable
? available
: Object.keys(filters.filter).filter((key) => key !== 'global'),
[showAvailable, filters.filter, available],
[filters.onlyShowAvailable, filters.filter, available],
)

return (
<List>
<ListItem>
<ListItemText>{t('only_show_available')}</ListItemText>
<Switch
onChange={(_, checked) => setShowAvailable(checked)}
checked={!!showAvailable}
/>
</ListItem>
<BoolToggle
field="filters.pokemon.onlyShowAvailable"
label="only_show_available"
/>
<ListItem>
<ListItemText>{t('set_all')}</ListItemText>
<ButtonGroup variant="text" size="small" color="warning">
<IconButton color="success" onClick={() => setAll('enable')}>
<CheckIcon />
</IconButton>
<IconButton
color="info"
onClick={() => {
setAdvanced((prev) => ({
...prev,
id: 'global',
tempFilters: filters.filter.global,
}))
setOpen(true)
}}
>
<TuneIcon />
</IconButton>
<Collapse in={!filters.easyMode} orientation="horizontal">
<IconButton
color="info"
onClick={() => {
setAdvanced((prev) => ({
...prev,
id: 'global',
tempFilters: filters.filter.global,
}))
setOpen(true)
}}
>
<TuneIcon />
</IconButton>
</Collapse>
<IconButton color="error" onClick={() => setAll('disable')}>
<ClearIcon />
</IconButton>
Expand All @@ -153,7 +152,7 @@ function AvailableSelector() {
const [pokemon, form] = key.split('-', 2)
const url = ctx.Icons.getPokemon(pokemon, form)
const bgcolor = filters.filter[key]?.enabled
? filters.filter[key]?.all
? filters.filter[key]?.all || filters.easyMode
? 'success.main'
: 'info.main'
: 'error.dark'
Expand All @@ -169,7 +168,7 @@ function AvailableSelector() {
const filter = { ...filters.filter[key] }
if (filter.all) {
filter.all = false
filter.enabled = true
filter.enabled = !filters.easyMode
} else if (filter.enabled) {
filter.enabled = false
} else {
Expand Down Expand Up @@ -208,21 +207,23 @@ function AvailableSelector() {
zIndex: 10,
}}
/>
<IconButton
size="small"
sx={{ position: 'absolute', right: 0, top: 0 }}
onClick={(e) => {
e.stopPropagation()
setAdvanced((prev) => ({
...prev,
id: key,
tempFilters: filters.filter[key],
}))
setOpen(true)
}}
>
<TuneIcon fontSize="small" />
</IconButton>
<Collapse in={!filters.easyMode}>
<IconButton
size="small"
sx={{ position: 'absolute', right: 0, top: 0 }}
onClick={(e) => {
e.stopPropagation()
setAdvanced((prev) => ({
...prev,
id: key,
tempFilters: filters.filter[key],
}))
setOpen(true)
}}
>
<TuneIcon fontSize="small" />
</IconButton>
</Collapse>
</Box>
)
}}
Expand Down Expand Up @@ -290,10 +291,13 @@ export default function WithSliders({ category, context }) {
return (
<>
<BoolToggle field="filters.pokemon.enabled" label="enabled" />
<BoolToggle
field="userSettings.pokemon.linkGlobalAndAdvanced"
label="global_respects_selected"
/>
<BoolToggle field="filters.pokemon.easyMode" label="easy_mode" />
<Collapse in={!filters.pokemon.easyMode}>
<BoolToggle
field="userSettings.pokemon.linkGlobalAndAdvanced"
label="global_respects_selected"
/>
</Collapse>
{userSettings[category].legacyFilter && context.legacy ? (
<ListItem>
<StringFilter
Expand Down

0 comments on commit 5298676

Please sign in to comment.