diff --git a/marko/page/logs-content/components/edit-post-modal/component.js b/marko/page/logs-content/components/edit-post-modal/component.js
new file mode 100644
index 0000000..981487f
--- /dev/null
+++ b/marko/page/logs-content/components/edit-post-modal/component.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
+ })
+ }
+}
\ No newline at end of file
diff --git a/marko/page/logs-content/components/edit-post-modal/index.marko b/marko/page/logs-content/components/edit-post-modal/index.marko
new file mode 100644
index 0000000..c7e6277
--- /dev/null
+++ b/marko/page/logs-content/components/edit-post-modal/index.marko
@@ -0,0 +1,26 @@
+
+ Edit Post ${input.post.position}
+
+ ${state.error}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/marko/page/logs-content/components/page/component.js b/marko/page/logs-content/components/page/component.js
index d73a0d9..6f6a676 100644
--- a/marko/page/logs-content/components/page/component.js
+++ b/marko/page/logs-content/components/page/component.js
@@ -70,6 +70,10 @@ module.exports = class {
})
}
+ postEdited(post) {
+ this.patch([post])
+ }
+
get title() {
if (this.state.log.title) {
return this.state.log.title
diff --git a/marko/page/logs-content/components/page/index.marko b/marko/page/logs-content/components/page/index.marko
index 167a872..50dbc14 100644
--- a/marko/page/logs-content/components/page/index.marko
+++ b/marko/page/logs-content/components/page/index.marko
@@ -6,6 +6,7 @@
key=post.id
on-move("movePost", post)
on-remove("removePost", post)
+ on-edited("postEdited")
post=post
characters=state.log.characters
last=(post.position === state.log.posts.length)
diff --git a/marko/page/logs-content/components/post/component.js b/marko/page/logs-content/components/post/component.js
index 7b19652..536e428 100644
--- a/marko/page/logs-content/components/post/component.js
+++ b/marko/page/logs-content/components/post/component.js
@@ -29,6 +29,10 @@ module.exports = class {
this.emit("remove")
}
+ edited(data) {
+ this.emit("edited", data)
+ }
+
onInput(input) {
if (this.state == null) {
return
diff --git a/marko/page/logs-content/components/post/index.marko b/marko/page/logs-content/components/post/index.marko
index dc7145a..f9d180c 100644
--- a/marko/page/logs-content/components/post/index.marko
+++ b/marko/page/logs-content/components/post/index.marko
@@ -3,7 +3,7 @@
@@ -24,4 +24,5 @@
+
\ No newline at end of file
diff --git a/rpdata/api/Post.js b/rpdata/api/Post.js
index 3a12057..d6d7cf6 100644
--- a/rpdata/api/Post.js
+++ b/rpdata/api/Post.js
@@ -43,6 +43,28 @@ class PostAPI {
})
}
+ /**
+ * Call `editPost(input)` mutation, returns the id and edited fields of the post
+ *
+ * @param {{id:string, time:Date, kind:string, nick:string, text:string}} input
+ * @returns {Promise<{id:string, time:Date, kind:string, nick:string, text:string}>}
+ */
+ edit(input) {
+ return query(`
+ mutation RemovePost($input: PostEditInput!) {
+ editPost(input: $input) {
+ id
+ time
+ kind
+ nick
+ text
+ }
+ }
+ `, {input}, {permissions: ["post.edit"]}).then(({editPost}) => {
+ return editPost
+ })
+ }
+
/**
* Call `removePost(input)` mutation, returns the id of the affected post.
*