Skip to content

Commit 3ee0370

Browse files
committed
refactor: more
1 parent c17d52a commit 3ee0370

5 files changed

Lines changed: 31 additions & 29 deletions

File tree

src/components/popups/BackgroundCard.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const DARK_PALETTE_ENTRIES = Object.entries(
3232
* @param {{
3333
* horizontal?: number
3434
* vertical?: number
35-
* clampWidth?: boolean
3635
* }} [options]
3736
* @returns {React.CSSProperties}
3837
*/

src/features/gym/GymPopup.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import {
3838
import { useAnalytics } from '@hooks/useAnalytics'
3939
import { getTimeUntil } from '@utils/getTimeUntil'
4040
import { formatInterval } from '@utils/formatInterval'
41-
import { usePokemonBackgroundVisuals } from '@hooks/usePokemonBackgroundVisuals'
41+
import {
42+
usePokemonBackgroundVisuals,
43+
usePokemonBackgroundVisual,
44+
} from '@hooks/usePokemonBackgroundVisuals'
4245

4346
import { useWebhook } from './useWebhook'
4447

@@ -273,16 +276,15 @@ function DefendersModal({ gym, onClose }) {
273276
const { t, i18n } = useTranslation()
274277
const theme = useTheme()
275278
const Icons = useMemory((s) => s.Icons)
276-
const getPokemonBackgroundVisuals = usePokemonBackgroundVisuals()
279+
const resolvePokemonBackgroundVisual = usePokemonBackgroundVisuals()
277280
const numFormatter = new Intl.NumberFormat(i18n.language)
278281
const defenders = gym.defenders || []
279282
const updatedMs =
280283
defenders.length &&
281284
defenders[0].deployed_ms + defenders[0].deployed_time * 1000
282285
const now = Date.now()
283-
const fallbackVisuals = React.useMemo(
284-
() => getPokemonBackgroundVisuals(gym.guarding_pokemon_display?.background),
285-
[getPokemonBackgroundVisuals, gym.guarding_pokemon_display?.background],
286+
const fallbackVisuals = usePokemonBackgroundVisual(
287+
gym.guarding_pokemon_display?.background,
286288
)
287289

288290
// Fallback to basic gym data when detailed defender info isn't available
@@ -308,7 +310,6 @@ function DefendersModal({ gym, onClose }) {
308310
const rowContent = (
309311
<DefenderRowLayout
310312
borderColor={fallbackBorderColor}
311-
tooltip={fallbackBackgroundMeta?.tooltip}
312313
imageSrc={fallbackImageSrc}
313314
imageAlt={t(`poke_${gym.guarding_pokemon_id}`)}
314315
showBestBuddy={gym.guarding_pokemon_display?.badge === 1}
@@ -347,7 +348,6 @@ function DefendersModal({ gym, onClose }) {
347348
fallbackRow = (
348349
<BackgroundCard
349350
visuals={fallbackHasBackground ? fallbackVisuals : undefined}
350-
tooltip={fallbackBackgroundMeta?.tooltip}
351351
wrapperProps={
352352
fallbackBackgroundMeta?.tooltip
353353
? { style: { width: '100%' } }
@@ -431,7 +431,7 @@ function DefendersModal({ gym, onClose }) {
431431
const currentCP = Math.round(
432432
fullCP * (0.2 + 0.8 * predictedMotivation),
433433
)
434-
const visuals = getPokemonBackgroundVisuals(def.background)
434+
const visuals = resolvePokemonBackgroundVisual(def.background)
435435
const {
436436
borderColor,
437437
primaryColor,
@@ -638,7 +638,6 @@ function DefendersModal({ gym, onClose }) {
638638
<React.Fragment key={rowKey}>
639639
<BackgroundCard
640640
visuals={hasBackground ? visuals : undefined}
641-
tooltip={backgroundMeta?.tooltip}
642641
wrapperProps={
643642
backgroundMeta?.tooltip
644643
? { style: { width: '100%' } }

src/features/pokemon/PokemonPopup.jsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { StatusIcon } from '@components/StatusIcon'
3030
import { readableProbability } from '@utils/readableProbability'
3131
import { GET_POKEMON_SHINY_STATS } from '@services/queries/pokemon'
3232
import { GET_TAPPABLE_BY_ID } from '@services/queries/tappable'
33-
import { usePokemonBackgroundVisuals } from '@hooks/usePokemonBackgroundVisuals'
33+
import { usePokemonBackgroundVisual } from '@hooks/usePokemonBackgroundVisuals'
3434
import {
3535
BackgroundCard,
3636
createFullBleedSurfaceStyle,
@@ -91,12 +91,7 @@ export function PokemonPopup({ pokemon, iconUrl, isTutorial = false }) {
9191
const timeOfDay = useMemory((s) => s.timeOfDay)
9292
const metaData = useMemory((s) => s.masterfile.pokemon[pokemon_id])
9393
const Icons = useMemory((s) => s.Icons)
94-
const getPokemonBackgroundVisuals = usePokemonBackgroundVisuals()
95-
const backgroundVisuals = React.useMemo(
96-
() => getPokemonBackgroundVisuals(pokemon.background),
97-
[getPokemonBackgroundVisuals, pokemon.background],
98-
)
99-
const backgroundTooltip = backgroundVisuals?.backgroundMeta?.tooltip
94+
const backgroundVisuals = usePokemonBackgroundVisual(pokemon.background)
10095

10196
const userSettings = useStorage((s) => s.userSettings.pokemon)
10297
const pokePerms = isTutorial
@@ -324,7 +319,6 @@ export function PokemonPopup({ pokemon, iconUrl, isTutorial = false }) {
324319
<ErrorBoundary noRefresh style={{}} variant="h5">
325320
<BackgroundCard
326321
visuals={backgroundVisuals}
327-
tooltip={backgroundTooltip}
328322
wrapperProps={{ style: { display: 'block', width: '100%' } }}
329323
surfaceStyle={
330324
backgroundVisuals?.hasBackground

src/features/pokestop/PokestopPopup.jsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ import { useGetAvailable } from '@hooks/useGetAvailable'
3636
import { parseQuestConditions } from '@utils/parseConditions'
3737
import { Img } from '@components/Img'
3838
import { readableProbability } from '@utils/readableProbability'
39-
import { usePokemonBackgroundVisuals } from '@hooks/usePokemonBackgroundVisuals'
39+
import {
40+
usePokemonBackgroundVisuals,
41+
usePokemonBackgroundVisual,
42+
} from '@hooks/usePokemonBackgroundVisuals'
4043

4144
/**
4245
*
@@ -601,15 +604,14 @@ const RewardInfo = ({ with_ar, ...quest }) => {
601604
*
602605
* @param {{
603606
* quest: Omit<import('@rm/types').Quest, 'key'>
604-
* visuals?: ReturnType<ReturnType<typeof usePokemonBackgroundVisuals>>
607+
* visuals?: ReturnType<typeof usePokemonBackgroundVisual>
605608
* }} props
606609
* @returns
607610
*/
608611
const QuestRewardRow = ({ quest, visuals }) => {
609612
const { quest_reward_type, quest_shiny_probability } = quest
610613
const hasBackground = visuals?.hasBackground ?? false
611614
const applyBackground = quest_reward_type === 7 && hasBackground
612-
const backgroundMeta = visuals?.backgroundMeta
613615
const rowContent = (
614616
<Grid container justifyContent="center" alignItems="center">
615617
<Grid
@@ -653,7 +655,6 @@ const QuestRewardRow = ({ quest, visuals }) => {
653655
const wrappedRow = (
654656
<BackgroundCard
655657
visuals={applyBackground ? visuals : undefined}
656-
tooltip={applyBackground ? backgroundMeta?.tooltip : undefined}
657658
wrapperProps={applyBackground ? { style: { width: '100%' } } : undefined}
658659
surfaceStyle={
659660
applyBackground
@@ -992,12 +993,8 @@ const ShowcaseEntry = ({
992993
}) => {
993994
const Icons = useMemory((s) => s.Icons)
994995
const { t } = useTranslation()
995-
const getPokemonBackgroundVisuals = usePokemonBackgroundVisuals()
996-
const visuals = React.useMemo(
997-
() => getPokemonBackgroundVisuals(background),
998-
[background, getPokemonBackgroundVisuals],
999-
)
1000-
const { hasBackground, backgroundMeta } = visuals
996+
const visuals = usePokemonBackgroundVisual(background)
997+
const { hasBackground } = visuals
1001998
const entry = (
1002999
<div className="showcase-entry">
10031000
<div className="showcase-entry-content">
@@ -1044,7 +1041,6 @@ const ShowcaseEntry = ({
10441041
return (
10451042
<BackgroundCard
10461043
visuals={hasBackground ? visuals : undefined}
1047-
tooltip={backgroundMeta?.tooltip}
10481044
wrapperProps={{ style: { width: '100%' } }}
10491045
wrapWhenNoTooltip
10501046
surfaceStyle={

src/hooks/usePokemonBackgroundVisuals.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,17 @@ export function usePokemonBackgroundVisuals() {
174174
[Icons, i18n, locationCards, t, theme],
175175
)
176176
}
177+
178+
/**
179+
* Convenience hook for resolving a single Pokemon background visual record.
180+
*
181+
* @param {number | string | null | undefined} backgroundValue
182+
*/
183+
export function usePokemonBackgroundVisual(backgroundValue) {
184+
const resolveBackgroundVisual = usePokemonBackgroundVisuals()
185+
186+
return React.useMemo(
187+
() => resolveBackgroundVisual(backgroundValue),
188+
[backgroundValue, resolveBackgroundVisual],
189+
)
190+
}

0 commit comments

Comments
 (0)