Gisle Aune
6 years ago
7 changed files with 144 additions and 6 deletions
-
59marko/page/logs-content/components/add-post-modal/component.js
-
26marko/page/logs-content/components/add-post-modal/index.marko
-
5marko/page/logs-content/components/logs-content-menu/component.js
-
4marko/page/logs-content/components/logs-content-menu/index.marko
-
20marko/page/logs-content/components/page/component.js
-
4marko/page/logs-content/components/page/index.marko
-
32rpdata/api/Post.js
@ -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> |
@ -0,0 +1,5 @@ |
|||||
|
module.exports = class { |
||||
|
select(value) { |
||||
|
this.emit("select", value) |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue