diff --git a/index.js b/index.js
index 56390f12c..38827c799 100644
--- a/index.js
+++ b/index.js
@@ -96,6 +96,7 @@ const typeDefs = gql`
topPlayers (weapon: String!): topPlayer!
weaponPlacementStats(weapon: String!): [Int!]!
playerInfo(uid: String!): PlayerWithPlacements!
+ searchForPlayers(name: String! exact: Boolean): [Placement]!
}
type Mutation {
@@ -322,6 +323,46 @@ const resolvers = {
})
return { player, placements }
+ },
+ searchForPlayers: async (root, args) => {
+ let placements = []
+ if (args.exact) {
+ placements = await Placement
+ .find({ name: args.name })
+ .sort({ "x_power": "desc" })
+ .limit(100)
+ .select({ name: 1, weapon: 1, x_power: 1, unique_id: 1})
+ .catch(e => {
+ throw new UserInputError(e.message, {
+ invalidArgs: args,
+ })
+ })
+ } else {
+ placements = await Placement
+ .find({ name: { "$regex": args.name, "$options": "i" }})
+ .sort({ "x_power": "desc" })
+ .limit(100)
+ .select({ name: 1, weapon: 1, x_power: 1, unique_id: 1})
+ .catch(e => {
+ throw new UserInputError(e.message, {
+ invalidArgs: args,
+ })
+ })
+ }
+
+ let uids = []
+
+ return placements.filter(p => {
+ if (uids.length === 21) {
+ return false
+ }
+ const bool = uids.includes(p.unique_id)
+ if (bool) {
+ return false
+ }
+ uids.push(p.unique_id)
+ return true
+ })
}
}
}
diff --git a/react-ui/src/components/InfoPlayer.js b/react-ui/src/components/InfoPlayer.js
index 1924aaa34..67b248647 100644
--- a/react-ui/src/components/InfoPlayer.js
+++ b/react-ui/src/components/InfoPlayer.js
@@ -60,6 +60,15 @@ const InfoPlayer = ({ uid }) => {
{playerData.twitter ? : null} {playerData.alias ? playerData.alias : playerData.name}
{playerData.twitter ? : null}
+ {playerData.topTotalScore ? <>Total Power: {playerData.topTotalScore}
> : null}
+ {playerData.topShooterScore ? <>Shooter Power: {playerData.topShooterScore}
> : null}
+ {playerData.topBlasterScore ? <>Blaster Power: {playerData.topBlasterScore}
> : null}
+ {playerData.topRollerScore ? <>Roller Power: {playerData.topRollerScore}
> : null}
+ {playerData.topChargerScore ? <>Charger Power: {playerData.topChargerScore}
> : null}
+ {playerData.topSlosherScore ? <>Slosher Power: {playerData.topSlosherScore}
> : null}
+ {playerData.topSplatlingScore ? <>Splatling Power: {playerData.topSplatlingScore}
> : null}
+ {playerData.topDualiesScore ? <>Dualies Power: {playerData.topDualiesScore}
> : null}
+ {playerData.topBrellaScore ? <>Brella Power: {playerData.topBrellaScore}
> : null}
diff --git a/react-ui/src/components/NotFound.js b/react-ui/src/components/NotFound.js
index a86655c03..639356e8a 100644
--- a/react-ui/src/components/NotFound.js
+++ b/react-ui/src/components/NotFound.js
@@ -50,7 +50,7 @@ const NotFound = () => {
- ...not unlike {mapObject.name} can't be found in Splatoon 2
+ ...not unlike how {mapObject.name} can't be found in Splatoon 2
>
)
diff --git a/react-ui/src/components/XSearch.js b/react-ui/src/components/XSearch.js
index 66c7731b2..694609431 100644
--- a/react-ui/src/components/XSearch.js
+++ b/react-ui/src/components/XSearch.js
@@ -4,11 +4,13 @@ import { Route, withRouter } from 'react-router-dom'
import WeaponForm from '../components/WeaponForm'
import InfoWeapon from '../components/InfoWeapon'
import InfoPlayer from '../components/InfoPlayer'
+import XSearchResults from '../components/XSearchResults'
import weaponDict from '../utils/english_internal.json'
const XSearch = withRouter(({ history, setMenuSelection }) => {
const [weaponForm, setWeaponForm] = useState('')
const [playerForm, setPlayerForm] = useState('')
+ const [exact, setExact] = useState(false)
useEffect(() => {
setMenuSelection('search')
document.title = "X Rank Top 500 Search - sendou.ink"
@@ -22,13 +24,17 @@ const XSearch = withRouter(({ history, setMenuSelection }) => {
or
+ setPlayerForm(event.target.value)} />
-
+
+ {playerForm.length !== 999 ? null : }
@@ -38,6 +44,6 @@ const XSearch = withRouter(({ history, setMenuSelection }) => {
} />
)
-}) //alemmalle buttonille onChange uncontrolled?
+}) //weapon forming renderöinti liian raskas
export default XSearch
\ No newline at end of file
diff --git a/react-ui/src/components/XSearchResults.js b/react-ui/src/components/XSearchResults.js
new file mode 100644
index 000000000..29a31d50b
--- /dev/null
+++ b/react-ui/src/components/XSearchResults.js
@@ -0,0 +1,54 @@
+import React from 'react'
+import { withRouter } from 'react-router-dom'
+import { useQuery } from 'react-apollo-hooks'
+import { Loader, Message, Grid, Button, Header } from 'semantic-ui-react'
+import { searchForPlayers } from '../graphql/queries/searchForPlayers'
+
+const XSearchResults = withRouter(({ history, name, exact }) => {
+ const result = useQuery(searchForPlayers, {variables: { name, exact }})
+
+ if (result.loading) {
+ return
+ }
+ if (result.error) {
+ return {result.error.message}
+ }
+ const searchResult = result.data['searchForPlayers']
+ if (searchResult.length === 0) {
+ return
+ }
+ return (
+
+
+ {searchResult.length > 20 ? : null}
+
+ {searchResult.map(r => {
+ return (
+
+
+ {r.name} ({r.x_power} with {r.weapon})
+
+
+
+
+
+
+ )
+ })}
+
+
+ )
+
+})
+
+export default XSearchResults
\ No newline at end of file
diff --git a/react-ui/src/graphql/queries/searchForPlayers.js b/react-ui/src/graphql/queries/searchForPlayers.js
new file mode 100644
index 000000000..480771eed
--- /dev/null
+++ b/react-ui/src/graphql/queries/searchForPlayers.js
@@ -0,0 +1,12 @@
+import { gql } from 'apollo-boost'
+
+export const searchForPlayers = gql`
+query searchForPlayers($name: String!, $exact: Boolean) {
+ searchForPlayers(name: $name, exact: $exact) {
+ name
+ x_power
+ weapon
+ unique_id
+ }
+}
+`
\ No newline at end of file