Gisle Aune
6 years ago
7 changed files with 127 additions and 1 deletions
-
68marko/page/logs-content/components/edit-post-modal/component.js
-
26marko/page/logs-content/components/edit-post-modal/index.marko
-
4marko/page/logs-content/components/page/component.js
-
1marko/page/logs-content/components/page/index.marko
-
4marko/page/logs-content/components/post/component.js
-
3marko/page/logs-content/components/post/index.marko
-
22rpdata/api/Post.js
@ -0,0 +1,68 @@ |
|||
const moment = require("moment") |
|||
|
|||
const {postApi} = require("../../../../../rpdata/api/Post") |
|||
|
|||
module.exports = class { |
|||
onCreate(input) { |
|||
this.state = { |
|||
error: null, |
|||
loading: false, |
|||
values: { |
|||
time: "", |
|||
kind: "", |
|||
nick: "", |
|||
text: "", |
|||
}, |
|||
} |
|||
|
|||
this.first = false |
|||
} |
|||
|
|||
onInput(input) { |
|||
if (input.post) { |
|||
const {kind, nick, text} = input.post |
|||
const time = moment.utc(input.post.time).format("YYYY-MM-DD HH:mm:ss") |
|||
|
|||
this.state.values = {time, kind, nick, text} |
|||
} |
|||
} |
|||
|
|||
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 = {id: this.input.post.id, time, kind: this.state.values.kind, nick: this.state.values.nick, text: this.state.values.text} |
|||
|
|||
this.state.loading = true |
|||
postApi.edit(input).then(data => { |
|||
this.emit("edited", data) |
|||
this.emit("close") |
|||
}).catch(errs => { |
|||
console.warn("Failed to edit:", errs) |
|||
this.state.error = "Failed to edit: " + 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>Edit Post ${input.post.position}</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")>Alter History</button> |
|||
</modal> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue