Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .configref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18095
18276
8 changes: 6 additions & 2 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
sync:
Sync:
name: Check for config changes
runs-on: ubuntu-latest
steps:
Expand All @@ -20,7 +20,7 @@ jobs:
uses: tj-actions/changed-files@v32
with:
files: |
server/src/configs/default.json
server/src/configs/*
- name: Setup Node.js environment
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-node@v3
Expand All @@ -31,6 +31,10 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
run: |
yarn config-check
- name: Generate latest env vars
if: steps.changed-files.outputs.any_changed == 'true'
run: |
yarn gen-env-config
- name: Commit and push changes
if: steps.changed-files.outputs.any_changed == 'true'
uses: devops-infra/action-commit-push@v0.9.0
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
Sync:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v32
with:
files: |
server/src/configs/*.json
- name: Setup Node.js environment
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- name: Generate latest env vars
if: steps.changed-files.outputs.any_changed == 'true'
run: |
yarn gen-env-config
- name: Commit and push changes
if: steps.changed-files.outputs.any_changed == 'true'
uses: devops-infra/action-commit-push@v0.9.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Synced docker env vars with latest config
Docker:
if: ${{ always() }}
needs: Sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.6.9",
"version": "1.7.0",
"description": "React based frontend map.",
"main": "ReactMap.js",
"author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>",
Expand Down
1 change: 1 addition & 0 deletions public/base-locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
"global_search_portals": "Enter Portal Name...",
"global_search_nests": "Enter Nest Pokémon Name...",
"global_search_raids": "Enter Raid Boss Name...",
"global_search_pokemon": "Enter Pokemon Name...",
"raid_level_badges": "Raid Level Badges",
"options": "Options",
"profile": "Profile",
Expand Down
30 changes: 30 additions & 0 deletions server/src/configs/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@
"__format": "number"
}
},
"searchable": {
"quests": {
"__name": "API_SEARCHABLE_QUESTS",
"__format": "boolean"
},
"pokestops": {
"__name": "API_SEARCHABLE_POKESTOPS",
"__format": "boolean"
},
"raids": {
"__name": "API_SEARCHABLE_RAIDS",
"__format": "boolean"
},
"gyms": {
"__name": "API_SEARCHABLE_GYMS",
"__format": "boolean"
},
"portals": {
"__name": "API_SEARCHABLE_PORTALS",
"__format": "boolean"
},
"nests": {
"__name": "API_SEARCHABLE_NESTS",
"__format": "boolean"
},
"pokemon": {
"__name": "API_SEARCHABLE_POKEMON",
"__format": "boolean"
}
},
"queryUpdateHours": {
"pokemon": {
"__name": "API_QUERY_UPDATE_HOURS_POKEMON",
Expand Down
9 changes: 9 additions & 0 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
"submissionCells": 500,
"weather": 30
},
"searchable": {
"quests": true,
"pokestops": true,
"raids": true,
"gyms": true,
"portals": true,
"nests": true,
"pokemon": true
},
"queryUpdateHours": {
"pokemon": 0.25,
"quests": 0.5,
Expand Down
6 changes: 6 additions & 0 deletions server/src/graphql/mapTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ module.exports = gql`
raid_pokemon_gender: Int
raid_pokemon_costume: Int
raid_pokemon_evolution: Int
pokemon_id: Int
form: Int
gender: Int
costume: Int
shiny: Int
iv: Float
}

type SearchQuest {
Expand Down
2 changes: 2 additions & 0 deletions server/src/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ module.exports = {
return []
}
switch (args.category) {
case 'pokemon':
return Db.search('Pokemon', perms, args)
case 'pokestops':
return Db.search('Pokestop', perms, args)
case 'raids':
Expand Down
41 changes: 41 additions & 0 deletions server/src/models/Pokemon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable no-console */
/* eslint-disable no-restricted-syntax */
const { Model, raw, ref } = require('objection')
const i18next = require('i18next')

