const moment = require("moment") module.exports = class { onCreate(input) { this.state = { chapterTitles: {}, fdateLink: "", fdate: "", selectedChapter: "" } } onMount() { this.state.selectedChapter = (window.location.hash||"#").slice(1) } onInput(input) { if (input.story.fictionalDate && input.story.fictionalDate.getUTCFullYear() > 10) { const fdate = input.story.fictionalDate this.state.fdateLink = `/story/by-month/${moment(fdate).format("YYYY-MM")}` this.state.fdate = moment(fdate).format("MMM D, YYYY") } for (const chapter of input.story.chapters) { let title = "Chapter " + input.story.chapters.indexOf(chapter) + 1 if (chapter.title) { title = chapter.title } else if (chapter.fictionalDate && chapter.fictionalDate.getUTCFullYear() > 1) { title = moment(chapter.fictionalDate).format("MMM D, YYYY") } this.state.chapterTitles[chapter.id] = title } } selectChapter(id) { this.state.selectedChapter = id } }