Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export interface Defender extends PokemonDisplay {
cp_now: number
}

export interface Rsvp {
timeslot: number
going_count: number
maybe_count: number
}

export interface Gym {
id: string
lat: number
Expand All @@ -68,6 +74,7 @@ export interface Gym {
guarding_pokemon_id: number
guarding_pokemon_display: PokemonDisplay
defenders: Defender[]
rsvps: Rsvp[]
available_slots: number
team_id: number
raid_level: number
Expand Down
1 change: 1 addition & 0 deletions server/src/graphql/typeDefs/scanner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Gym {
guarding_pokemon_id: Int
guarding_pokemon_display: JSON
defenders: JSON
rsvps: JSON
available_slots: Int
team_id: Int
raid_level: Int
Expand Down
4 changes: 4 additions & 0 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const gymFields = [
'guarding_pokemon_id',
'guarding_pokemon_display',
'defenders',
'rsvps',
'total_cp',
'power_up_points',
'power_up_level',
Expand Down Expand Up @@ -383,6 +384,9 @@ class Gym extends Model {
if (typeof gym.defenders === 'string' && gym.defenders) {
newGym.defenders = JSON.parse(gym.defenders)
}
if (typeof gym.rsvps === 'string' && gym.rsvps) {
newGym.rsvps = JSON.parse(gym.rsvps)
}
}
if (
onlyRaids &&
Expand Down
61 changes: 61 additions & 0 deletions src/features/gym/GymPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ export function GymPopup({ hasRaid, hasHatched, raidIconUrl, ...gym }) {
)
}

const formatTime = (timestamp) => {
const locale = localStorage.getItem('i18nextLng') || 'en'
return new Date(timestamp).toLocaleTimeString(locale, {
hour: '2-digit',
minute: '2-digit',
})
}

const nowSec = Math.floor(Date.now() / 1000)
const raidStart = Number(gym.raid_spawn_timestamp ?? 0)
const raidEnd = Number(gym.raid_end_timestamp ?? 0)

const filteredRsvps =
gym.rsvps?.filter((entry) => {
const etsSec = entry.timeslot / 1000
return etsSec >= nowSec && etsSec >= raidStart && etsSec <= raidEnd
}) || []

return (
<ErrorBoundary noRefresh style={{}} variant="h5">
<Grid
Expand Down Expand Up @@ -144,6 +162,49 @@ export function GymPopup({ hasRaid, hasHatched, raidIconUrl, ...gym }) {
{Boolean(
gym.raid_pokemon_id && gym.raid_battle_timestamp >= ts,
) && <Timer start {...gym} hasHatched={hasHatched} />}
{filteredRsvps.length > 0 && (
<Grid xs={12}>
<Grid
container
direction="column"
alignItems="center"
style={{ margin: '2px 0' }}
>
<small
style={{
fontWeight: 'bold',
fontSize: '0.9rem',
marginBottom: 4,
}}
>
<Typography variant="subtitle1">RSVP</Typography>
</small>
<Grid container justifyContent="center" spacing={1}>
{filteredRsvps.slice(0, 3).map((entry) => (
<Grid
key={entry.timeslot}
xs="auto"
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
borderRadius: '6px',
paddingTop: '4px',
fontSize: '0.80rem',
minWidth: 50,
textAlign: 'center',
}}
>
<div>{formatTime(entry.timeslot)}</div>
<div style={{ fontSize: '0.75rem', opacity: 0.8 }}>
{entry.going_count} / {entry.maybe_count}
</div>
</Grid>
))}
</Grid>
</Grid>
</Grid>
)}
<Timer {...gym} hasHatched={hasHatched} />
</Grid>
</Collapse>
Expand Down
1 change: 1 addition & 0 deletions src/services/queries/gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const gym = gql`
guarding_pokemon_id
guarding_pokemon_display
defenders
rsvps
total_cp
badge
power_up_level
Expand Down
Loading