const moment = require("moment") const {charactersApi} = require("../../../../../rpdata/api/Character") module.exports = class { onCreate(input) { this.state = { error: null, loading: false, values: { newNick: "", } } } change(key, ev) { this.state.values[key] = ev.target.value } open() { } close() { this.emit("close") } addNick() { if (this.state.loading) { return } const input = {id: this.input.character.id, nick: this.state.values.newNick} this.state.loading = true charactersApi.addNick(input).then((res) => { this.emit("nicks", res.nicks) this.state.values = {newNick: ""} }).catch(errs => { console.warn("Failed to add nick:", errs) 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(() => { this.state.loading = false }) } removeNick(nick) { if (this.state.loading) { return } const input = {id: this.input.character.id, nick} this.state.loading = true charactersApi.removeNick(input).then((res) => { this.emit("nicks", res.nicks) }).catch(errs => { console.warn("Failed to remove nick:", errs) this.state.error = "Failed to remove nick: " + errs[0].message }).then(() => { this.state.loading = false }) } }