Browse Source

data: Added unknown nick list to character add and nicks modal.

1.2
Gisle Aune 6 years ago
parent
commit
7c1623493a
  1. 17
      marko/components/unknown-nick-list/component.js
  2. 3
      marko/components/unknown-nick-list/index.marko
  3. 16
      marko/components/unknown-nick-list/style.less
  4. 8
      marko/page/data/components/add-character-modal/component.js
  5. 8
      marko/page/data/components/add-character-modal/index.marko
  6. 19
      marko/page/data/components/character-nicks-modal/component.js
  7. 3
      marko/page/data/components/character-nicks-modal/index.marko
  8. 13
      rpdata/api/Character.js

17
marko/components/unknown-nick-list/component.js

@ -0,0 +1,17 @@
const {charactersApi} = require("../../../rpdata/api/Character")
module.exports = class {
onCreate() {
this.state = {
nicks: [],
}
}
onMount() {
charactersApi.unknownNicks(100).then(unknowns => {
this.state.nicks = unknowns.map(u => u.nick)
}).catch(err => {
console.warn("Failed to get unknown nicks:", err)
})
}
}

3
marko/components/unknown-nick-list/index.marko

@ -0,0 +1,3 @@
<div class="unknown-nick-list">
<div for(nick in state.nicks) on-click("emit", "select", nick) key=nick class="nick">${nick}</div>
</div>

16
marko/components/unknown-nick-list/style.less

@ -0,0 +1,16 @@
div.unknown-nick-list {
padding: 0.5em 0;
div.nick {
display: inline-block;
padding: 0.25em 0.5ch;
margin: 2px;
background-color: #111;
color: #881;
}
div.nick:hover {
cursor: pointer;
background-color: #222;
color: #CC2;
}
}

8
marko/page/data/components/add-character-modal/component.js

@ -33,6 +33,14 @@ module.exports = class {
this.emit("close") this.emit("close")
} }
selectUnknown(nick) {
this.state.values = Object.assign({}, this.state.values, {
nick: nick,
name: nick.replace(/_/g, " ").replace(/`/g, "'"),
shortName: (!nick.includes("_") && nick.includes("`")) ? nick.split("`")[0] : "",
})
}
save() { save() {
if (this.state.loading) { if (this.state.loading) {
return return

8
marko/page/data/components/add-character-modal/index.marko

@ -21,4 +21,12 @@
<textarea key="description" placeholder="Description" on-change("change", "description") value=state.values.description /> <textarea key="description" placeholder="Description" on-change("change", "description") value=state.values.description />
<button disabled=state.loading on-click("save")>Save</button> <button disabled=state.loading on-click("save")>Save</button>
<h2>Unknown Nicks</h2>
<p>After you're done adding the one you're here for, why not take a look at the unknown nicks discovered in the last log character updates?</p>
<p>Clicking one will change the nick in the form above, and add a guess for what the full name is.</p>
<if-permitted not user=input.user permission="character.add">
<p class="color-danger">You don't have permission to set a different author on characters, so only add your own.</p>
</if-permitted>
<unknown-nick-list on-select("selectUnknown") />
</modal> </modal>

19
marko/page/data/components/character-nicks-modal/component.js

@ -39,7 +39,24 @@ module.exports = class {
}).catch(errs => { }).catch(errs => {
console.warn("Failed to add nick:", errs) console.warn("Failed to add nick:", errs)
this.state.error = "Failed to add nick: " + errs[0].message
this.state.error = errs[0].message
}).then(() => {
this.state.loading = false
})
}
selectUnknown(nick) {
if (this.state.loading) {
return
}
const input = {id: this.input.character.id, nick}
this.state.loading = true
charactersApi.addNick(input).then((res) => {
this.emit("nicks", res.nicks)
}).catch(errs => {
this.state.error = errs[0].message
}).then(() => { }).then(() => {
this.state.loading = false this.state.loading = false
}) })

3
marko/page/data/components/character-nicks-modal/index.marko

@ -15,4 +15,7 @@
<button disabled=state.loading on-click("removeNick", nick)>Remove</button> <button disabled=state.loading on-click("removeNick", nick)>Remove</button>
</div> </div>
<h2>Unknown Nicks</h2>
<p>These are the 100 most common nicks in the logs, maybe one of these belongs to <strong>${input.character.name}</strong>?</p>
<unknown-nick-list key="un-list" on-select("selectUnknown") />
</modal> </modal>

13
rpdata/api/Character.js

@ -190,6 +190,19 @@ class ChracterAPI {
return removeCharacter return removeCharacter
}) })
} }
unknownNicks(limit = 100) {
return query(`
query UnknownNicks($limit: Int!) {
unknownNicks(filter: {limit: $limit}) {
nick
score
}
}
`, {limit}).then(({unknownNicks}) => {
return unknownNicks
})
}
} }
module.exports = { Character, charactersApi: new ChracterAPI } module.exports = { Character, charactersApi: new ChracterAPI }
Loading…
Cancel
Save