logs-content: Added add post form

This commit is contained in:
2018-09-30 15:59:28 +02:00
parent 3c35f75f62
commit 3466b1a707
7 changed files with 144 additions and 6 deletions
@@ -0,0 +1,59 @@
const moment = require("moment")
const {postApi} = require("../../../../../rpdata/api/Post")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
time: moment.utc(new Date()).format("YYYY-MM-DD HH:mm:ss"),
kind: "text",
nick: "",
text: "",
},
}
this.first = false
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.first = false
this.emit("close")
}
save() {
if (this.state.loading) {
return
}
const values = this.state.values
let time = new Date(values.time + " UTC")
if (Number.isNaN(time)) {
this.state.error = `Could not parse ${values.time} as date`
return
}
const input = {logId: this.input.logId, time, kind: this.state.values.kind, nick: this.state.values.nick, text: this.state.values.text}
this.state.loading = true
postApi.add(input).then(data => {
this.emit("added", data)
this.emit("close")
}).catch(errs => {
console.warn("Failed to add post:", errs)
this.state.error = "Failed to add post: " + errs[0].message
}).then(() => {
this.state.loading = false
})
}
}
@@ -0,0 +1,26 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<h1>Add Post</h1>
<p key="error" class="color-error">${state.error}</p>
<label>Timestamp</label>
<input key="time" placeholder="Title" class="big" on-change("change", "time") value=state.values.time />
<label>Kind</label>
<select key="kind" class="big" placeholder="Kind" on-change("change", "kind") value=state.values.kind>
<option value="text" selected=(state.values.kind === "text")>Text (text, /npc)</option>
<option value="action" selected=(state.values.kind === "action")>Action (/me, /npca)</option>
<option value="scene" selected=(state.values.kind === "scene")>Scene (/scene)</option>
<option value="annotation.info" selected=(state.values.kind === "annotation.info")>Annotation - Info</option>
<option value="annotation.warning" selected=(state.values.kind === "annotation.warning")>Annotation - Warning</option>
<option value="annotation.error" selected=(state.values.kind === "annotation.error")>Annotation - Error</option>
</select>
<label>Nick</label>
<input key="nick" placeholder="IRC_Nick (You can use non-IRC letters here, like ', but I recommend you don't so the character is found)" class="big" on-change("change", "nick") value=state.values.nick />
<label>Text</label>
<textarea key="text" placeholder="Text" class="tall" on-change("change", "text") value=state.values.text />
<button disabled=state.loading on-click("save")>Add Post</button>
</modal>