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.
 
 
 
 

40 lines
1.0 KiB

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
}
}