Skip to content

Commit c17d52a

Browse files
committed
refactor: reduce dup more
1 parent e7285d7 commit c17d52a

4 files changed

Lines changed: 48 additions & 54 deletions

File tree

src/components/popups/BackgroundCard.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ const DARK_PALETTE_ENTRIES = Object.entries(
2626
return acc
2727
}, {})
2828

29+
/**
30+
* Generates symmetrical margin/padding to let the background artwork bleed.
31+
*
32+
* @param {{
33+
* horizontal?: number
34+
* vertical?: number
35+
* clampWidth?: boolean
36+
* }} [options]
37+
* @returns {React.CSSProperties}
38+
*/
39+
export function createFullBleedSurfaceStyle({
40+
horizontal = 0,
41+
vertical = 0,
42+
} = {}) {
43+
const horizontalPixels = Number(horizontal) || 0
44+
const verticalPixels = Number(vertical) || 0
45+
const widthAdjustment = horizontalPixels * 2
46+
const width = widthAdjustment ? `calc(100% + ${widthAdjustment}px)` : '100%'
47+
return {
48+
margin: `${-verticalPixels}px ${-horizontalPixels}px`,
49+
padding: `${verticalPixels}px ${horizontalPixels}px`,
50+
width,
51+
boxSizing: 'border-box',
52+
}
53+
}
54+
2955
/**
3056
* Applies themed background visuals (and optional tooltip) around popup content.
3157
*

src/features/gym/GymPopup.jsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import { GenderIcon } from '@components/popups/GenderIcon'
3131
import { Navigation } from '@components/popups/Navigation'
3232
import { Coords } from '@components/popups/Coords'
3333
import { TimeStamp } from '@components/popups/TimeStamps'
34-
import { BackgroundCard } from '@components/popups/BackgroundCard'
34+
import {
35+
BackgroundCard,
36+
createFullBleedSurfaceStyle,
37+
} from '@components/popups/BackgroundCard'
3538
import { useAnalytics } from '@hooks/useAnalytics'
3639
import { getTimeUntil } from '@utils/getTimeUntil'
3740
import { formatInterval } from '@utils/formatInterval'
@@ -351,14 +354,7 @@ function DefendersModal({ gym, onClose }) {
351354
: undefined
352355
}
353356
surfaceStyle={
354-
fallbackHasBackground
355-
? {
356-
margin: 0,
357-
padding: 0,
358-
width: '100%',
359-
maxWidth: '100%',
360-
}
361-
: undefined
357+
fallbackHasBackground ? createFullBleedSurfaceStyle({}) : undefined
362358
}
363359
>
364360
{rowContent}
@@ -650,12 +646,7 @@ function DefendersModal({ gym, onClose }) {
650646
}
651647
surfaceStyle={
652648
hasBackground
653-
? {
654-
margin: 0,
655-
padding: 0,
656-
width: '100%',
657-
maxWidth: '100%',
658-
}
649+
? createFullBleedSurfaceStyle({})
659650
: undefined
660651
}
661652
>

src/features/pokemon/PokemonPopup.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ 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'
3333
import { usePokemonBackgroundVisuals } from '@hooks/usePokemonBackgroundVisuals'
34-
import { BackgroundCard } from '@components/popups/BackgroundCard'
34+
import {
35+
BackgroundCard,
36+
createFullBleedSurfaceStyle,
37+
} from '@components/popups/BackgroundCard'
3538

3639
const rowClass = { width: 30, fontWeight: 'bold' }
3740

@@ -326,15 +329,14 @@ export function PokemonPopup({ pokemon, iconUrl, isTutorial = false }) {
326329
surfaceStyle={
327330
backgroundVisuals?.hasBackground
328331
? {
332+
...createFullBleedSurfaceStyle({
333+
horizontal: 20,
334+
vertical: 13,
335+
}),
329336
display: 'flex',
330337
flexDirection: 'column',
331338
flex: '1 1 auto',
332339
alignSelf: 'stretch',
333-
margin: '-13px -20px',
334-
padding: '13px 20px',
335-
width: 'calc(100% + 40px)',
336-
maxWidth: 'none',
337-
boxSizing: 'border-box',
338340
}
339341
: undefined
340342
}

src/features/pokestop/PokestopPopup.jsx

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import { Timer } from '@components/popups/Timer'
2727
import { PowerUp } from '@components/popups/PowerUp'
2828
import { NameTT } from '@components/popups/NameTT'
2929
import { TimeStamp } from '@components/popups/TimeStamps'
30-
import { BackgroundCard } from '@components/popups/BackgroundCard'
30+
import {
31+
BackgroundCard,
32+
createFullBleedSurfaceStyle,
33+
} from '@components/popups/BackgroundCard'
3134
import { useAnalytics } from '@hooks/useAnalytics'
3235
import { useGetAvailable } from '@hooks/useGetAvailable'
3336
import { parseQuestConditions } from '@utils/parseConditions'
@@ -599,27 +602,11 @@ const RewardInfo = ({ with_ar, ...quest }) => {
599602
* @param {{
600603
* quest: Omit<import('@rm/types').Quest, 'key'>
601604
* visuals?: ReturnType<ReturnType<typeof usePokemonBackgroundVisuals>>
602-
* hasBackground?: boolean
603605
* }} props
604606
* @returns
605607
*/
606-
const QuestRewardRow = ({ quest, visuals: visualsProp }) => {
607-
const { quest_reward_type, quest_background, quest_shiny_probability } = quest
608-
const getPokemonBackgroundVisuals = usePokemonBackgroundVisuals()
609-
const visuals = React.useMemo(() => {
610-
if (visualsProp) {
611-
return visualsProp
612-
}
613-
if (quest_reward_type !== 7) {
614-
return undefined
615-
}
616-
return getPokemonBackgroundVisuals(quest_background)
617-
}, [
618-
visualsProp,
619-
getPokemonBackgroundVisuals,
620-
quest_background,
621-
quest_reward_type,
622-
])
608+
const QuestRewardRow = ({ quest, visuals }) => {
609+
const { quest_reward_type, quest_shiny_probability } = quest
623610
const hasBackground = visuals?.hasBackground ?? false
624611
const applyBackground = quest_reward_type === 7 && hasBackground
625612
const backgroundMeta = visuals?.backgroundMeta
@@ -670,13 +657,7 @@ const QuestRewardRow = ({ quest, visuals: visualsProp }) => {
670657
wrapperProps={applyBackground ? { style: { width: '100%' } } : undefined}
671658
surfaceStyle={
672659
applyBackground
673-
? {
674-
margin: '0 -21px',
675-
padding: '0 21px',
676-
width: 'calc(100% + 42px)',
677-
maxWidth: 'calc(100% + 42px)',
678-
boxSizing: 'border-box',
679-
}
660+
? createFullBleedSurfaceStyle({ horizontal: 21 })
680661
: undefined
681662
}
682663
>
@@ -1068,13 +1049,7 @@ const ShowcaseEntry = ({
10681049
wrapWhenNoTooltip
10691050
surfaceStyle={
10701051
hasBackground
1071-
? {
1072-
margin: '0 -21px',
1073-
padding: '0 21px',
1074-
width: 'calc(100% + 42px)',
1075-
maxWidth: 'none',
1076-
boxSizing: 'border-box',
1077-
}
1052+
? createFullBleedSurfaceStyle({ horizontal: 21 })
10781053
: undefined
10791054
}
10801055
>

0 commit comments

Comments
 (0)