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.

39 lines
1.0 KiB

6 years ago
  1. const moment = require("moment")
  2. module.exports = class {
  3. onCreate(input) {
  4. this.state = {
  5. chapterTitles: {},
  6. fdateLink: "",
  7. fdate: "",
  8. selectedChapter: ""
  9. }
  10. }
  11. onMount() {
  12. this.state.selectedChapter = (window.location.hash||"#").slice(1)
  13. }
  14. onInput(input) {
  15. if (input.story.fictionalDate && input.story.fictionalDate.getUTCFullYear() > 10) {
  16. const fdate = input.story.fictionalDate
  17. this.state.fdateLink = `/story/by-month/${moment(fdate).format("YYYY-MM")}`
  18. this.state.fdate = moment(fdate).format("MMM D, YYYY")
  19. }
  20. for (const chapter of input.story.chapters) {
  21. let title = "Chapter " + input.story.chapters.indexOf(chapter) + 1
  22. if (chapter.title) {
  23. title = chapter.title
  24. } else if (chapter.fictionalDate && chapter.fictionalDate.getUTCFullYear() > 1) {
  25. title = moment(chapter.fictionalDate).format("MMM D, YYYY")
  26. }
  27. this.state.chapterTitles[chapter.id] = title
  28. }
  29. }
  30. selectChapter(id) {
  31. this.state.selectedChapter = id
  32. }
  33. }