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.

74 lines
1.5 KiB

  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. story: input.story,
  5. modal: null,
  6. removed: false,
  7. }
  8. }
  9. open(modal) {
  10. this.state.modal = modal
  11. }
  12. close() {
  13. this.state.modal = null
  14. }
  15. updateStory(data) {
  16. this.state.story = Object.assign(Object.assign({}, this.state.story), data)
  17. }
  18. addChapter(chapter) {
  19. this.state.story.chapters.push(chapter)
  20. this.refreshStory()
  21. }
  22. moveChapter(chapter, data) {
  23. if (data.storyId !== this.state.story.id) {
  24. this.state.story = Object.assign({}, this.state.story, {chapters: this.state.story.chapters.filter(ch => ch.id !== chapter.id)})
  25. }
  26. }
  27. updateChapter(id, data) {
  28. const index = this.state.story.chapters.findIndex(ch => ch.id === id)
  29. if (index === -1) {
  30. return
  31. }
  32. this.state.story.chapters[index] = Object.assign({}, this.state.story.chapters[index], data);
  33. this.refreshStory()
  34. }
  35. removeChapter(id) {
  36. const index = this.state.story.chapters.findIndex(ch => ch.id === id)
  37. if (index === -1) {
  38. return
  39. }
  40. this.state.story.chapters.splice(index, 1)
  41. this.refreshStory()
  42. }
  43. menuSelect(kind, id) {
  44. switch (kind) {
  45. case "add":
  46. this.open("chapter.add")
  47. break
  48. }
  49. }
  50. updateStoryTags(tags) {
  51. this.state.story.tags = tags
  52. this.refreshStory()
  53. }
  54. timeToDie() {
  55. this.state.removed = true
  56. }
  57. refreshStory() {
  58. this.state.story = Object.assign({}, this.state.story)
  59. }
  60. }