diff --git a/server/src/graphql/resolvers.js b/server/src/graphql/resolvers.js index c6c70d0f2..7351fd43a 100644 --- a/server/src/graphql/resolvers.js +++ b/server/src/graphql/resolvers.js @@ -507,16 +507,9 @@ const resolvers = { })) } if (category === 'invasion') { - const { invasions } = Event.masterfile result.invasion = result.invasion.map((x) => ({ ...x, - real_grunt_id: - +Object.keys(invasions).find( - (key) => - invasions[key]?.type?.toLowerCase() === - x.grunt_type.toLowerCase() && - invasions[key].gender === (x.gender || 1), - ) || 0, + real_grunt_id: PoracleAPI.getRealGruntId(x, Event.invasions), })) } if (category === 'raid') { @@ -525,7 +518,6 @@ const resolvers = { allMoves: x.move === 9000, })) } - return result } return {} @@ -664,6 +656,27 @@ const resolvers = { status, data, ) + if (category === 'pokemon') { + result.pokemon = result.pokemon.map((x) => ({ + ...x, + allForms: !x.form, + pvpEntry: !!x.pvp_ranking_league, + xs: x.max_weight !== 9000000, + xl: x.min_weight !== 0, + })) + } + if (category === 'invasion') { + result.invasion = result.invasion.map((x) => ({ + ...x, + real_grunt_id: PoracleAPI.getRealGruntId(x, Event.invasions), + })) + } + if (category === 'raid') { + result.raid = result.raid.map((x) => ({ + ...x, + allMoves: x.move === 9000, + })) + } return result } return {} diff --git a/server/src/services/api/Poracle.js b/server/src/services/api/Poracle.js index d2c21da37..1ca622c53 100644 --- a/server/src/services/api/Poracle.js +++ b/server/src/services/api/Poracle.js @@ -1231,6 +1231,23 @@ class PoracleAPI { // this.disabledHooks.forEach((hook) => delete poracleUiObj[hook]) return poracleUiObj } + + /** + * + * @param {import('@rm/types').PoracleInvasion} item + * @param {import('@rm/types').Masterfile['invasions']} invasions + */ + static getRealGruntId(item, invasions) { + return ( + +Object.keys(invasions).find( + (key) => + invasions[key]?.type?.toLowerCase() === + item.grunt_type.toLowerCase() && + (invasions[key]?.gender === 0 || + invasions[key].gender === (item.gender || 1)), + ) || 0 + ) + } } module.exports = PoracleAPI diff --git a/src/components/layout/dialogs/webhooks/WebhookAdv.jsx b/src/components/layout/dialogs/webhooks/WebhookAdv.jsx index a2c20676a..ea58a5914 100644 --- a/src/components/layout/dialogs/webhooks/WebhookAdv.jsx +++ b/src/components/layout/dialogs/webhooks/WebhookAdv.jsx @@ -71,6 +71,7 @@ const skipFields = new Set([ 'shiny', 'everything_individually', 'all', + 'real_grunt_id', ]) const wildCards = { @@ -97,6 +98,20 @@ export default function WebhookAdvanced() { const { pokemon, moves, types } = useMemory((s) => s.masterfile) const isMobile = useMemory((s) => s.isMobile) + const [filterValues, setFilterValues] = React.useState( + tempFilters?.template + ? Poracle.reactMapFriendly(tempFilters) + : { + ...Poracle.reactMapFriendly(info?.defaults), + profile_no: human.current_profile_no, + }, + ) + const [poracleValues, setPoracleValues] = React.useState( + tempFilters?.template + ? tempFilters + : { ...info?.defaults, profile_no: human.current_profile_no }, + ) + Utility.analytics(`/poracle/${category}`) const [search, { data, previousData, loading }] = useLazyQuery( @@ -112,19 +127,6 @@ export default function WebhookAdvanced() { }, ) const fetchedData = data || previousData - const [filterValues, setFilterValues] = React.useState( - tempFilters?.template - ? Poracle.reactMapFriendly(tempFilters) - : { - ...Poracle.reactMapFriendly(info?.defaults), - profile_no: human.current_profile_no, - }, - ) - const [poracleValues, setPoracleValues] = React.useState( - tempFilters?.template - ? tempFilters - : { ...info?.defaults, profile_no: human.current_profile_no }, - ) React.useEffect(() => { setPoracleValues( @@ -142,6 +144,13 @@ export default function WebhookAdvanced() { ) }, [tempFilters, id, human.current_profile_no, info?.defaults]) + React.useEffect(() => { + setPoracleValues((prev) => ({ + ...prev, + everything_individually: !!selectedIds.length, + })) + }, [selectedIds]) + const handleSlider = React.useCallback( (low, high) => (name, values) => { setFilterValues((prev) => ({ ...prev, [name]: values })) @@ -758,47 +767,50 @@ export default function WebhookAdvanced() { const handleClose = (save, filterId, filterToSave) => { if (save) { - if (filterId === 'global' && filterToSave) { - const newFilters = {} - const wc = wildCards[category] || ['0-0'] - if (filterToSave.everything_individually !== false) { - selectedIds.forEach((item) => { - if (!wc.includes(item)) { + useWebhookStore.setState((prev) => { + if (filterId === 'global' && filterToSave) { + const newFilters = {} + const wc = wildCards[category] || ['0-0'] + if (filterToSave.everything_individually !== false) { + selectedIds.forEach((item) => { + if (!wc.includes(item)) { + newFilters[item] = { + ...prev.tempFilters[item], + ...filterToSave, + enabled: true, + } + } + }) + } else { + wc.forEach((item) => { newFilters[item] = { - ...tempFilters[item], + ...prev.tempFilters[item], ...filterToSave, enabled: true, } - } - }) - } else { - wc.forEach((item) => { - newFilters[item] = { - ...tempFilters[item], - ...filterToSave, - enabled: true, - } - }) + }) + } + return { + tempFilters: { + ...prev.tempFilters, + ...newFilters, + [filterId]: { ...filterToSave }, + }, + } } - useWebhookStore.setState((prev) => ({ - tempFilters: { - ...prev.tempFilters, - ...newFilters, - [filterId]: { ...filterToSave }, - }, - })) - } else if (filterId && filterToSave) { - useWebhookStore.setState((prev) => ({ - tempFilters: { - ...prev.tempFilters, - [filterId]: { - ...prev.tempFilters[id], - ...filterToSave, - enabled: true, + if (filterId && filterToSave) { + return { + tempFilters: { + ...prev.tempFilters, + [filterId]: { + ...prev.tempFilters[id], + ...filterToSave, + enabled: true, + }, }, - }, - })) - } + } + } + }) } else { useWebhookStore.setState((prev) => ({ tempFilters: { ...prev.tempFilters, [filterId]: { ...info?.defaults } }, @@ -818,7 +830,7 @@ export default function WebhookAdvanced() { icon: 'Save', }, ], - [id, poracleValues], + [id, poracleValues, selectedIds], ) if (!info || !tempFilters) return null diff --git a/src/components/layout/dialogs/webhooks/store.js b/src/components/layout/dialogs/webhooks/store.js index c81999884..f6518df04 100644 --- a/src/components/layout/dialogs/webhooks/store.js +++ b/src/components/layout/dialogs/webhooks/store.js @@ -127,3 +127,19 @@ export const setSelected = (id) => () => { selected: id ? { ...prev.selected, [id]: !prev.selected[id] } : {}, })) } + +/** + * @param {boolean} enabled + * @param {string[]} ids + */ +export const applyToAllWebhooks = (enabled, ids) => { + const selected = new Set(ids) + useWebhookStore.setState((prev) => ({ + tempFilters: Object.fromEntries( + Object.entries(prev.tempFilters).map(([k, v]) => [ + k, + selected.has(k) ? { ...v, enabled } : v, + ]), + ), + })) +} diff --git a/src/components/layout/dialogs/webhooks/tiles/TrackedTile.jsx b/src/components/layout/dialogs/webhooks/tiles/TrackedTile.jsx index 5f9d44d05..acb94aeef 100644 --- a/src/components/layout/dialogs/webhooks/tiles/TrackedTile.jsx +++ b/src/components/layout/dialogs/webhooks/tiles/TrackedTile.jsx @@ -28,7 +28,7 @@ export default function TrackedTile({ index }) { }, })) } - }, [advOpen, id]) + }, [advOpen, id, item]) const onClose = React.useCallback( (newFilter) => { diff --git a/src/components/layout/general/Menu.jsx b/src/components/layout/general/Menu.jsx index 161979c66..58d9c540a 100644 --- a/src/components/layout/general/Menu.jsx +++ b/src/components/layout/general/Menu.jsx @@ -18,7 +18,7 @@ import { applyToAll } from '@services/filtering/applyToAll' import OptionsContainer from '../dialogs/filters/OptionsContainer' import { VirtualGrid } from './VirtualGrid' import { GenericSearch } from '../drawer/ItemSearch' -import { useWebhookStore } from '../dialogs/webhooks/store' +import { applyToAllWebhooks, useWebhookStore } from '../dialogs/webhooks/store' /** * @param {{ @@ -86,10 +86,10 @@ export default function Menu({ name: 'apply_to_all', action: () => (webhookCategory ? useWebhookStore : useLayoutStore).setState({ - advancedFilter: { + [webhookCategory ? 'advanced' : 'advancedFilter']: { open: true, id: 'global', - category, + category: webhookCategory || category, selectedIds: filteredArr, }, }), @@ -98,24 +98,23 @@ export default function Menu({ { name: 'disable_all', action: () => - applyToAll( - { enabled: false }, - category, - filteredArr, - !webhookCategory, - ), + webhookCategory + ? applyToAllWebhooks(false, filteredArr) + : applyToAll({ enabled: false }, category, filteredArr), icon: 'Clear', color: 'error', }, { name: 'enable_all', action: () => - applyToAll( - { enabled: true }, - category, - filteredArr, - !webhookCategory, - ), + webhookCategory + ? applyToAllWebhooks(true, filteredArr) + : applyToAll( + { enabled: true }, + category, + filteredArr, + !webhookCategory, + ), icon: 'Check', color: 'success', }, diff --git a/src/hooks/useTranslateById.js b/src/hooks/useTranslateById.js index 58725b266..497d909cc 100644 --- a/src/hooks/useTranslateById.js +++ b/src/hooks/useTranslateById.js @@ -37,6 +37,14 @@ export function useTranslateById(options = {}) { if (id === 'global' || id === 'all') { return i18n.t(id) } + if ( + id === '0-0' || + id === 'e90' || + id === 'r90' || + id === 't4' || + id === 'i0' + ) + return i18n.t('poke_global') switch (id.charAt(0)) { case 'b': // event stops diff --git a/src/services/Poracle.js b/src/services/Poracle.js index 55870360f..79c5e7af5 100644 --- a/src/services/Poracle.js +++ b/src/services/Poracle.js @@ -1,7 +1,6 @@ // @ts-check import { t } from 'i18next' import { useWebhookStore } from '@components/layout/dialogs/webhooks/store' -import { useMemory } from '@hooks/useMemory' export default class Poracle { static getMapCategory(poracleCategory) { @@ -50,7 +49,6 @@ export default class Poracle { static getId(item) { if (!item) return '' - const { invasions } = useMemory.getState().masterfile const { category } = useWebhookStore.getState() switch (category) { @@ -63,12 +61,7 @@ export default class Poracle { ? 'kecleon' : item.grunt_type === 'showcase' ? 'showcase' - : `i${Object.keys(invasions).find( - (x) => - invasions[x].type?.toLowerCase() === - item.grunt_type.toLowerCase() && - invasions[x].gender === (item.gender || 1), - )}` + : `i${item.real_grunt_id}` case 'lure': return `l${item.lure_id}` case 'gym': @@ -317,7 +310,15 @@ export default class Poracle { switch (category) { case 'invasion': { let name = t( - item.real_grunt_id ? `grunt_${item.real_grunt_id}` : 'poke_global', + item.grunt_type === 'gold-stop' + ? 'gold_stop' + : item.grunt_type === 'kecleon' + ? 'poke_352' + : item.grunt_type === 'showcase' + ? 'showcase' + : item.real_grunt_id + ? `grunt_${item.real_grunt_id}` + : 'poke_global', ) if (!item.gender) name = name.replace(/\(.+?\)/g, `(${t('all')})`) return `${name}${item.clean ? ` | ${t('clean')} ` : ''}${