The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

6 years ago
6 years ago
  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. modal: null,
  5. removed: false,
  6. commentLabels: {
  7. Article: "Comment",
  8. Message: "Message",
  9. Chat: "Chat Message",
  10. },
  11. selectedComment: null,
  12. }
  13. }
  14. onOpenComment(comment, modal) {
  15. this.state.selectedComment = comment
  16. this.state.modal = modal
  17. }
  18. addComment(comment) {
  19. this.updateChapter({
  20. comments: this.input.chapter.comments.concat(comment),
  21. })
  22. }
  23. editComment(comment) {
  24. const comments = this.input.chapter.comments.slice()
  25. const index = comments.findIndex(c => c.id === comment.id)
  26. if (index != -1) {
  27. comments[index] = comment
  28. } else {
  29. comments.push(comment)
  30. }
  31. this.updateChapter({comments})
  32. }
  33. removeComment(comment) {
  34. this.updateChapter({comments: this.input.chapter.comments.filter(c => c.id !== comment.id)})
  35. }
  36. updateChapter(data) {
  37. this.emit("edit", data)
  38. }
  39. moveChapter(data) {
  40. this.emit("move", data)
  41. }
  42. removeChapter() {
  43. this.state.removed = true
  44. this.emit("remove")
  45. }
  46. open(modal) {
  47. this.state.modal = modal
  48. }
  49. close() {
  50. this.state.modal = null
  51. }
  52. }