Skip to content

Commit

Permalink
feat: station searching
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Sep 7, 2024
1 parent d87dd0e commit fbf3b6d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
4 changes: 3 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"portals": true,
"nests": true,
"pokemon": true,
"invasions": true
"invasions": true,
"stations": true
},
"queryUpdateHours": {
"pokemon": 0.17,
Expand Down Expand Up @@ -115,6 +116,7 @@
},
"portalUpdateLimit": 30,
"weatherCellLimit": 3,
"stationUpdateLimit": 30,
"searchResultsLimit": 15,
"searchSoftKmLimit": 10,
"searchHardKmLimit": 100,
Expand Down
3 changes: 2 additions & 1 deletion packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -795,5 +795,6 @@
"all_stations": "All Power Spots",
"search_battles": "Search Battles",
"started": "Started",
"ended": "Ended"
"ended": "Ended",
"global_search_stations": "Search Power Spots"
}
2 changes: 2 additions & 0 deletions server/src/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ const resolvers = {
return perms.portals ? Db.search('Portal', perms, args) : []
case 'nests':
return perms.nests ? Db.search('Nest', perms, args) : []
case 'stations':
return perms.stations ? Db.search('Station', perms, args) : []
default:
return []
}
Expand Down
34 changes: 33 additions & 1 deletion server/src/models/Station.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const { Model } = require('objection')
// const config = require('@rm/config')
const config = require('@rm/config')

const { getAreaSql } = require('../utils/getAreaSql')

Expand Down Expand Up @@ -116,6 +116,38 @@ class Station extends Model {
]),
}
}

/**
*
* @param {import("@rm/types").Permissions} perms
* @param {object} args
* @param {import("@rm/types").DbContext} context
* @param {ReturnType<typeof import('objection').raw>} distance
* @param {ReturnType<typeof import("server/src/utils/getBbox").getBboxFromCenter>} bbox
* @returns {Promise<import("@rm/types").FullStation[]>}
*/
static async search(perms, args, { isMad }, distance, bbox) {
const { areaRestrictions } = perms
const { onlyAreas = [], search = '' } = args
const { searchResultsLimit, stationUpdateLimit } = config.getSafe('api')

const query = this.query()
.select(['name', 'id', 'lat', 'lon', distance])
.whereILike('name', `%${search}%`)
.whereBetween('lat', [bbox.minLat, bbox.maxLat])
.andWhereBetween('lon', [bbox.minLon, bbox.maxLon])
.andWhere(
'updated',
'>',
Date.now() / 1000 - stationUpdateLimit * 60 * 60 * 24,
)
.limit(searchResultsLimit)
.orderBy('distance')
if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
return query
}
}

module.exports = { Station }
6 changes: 5 additions & 1 deletion src/features/search/OptionImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ function InvasionImage({ grunt_type, confirmed }) {

function Misc() {
const { searchTab } = useStorage.getState()
const miscIcon = useMemory((s) => s.Icons.getMisc(searchTab))
const miscIcon = useMemory((s) =>
searchTab === 'stations'
? s.Icons.getStation()
: s.Icons.getMisc(searchTab),
)
return <Img src={miscIcon} alt={searchTab} maxHeight={45} maxWidth={45} />
}

Expand Down
2 changes: 2 additions & 0 deletions src/features/search/renderOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { OptionImageMemo } from './OptionImage'
/** @param {string} tab */
const getBackupName = (tab) => {
switch (tab) {
case 'stations':
return 'unknown_station'
case 'quests':
case 'pokestops':
return 'unknown_pokestop'
Expand Down
15 changes: 9 additions & 6 deletions src/services/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,12 @@ export class UAssets {
getMisc(fileName = '') {
try {
const miscClass = this[this.selected.misc]?.class

const singular = fileName.slice(0, -1)
if (miscClass.has('misc', fileName)) {
return miscClass.misc(fileName)
}
if (
fileName.endsWith('s') &&
miscClass.has('misc', fileName.slice(0, -1))
) {
return miscClass.misc(fileName.slice(0, -1))
if (fileName.endsWith('s') && miscClass.has('misc', singular)) {
return miscClass.misc(singular)
}
if (!fileName.endsWith('s') && miscClass.has('misc', `${fileName}s`)) {
return miscClass.misc(`${fileName}s`)
Expand All @@ -540,6 +537,12 @@ export class UAssets {
) {
return this[this.selected[fileName]].class[fileName]('0')
}
if (
this[this.selected[singular]]?.path &&
this[this.selected[singular]].class.has(singular, `0`)
) {
return this[this.selected[singular]].class[singular]('0')
}
return miscClass.misc('0')
} catch (e) {
console.error(`[${this.assetType.toUpperCase()}]`, e)
Expand Down

0 comments on commit fbf3b6d

Please sign in to comment.