Skip to content

Commit

Permalink
fix: various webhook things
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 15, 2024
1 parent da656ce commit a4b7db5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
4 changes: 4 additions & 0 deletions packages/types/lib/poracle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,7 @@ export type APIMethod<T extends PoracleAPIInput = PoracleAPIInput> = (

export type ApolloQueryReturn<T extends APIReturnType[keyof APIReturnType]> =
ReturnType<typeof useQuery<{ webhook: T }>>

export type PoracleCategories = keyof PoracleUI

export type AllButHuman = Exclude<PoracleCategories, 'human'>
8 changes: 8 additions & 0 deletions server/src/services/api/Poracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ class PoracleAPI {
human: true,
pokemon: {
sortProp: 'pokemon_id',
identifiers: ['pokemon_id', 'form'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -770,6 +771,7 @@ class PoracleAPI {
},
},
raid: {
identifiers: ['pokemon_id', 'form', 'level'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -846,6 +848,7 @@ class PoracleAPI {
},
},
egg: {
identifiers: ['level'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -913,6 +916,7 @@ class PoracleAPI {
},
},
gym: {
identifiers: ['team'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -982,6 +986,7 @@ class PoracleAPI {
},
},
invasion: {
identifiers: ['grunt_type'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -1034,6 +1039,7 @@ class PoracleAPI {
},
},
lure: {
identifiers: ['lure_id'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -1078,6 +1084,7 @@ class PoracleAPI {
},
},
quest: {
identifiers: ['reward', 'reward_type'],
defaults: {
clean: false,
distance: 0,
Expand Down Expand Up @@ -1144,6 +1151,7 @@ class PoracleAPI {
},
},
nest: {
identifiers: ['pokemon_id', 'form'],
defaults: {
clean: false,
distance: 0,
Expand Down
1 change: 1 addition & 0 deletions src/components/layout/dialogs/webhooks/WebhookAdv.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const skipFields = new Set([
'battle_changes',
'shiny',
'everything_individually',
'all',
])

const wildCards = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export function ProfileSelect() {

const currentProfile = useWebhookStore((s) => s.human.current_profile_no || 0)

/** @type {import('@apollo/client').ApolloQueryResult<{ webhook: { profile: import("@rm/types").PoracleProfile[] } }>} */
const { data: profiles, loading } = useQuery(allProfiles, {
/** @type {import('@apollo/client').QueryResult<{ webhook: { profile: import("@rm/types").PoracleProfile[] } }>} */
const {
data: profiles,
previousData,
loading,
} = useQuery(allProfiles, {
fetchPolicy: 'no-cache',
variables: {
category: 'profiles',
Expand All @@ -52,18 +56,20 @@ export function ProfileSelect() {
[currentProfile],
)

const safeProfiles = (profiles || previousData)?.webhook?.profile

return (
<FormControl sx={{ m: 1 }}>
<InputLabel id="profile-select">{t('select_profile')}</InputLabel>
<Select
id="profile-select"
label={t('select_profile')}
value={currentProfile || ''}
value={safeProfiles ? currentProfile || '' : ''}
onChange={onChange}
style={STYLE}
endAdornment={loading ? <CircularProgress /> : null}
>
{(profiles?.webhook?.profile || []).map((profile) => (
{(safeProfiles || []).map((profile) => (
<MenuItem key={profile.profile_no} value={profile.profile_no}>
{profile.name}
</MenuItem>
Expand Down
29 changes: 11 additions & 18 deletions src/components/layout/drawer/SelectorItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@ import { useMemory } from '@hooks/useMemory'
import { useLayoutStore } from '@hooks/useLayoutStore'
import { useDeepStore, useStorage } from '@hooks/useStorage'
import { checkIfHasAll } from '@services/functions/hasAll'
import Poracle from '@services/Poracle'

import { ColoredTile } from '../general/ColoredTile'
import { useWebhookStore } from '../dialogs/webhooks/store'
import { ToggleTypography } from '../general/ToggleTypography'
import { SQUARE_ITEM } from '../general/VirtualGrid'

/** @param {string} id */
const getOtherData = (id) => {
switch (id.charAt(0)) {
case 'e':
case 'r':
return { level: id.slice(1) }
default:
return { pokemon_id: id.split('-')[0], form: id.split('-')[1] }
}
}

/**
* @template {string} T
* @typedef {{
Expand Down Expand Up @@ -79,16 +69,20 @@ export function StandardItem({ id, category, ...props }) {
)
}

/** @param {BaseProps<import('../dialogs/webhooks/store').WebhookStore['category']>} props */
/** @param {BaseProps<import('@rm/types').AllButHuman>} props */
export function WebhookItem({ id, category, ...props }) {
const filter = useWebhookStore((s) => s.tempFilters[id])
const setFilter = () => {

const setFilter = (newFilter) => {
useWebhookStore.setState((prev) => ({
tempFilters: {
...prev.tempFilters,
[id]: prev.tempFilters[id]
? { ...prev.tempFilters[id], enabled: !prev.tempFilters[id]?.enabled }
: { enabled: true, ...getOtherData(id) },
[id]: newFilter
? {
...newFilter,
enabled: newFilter.enabled,
}
: { enabled: true, ...Poracle.getOtherData(id) },
},
}))
}
Expand Down Expand Up @@ -137,7 +131,6 @@ function SelectorItem({ id, filter, setFilter, onClick, hasAll, easyMode }) {
newFilter.enabled = true
}
setFilter(newFilter)
setFilter(newFilter)
}, [filter, setFilter, hasAll, easyMode])

/** @type {import('@mui/material').IconButtonProps['onClick']} */
Expand All @@ -146,7 +139,7 @@ function SelectorItem({ id, filter, setFilter, onClick, hasAll, easyMode }) {
e.stopPropagation()
onClick()
},
[id],
[onClick],
)

return (
Expand Down
15 changes: 13 additions & 2 deletions src/services/Poracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default class Poracle {
return reactMapFriendly
}

static processor(type, entries, defaults) {
static processor(category, entries, defaults) {
const pvpFields = [
'pvp_ranking_league',
'pvp_ranking_best',
Expand All @@ -200,7 +200,7 @@ export default class Poracle {
'pvpEntry',
]
const dupes = {}
switch (type) {
switch (category) {
case 'egg':
return entries.map((egg) => ({
...defaults,
Expand Down Expand Up @@ -408,4 +408,15 @@ export default class Poracle {
return item.description || ''
}
}

/** @param {string} id */
static getOtherData(id) {
switch (id.charAt(0)) {
case 'e':
case 'r':
return { level: id.slice(1) }
default:
return { pokemon_id: id.split('-')[0], form: id.split('-')[1] }
}
}
}

0 comments on commit a4b7db5

Please sign in to comment.