const { Event } = require('../services/initialization')
const legacyFilter = require('../services/legacyFilter')
const {
api: {
searchResultsLimit,
pvp: { minCp: pvpMinCp, leagues, reactMapHandlesPvp, leagueObj },
queryLimits,
},
Expand Down Expand Up @@ -454,4 +457,42 @@ module.exports = class Pokemon extends Model {
.where(isMad ? 'encounter_id' : 'id', id)
.first()
}

static async search(perms, args, { isMad }, distance) {
const { search, locale, onlyAreas = [] } = args
const pokemonIds = Object.keys(Event.masterfile.pokemon).filter((pkmn) =>
i18next.t(`poke_${pkmn}`, { lng: locale }).toLowerCase().includes(search),
)
const safeTs = args.ts || Math.floor(Date.now() / 1000)
const query = this.query()
.select([distance])
.whereIn('pokemon_id', pokemonIds)
.andWhere(
isMad ? 'disappear_time' : 'expire_timestamp',
'>=',
isMad ? this.knex().fn.now() : safeTs,
)
.limit(searchResultsLimit)
.orderBy('distance')
if (isMad) {
getMadSql(query)
} else {
query.select([
'id',
'lat',
'lon',
'pokemon_id',
'form',
'costume',
'gender',
'iv',
'shiny',
])
}
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
const results = await query
return results.map((poke) => ({ ...poke, iv: perms.iv ? poke.iv : null }))
}
}
4 changes: 4 additions & 0 deletions server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ rootRouter.get('/settings', async (req, res) => {
if (serverSettings.user.valid) {
serverSettings.loggedIn = req.user

serverSettings.config.map.searchable = Object.keys(
config.api.searchable,
).filter((k) => config.api.searchable[k] && serverSettings.user.perms[k])

// keys that are being sent to the frontend but are not options
const ignoreKeys = [
'map',
Expand Down
8 changes: 2 additions & 6 deletions src/components/layout/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import DonorPage from './dialogs/DonorPage'
import Feedback from './dialogs/Feedback'
import ResetFilters from './dialogs/ResetFilters'

const searchable = ['quests', 'pokestops', 'raids', 'gyms', 'portals', 'nests']

export default function Nav({
map,
setManualParams,
Expand Down Expand Up @@ -78,8 +76,6 @@ export default function Nav({
)
const [donorPage, setDonorPage] = useState(false)

const safeSearch = searchable.filter((category) => perms[category])

const toggleDrawer = (open) => (event) => {
if (
event.type === 'keydown' &&
Expand Down Expand Up @@ -137,7 +133,7 @@ export default function Nav({
<FloatingBtn
toggleDrawer={toggleDrawer}
toggleDialog={toggleDialog}
safeSearch={safeSearch}
safeSearch={config.searchable}
isMobile={isMobile}
perms={perms}
webhooks={webhooks}
Expand Down Expand Up @@ -214,7 +210,7 @@ export default function Nav({
>
<Search
toggleDialog={toggleDialog}
safeSearch={safeSearch}
safeSearch={config.searchable}
isMobile={isMobile}
Icons={Icons}
/>
Expand Down
22 changes: 21 additions & 1 deletion src/components/layout/dialogs/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function Search({ safeSearch, toggleDialog, isMobile, Icons }) {
nest_pokemon_id,
nest_pokemon_form,
raid_pokemon_id,
pokemon_id,
} = option

if (quest_reward_type) {
Expand Down Expand Up @@ -88,6 +89,18 @@ export default function Search({ safeSearch, toggleDialog, isMobile, Icons }) {
</div>
)
}
if (pokemon_id) {
const { form, gender, costume, shiny } = option
return (
<NameTT id={[form ? `form_${form}` : '', `poke_${pokemon_id}`]}>
<img
src={Icons.getPokemon(pokemon_id, form, 0, gender, costume, shiny)}
alt={nest_pokemon_form}
style={{ maxWidth: 45, maxHeight: 45 }}
/>
</NameTT>
)
}
if (raid_pokemon_id) {
const {
raid_pokemon_form,
Expand Down Expand Up @@ -216,7 +229,14 @@ export default function Search({ safeSearch, toggleDialog, isMobile, Icons }) {
</Grid>
<Grid item xs={8}>
<Typography variant="caption" style={{ fontWeight: 'bold' }}>
{option.name || getBackupName()}
{safeSearch[searchTab] === 'pokemon'
? `${t(`poke_${option.pokemon_id}`)} ${
option.form &&
t(`form_${option.form}`) !== t('poke_type_1')
? `(${t(`form_${option.form}`)})`
: ''
}${option.iv ? ` - ${option.iv}%` : ''}`
: option.name || getBackupName()}
</Typography>
<br />
{option.quest_title && option.quest_target && (
Expand Down
1 change: 1 addition & 0 deletions src/services/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default class Query {
case 'raids':
case 'nests':
case 'quests':
case 'pokemon':
return searchIndex[category]
case 'webhook':
return searchIndex.poiWebhook
Expand Down
30 changes: 30 additions & 0 deletions src/services/queries/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ export const nests = gql`
}
`

export const pokemon = gql`
${core}
query SearchPokemon(
$search: String!
$category: String!
$lat: Float!
$lon: Float!
$locale: String!
$onlyAreas: [String]
) {
search(
search: $search
category: $category
lat: $lat
lon: $lon
locale: $locale
onlyAreas: $onlyAreas
) {
...CoreSearch
pokemon_id
pokemon_id
form
gender
costume
shiny
iv
}
}
`

export const quests = gql`
query SearchQuests(
$search: String!
Expand Down