Skip to content

Commit

Permalink
fix: add missing copy coords menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Sep 12, 2024
1 parent a1776f1 commit 32b22ff
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 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 @@ -808,5 +808,6 @@
"stationed_pokemon": "Stationed Pokémon",
"attack_bonus": "Attack Bonus",
"no_stationed_pokemon": "No Pokémon Have Been Set",
"battle_bonus": "Battle Bonus"
"battle_bonus": "Battle Bonus",
"copy_coordinates": "Copy Coordinates"
}
6 changes: 5 additions & 1 deletion src/components/inputs/ExpandCollapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export function CollapseWithState({
}

/**
* @param {import('@mui/material').BoxProps} props
* Wrapper for a layout that can be expanded or collapsed. Intended to be used with 3 children.
*
* @param {{
* children: [React.ReactNode, React.ReactNode, React.ReactNode]
* } & Omit<import('@mui/material').BoxProps, 'children'>} props
*/
export function ExpandCollapse({ children, ...props }) {
return (
Expand Down
13 changes: 13 additions & 0 deletions src/components/popups/Coords.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
import * as React from 'react'
import Typography from '@mui/material/Typography'
import MenuItem from '@mui/material/MenuItem'
import { useTranslation } from 'react-i18next'

/**
*
Expand All @@ -14,3 +16,14 @@ export function Coords({ lat, lon }) {
</Typography>
)
}

export function CopyCoords({ lat, lon }) {
const { t } = useTranslation()

const copy = React.useCallback(
() => navigator.clipboard.writeText(`${lat}, ${lon}`),
[lat, lon],
)

return <MenuItem onClick={copy}>{t('copy_coordinates')}</MenuItem>
}
13 changes: 10 additions & 3 deletions src/features/station/StationPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import LockOpenIcon from '@mui/icons-material/LockOpen'
import LockIcon from '@mui/icons-material/Lock'

import { useMemory } from '@store/useMemory'
import { setDeepStore } from '@store/useStorage'
import { setDeepStore, useGetDeepStore } from '@store/useStorage'
import { Navigation } from '@components/popups/Navigation'
import { useTranslateById } from '@hooks/useTranslateById'
import { PokeType } from '@components/popups/PokeType'
Expand All @@ -36,6 +36,7 @@ import {
} from '@components/inputs/ExpandCollapse'
import { VirtualGrid } from '@components/virtual/VirtualGrid'
import { getStationAttackBonus } from '@utils/getAttackBonus'
import { CopyCoords } from '@components/popups/Coords'

import { useGetStationMons } from './useGetStationMons'

Expand All @@ -55,7 +56,6 @@ export function StationPopup(station) {
field="popups.stationExtras"
disabled={!station.total_stationed_pokemon}
/>

<CollapseWithState
field="popups.stationExtras"
in={!!station.total_stationed_pokemon}
Expand Down Expand Up @@ -127,7 +127,13 @@ function StationMenu({
battle_level,
battle_pokemon_id,
battle_pokemon_form,
lat,
lon,
}) {
const copyCoords = useGetDeepStore(
'userSettings.stations.enableStationPopupCoords',
false,
)
const [anchorEl, setAnchorEl] = React.useState(null)
const { t } = useTranslation()

Expand Down Expand Up @@ -190,6 +196,7 @@ function StationMenu({
{t(option.name)}
</MenuItem>
))}
{copyCoords && <CopyCoords lat={lat} lon={lon} />}
</Menu>
</>
)
Expand Down Expand Up @@ -280,7 +287,7 @@ function StationAttackBonus({ total_stationed_pokemon }) {
max={4}
/>
<Typography variant="caption">
{t('battle_bonus')} &nbsp;({total_stationed_pokemon})
{t('battle_bonus')} &nbsp;({total_stationed_pokemon} / 40)
</Typography>
</Stack>
)
Expand Down
2 changes: 1 addition & 1 deletion src/services/fetches.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function login(user, endpoint = '/auth/local/callback') {

/**
*
* @param {Error} error
* @param {Error & { uuid: string }} error
* @returns {Promise<Response | FetchError>}
*/
export async function sendError(error) {
Expand Down

0 comments on commit 32b22ff

Please sign in to comment.