From 6ea96326237e5c6e682904f246db1f449958ca10 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 17 Mar 2019 20:00:49 +0100 Subject: [PATCH] Comments are pretty much done! --- marko/components/modal/component.js | 3 + .../components/chapter-meta/component.js | 7 + .../components/chapter-meta/index.marko | 4 + .../components/chapter/component.js | 28 ++++ .../components/chapter/index.marko | 3 + .../components/comment/index.marko | 23 +-- .../create-comment-modal/component.js | 53 ++++++- .../create-comment-modal/index.marko | 10 +- .../edit-comment-modal/component.js | 131 ++++++++++++++++++ .../components/edit-comment-modal/index.marko | 27 ++++ .../components/page/component.js | 8 +- .../remove-comment-modal/component.js | 36 +++++ .../remove-comment-modal/index.marko | 9 ++ rpdata/api/Comment.js | 50 ++++++- 14 files changed, 365 insertions(+), 27 deletions(-) create mode 100644 marko/page/story-content/components/edit-comment-modal/component.js create mode 100644 marko/page/story-content/components/edit-comment-modal/index.marko create mode 100644 marko/page/story-content/components/remove-comment-modal/component.js create mode 100644 marko/page/story-content/components/remove-comment-modal/index.marko diff --git a/marko/components/modal/component.js b/marko/components/modal/component.js index a94ddcb..39a30ba 100644 --- a/marko/components/modal/component.js +++ b/marko/components/modal/component.js @@ -47,6 +47,9 @@ module.exports = class { if (this.input.enabled) { window.removeEventListener("keydown", this.onPress) } + + this.mounted = false + this.opened = false } /** diff --git a/marko/page/story-content/components/chapter-meta/component.js b/marko/page/story-content/components/chapter-meta/component.js index 0a423c9..212a0f7 100644 --- a/marko/page/story-content/components/chapter-meta/component.js +++ b/marko/page/story-content/components/chapter-meta/component.js @@ -50,6 +50,13 @@ module.exports = class { break } + + case "title": { + this.state.color = "color-primary" + this.state.text = value + + break + } default: { this.state.color = "color-menu" diff --git a/marko/page/story-content/components/chapter-meta/index.marko b/marko/page/story-content/components/chapter-meta/index.marko index 9165ff5..f554de8 100644 --- a/marko/page/story-content/components/chapter-meta/index.marko +++ b/marko/page/story-content/components/chapter-meta/index.marko @@ -9,6 +9,10 @@

${input.character.author}

+
+

(Unknown Character)

+

${input.ukAuthor}

+
\ No newline at end of file diff --git a/marko/page/story-content/components/chapter/component.js b/marko/page/story-content/components/chapter/component.js index 05929a8..924e20a 100644 --- a/marko/page/story-content/components/chapter/component.js +++ b/marko/page/story-content/components/chapter/component.js @@ -8,9 +8,37 @@ module.exports = class { Message: "Message", Chat: "Chat Message", }, + selectedComment: null, } } + onOpenComment(comment, modal) { + this.state.selectedComment = comment + this.state.modal = modal + } + + addComment(comment) { + this.updateChapter({ + comments: this.input.chapter.comments.concat(comment), + }) + } + + editComment(comment) { + const comments = this.input.chapter.comments.slice() + const index = comments.findIndex(c => c.id === comment.id) + if (index != -1) { + comments[index] = comment + } else { + comments.push(comment) + } + + this.updateChapter({comments}) + } + + removeComment(comment) { + this.updateChapter({comments: this.input.chapter.comments.filter(c => c.id !== comment.id)}) + } + updateChapter(data) { this.emit("edit", data) } diff --git a/marko/page/story-content/components/chapter/index.marko b/marko/page/story-content/components/chapter/index.marko index 3b7465d..304e7ad 100644 --- a/marko/page/story-content/components/chapter/index.marko +++ b/marko/page/story-content/components/chapter/index.marko @@ -25,6 +25,7 @@ locked=input.chapter.commentsLocked mode=input.chapter.commentMode user=input.user + on-open("onOpenComment", comment) />
Add ${state.commentLabels[input.chapter.commentMode] || "Comment"}
@@ -32,6 +33,8 @@ + + \ No newline at end of file diff --git a/marko/page/story-content/components/comment/index.marko b/marko/page/story-content/components/comment/index.marko index 2cbbe5b..6419aa2 100644 --- a/marko/page/story-content/components/comment/index.marko +++ b/marko/page/story-content/components/comment/index.marko @@ -5,10 +5,10 @@ import moment from "moment"
- ${input.comment.characterName} + + ${input.comment.characterName} + +
+

(Unknown Character)

+

${input.comment.author}

+
+
@@ -51,10 +58,10 @@ import moment from "moment"
@@ -91,14 +98,14 @@ import moment from "moment"