Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/features/gym/GymPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const DropdownOptions = ({
raid_level,
}) => {
const { t } = useTranslation()
const { perms } = useMemory((s) => s.auth)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { perms } = useMemory((s) => s.auth)
const admin = useMemory((s) => s.auth.perms.admin)

I know the way you have it is how it was done in the Nest Popup component, but that isn't the "correct" way and should be fixed there too. For new components though, I would prefer if you could use the way I suggested on Discord. That goes for the rest of the popups too. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes included. I still have to do it for spawnpoints and routes. This ones are going to be more difficult for me since I have to add the menu...


const { gyms, raids, gymBadges, webhooks } = useMemory((s) => s.auth.perms)
const gymValidDataLimit = useMemory((s) => s.gymValidDataLimit)
Expand Down Expand Up @@ -208,6 +209,11 @@ const DropdownOptions = ({
})
}

const copyId = () => {
handleClose()
navigator.clipboard.writeText(id)
}

const options = [{ name: 'hide', action: handleHide }]

if (gyms) {
Expand Down Expand Up @@ -251,6 +257,10 @@ const DropdownOptions = ({
})
}

if (perms.admin) {
options.push({ name: 'Copy ID', action: copyId })
}

return options.filter(Boolean).map((option) => (
<MenuItem key={option.key || option.name} onClick={option.action} dense>
{typeof option.name === 'string' ? t(option.name) : option.name}
Expand Down
9 changes: 9 additions & 0 deletions src/features/nest/NestPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@ export function NestPopup({
setDeepStore(`filters.nests.filter.${key}.enabled`, false)
}

const copyId = () => {
setAnchorEl(null)
navigator.clipboard.writeText(id)
}

useAnalytics('Popup', `Name: ${name} Pokemon: ${pokemon_id}`, 'Nest')

const options = [
{ name: 'hide', action: handleHide },
{ name: 'exclude', action: handleExclude },
]

if (perms.admin) {
options.push({ name: 'Copy ID', action: copyId })
}

return (
<ErrorBoundary noRefresh variant="h5">
<Grid
Expand Down
11 changes: 11 additions & 0 deletions src/features/pokestop/PokestopPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ const MenuActions = ({
invasions,
}) => {
const { t } = useTranslation()
const { perms } = useMemory((s) => s.auth)
const masterfile = useMemory((s) => s.masterfile)
const filters = useStorage((s) => s.filters)

Expand Down Expand Up @@ -354,6 +355,11 @@ const MenuActions = ({
})
}

const copyId = () => {
setAnchorEl(null)
navigator.clipboard.writeText(id)
}

const options = [{ name: 'hide', action: handleHide }]

if (hasQuest) {
Expand Down Expand Up @@ -459,6 +465,11 @@ const MenuActions = ({
}
options.push({ name: 'timer', action: handleTimer })
}

if (perms.admin) {
options.push({ name: 'Copy ID', action: copyId })
}

return (
<Grid xs={2} textAlign="right">
<IconButton aria-haspopup="true" onClick={handleClick} size="large">
Expand Down
41 changes: 40 additions & 1 deletion src/features/spawnpoint/SpawnpointPopup.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// @ts-check
import * as React from 'react'
import Typography from '@mui/material/Typography'
import Menu from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'
import { useTranslation } from 'react-i18next'

import { useMemory } from '@store/useMemory'
import { ErrorBoundary } from '@components/ErrorBoundary'
import { dayCheck } from '@utils/dayCheck'

Expand All @@ -11,14 +14,50 @@ import { dayCheck } from '@utils/dayCheck'
* @param {import('@rm/types').Spawnpoint} props
* @returns
*/
export function SpawnpointPopup({ despawn_sec, lat, lon, updated }) {
export function SpawnpointPopup({ id, despawn_sec, lat, lon, updated }) {
const { t } = useTranslation()
const { perms } = useMemory((s) => s.auth)

const [anchorEl, setAnchorEl] = React.useState(null)

const minute = despawn_sec > 60 ? Math.round(despawn_sec / 60) : despawn_sec
const minuteFixed = minute < 10 ? `0${minute}` : minute

const handleClose = () => {
setAnchorEl(null)
}

const copyId = () => {
setAnchorEl(null)
navigator.clipboard.writeText(id)
}

const options = []

if (perms.admin) {
options.push({ name: 'Copy ID', action: copyId })
}

return (
<ErrorBoundary noRefresh style={{}} variant="h5">
<Menu
anchorEl={anchorEl}
keepMounted
open={!!anchorEl}
onClose={handleClose}
PaperProps={{
style: {
maxHeight: 216,
minWidth: '20ch',
},
}}
>
{options.map((option) => (
<MenuItem key={option.key || option.name} onClick={option.action}>
{typeof option.name === 'string' ? t(option.name) : option.name}
</MenuItem>
))}
</Menu>
<Typography variant="h5" align="center">
{t('spawnpoint')}
</Typography>
Expand Down