9 changed files with 175 additions and 9 deletions
			
			
		- 
					12marko/components/menu-link/component.js
- 
					6marko/components/menu-link/style.less
- 
					82marko/page/story-content/components/create-chapter-modal/component.js
- 
					11marko/page/story-content/components/create-chapter-modal/index.marko
- 
					25marko/page/story-content/components/page/component.js
- 
					5marko/page/story-content/components/page/index.marko
- 
					8marko/page/story-content/components/story-content-menu/component.js
- 
					3marko/page/story-content/components/story-content-menu/index.marko
- 
					30rpdata/api/Chapter.js
| @ -0,0 +1,82 @@ | |||
| const moment = require("moment") | |||
| 
 | |||
| const {chapterApi} = require("../../../../../rpdata/api/Chapter") | |||
| 
 | |||
| module.exports = class { | |||
|   onCreate(input) { | |||
|     this.state = { | |||
|       error: null, | |||
|       loading: false, | |||
|       values: { | |||
|         title: "", | |||
|         source: "", | |||
|         fictionalDate: "", | |||
|       }, | |||
|     } | |||
| 
 | |||
|     this.first = false | |||
|   } | |||
| 
 | |||
|   onInput(input) { | |||
|     if (input.chapter && !this.first) { | |||
|       let {fictionalDate, title, source} = input.chapter | |||
| 
 | |||
|       if (fictionalDate != null) { | |||
|         fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY") | |||
|       } | |||
|    | |||
|       this.state.values = {fictionalDate, title, source} | |||
|     } | |||
|   } | |||
| 
 | |||
|   change(key, ev) { | |||
|     this.state.values[key] = ev.target.value | |||
|   } | |||
| 
 | |||
|   open() { | |||
|      | |||
|   } | |||
| 
 | |||
|   close() { | |||
|     this.first = false | |||
|     this.emit("close") | |||
|   } | |||
| 
 | |||
|   save() { | |||
|     const values = this.state.values | |||
| 
 | |||
|     if (values.source.length < 1) { | |||
|       this.state.error = "You cannot post an empty chapter." | |||
|       return | |||
|     } | |||
|      | |||
|     let fictionalDate = new Date(values.fictionalDate + " UTC") | |||
|     if (values.fictionalDate != "") { | |||
|       if (Number.isNaN(fictionalDate)) { | |||
|         this.state.error = `Could not parse ${values.fictionalDate} as date!` | |||
|         return | |||
|       } | |||
|     } else { | |||
|       fictionalDate = null | |||
|     } | |||
|      | |||
|     const input = {storyId: this.input.storyId, title: values.title, source: values.source, fictionalDate} | |||
| 
 | |||
|     chapterApi.addChapter(input).then(chapter => { | |||
|       this.emit("add", chapter) | |||
|       this.emit("close") | |||
| 
 | |||
|       this.state.values = { | |||
|         title: "", | |||
|         source: "", | |||
|         fictionalDate: "", | |||
|       } | |||
|     }).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,11 @@ | |||
| <modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") > | |||
|   <h1>Create Chapter</h1> | |||
| 
 | |||
|   <p key="error" class="color-error">${state.error}</p> | |||
| 
 | |||
|   <input key="title" placeholder="Title (Optional)" class="big" on-change("change", "title") value=state.values.title /> | |||
|   <input key="icdate" placeholder="IC Date (Optional)" on-change("change", "fictionalDate") value=state.values.fictionalDate /> | |||
|   <textarea key="source" placeholder="Content" class="tall" on-change("change", "source") value=state.values.source /> | |||
| 
 | |||
|   <button disabled=state.loading on-click("save")>Save</button> | |||
| </modal> | |||
| @ -1,8 +1,11 @@ | |||
| <story-content-menu key="menu" story=state.story selected=(input.selected || {}) user=input.user /> | |||
| <story-content-menu key="menu" on-select("menuSelect") story=state.story selected=(input.selected || {}) user=input.user /> | |||
| <main> | |||
|   <div class="story-content"> | |||
|     <h1 class="color-primary">${state.story.name}</h1> | |||
|     <story-tags tags=state.story.tags /> | |||
|     <chapter for(chapter in state.story.chapters) key=chapter.id chapter=chapter on-edit("updateChapter", chapter.id) on-remove("removeChapter", chapter.id)/> | |||
|   </div> | |||
| 
 | |||
|   <create-chapter-modal storyId=state.story.id enabled=(state.modal === "chapter.add") chapter=input.chapter on-close("close") on-add("addChapter") /> | |||
|    | |||
| </main> | |||
| @ -1,6 +1,7 @@ | |||
| <menu user=input.user> | |||
|   <menu-header>${input.story.name}</menu-header> | |||
|   <for(chapter in input.story.chapters | status-var=loop)> | |||
|     <menu-link key=chapter.id on-click("selectChapter", chapter.id) href=("#" + chapter.id) selected=(state.selectedChapter === chapter.id) icon=(loop.getIndex()+1)>${component.chapterTitle(chapter)}</menu-link> | |||
|     <menu-link key=chapter.id on-click("select", "chapter", chapter.id) href=("#" + chapter.id) selected=(state.selectedChapter === chapter.id) icon=(loop.getIndex()+1)>${component.chapterTitle(chapter)}</menu-link> | |||
|   </for> | |||
|   <menu-link dark key="_create" on-click("select", "add", null) icon="+">Add Chapter</menu-link> | |||
| </menu> | |||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue