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.

68 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. const moment = require("moment")
  2. module.exports = class {
  3. onCreate() {
  4. this.state = {text: null, color: "color-menu", href: null, tooltip: null}
  5. }
  6. onInput(input) {
  7. if (this.state != null) {
  8. this.updateState(input)
  9. }
  10. }
  11. updateState({kind, weak, value, utc, updated}) {
  12. this.state = {text: null, color: "color-menu", href: null, tooltip: null}
  13. if (value == null || value == "") {
  14. return
  15. }
  16. switch (kind) {
  17. case "date": {
  18. const m = utc ? moment.utc(value) : moment(value)
  19. if (m.year() < 2) {
  20. break
  21. }
  22. if (!weak) {
  23. this.state.tooltip = `See all stories set during ${m.format("MMMM YYYY")}`
  24. this.state.href = `/story/by-month/${m.format("YYYY-MM")}/`
  25. }
  26. const dateStr = m.format("MMM D, YYYY")
  27. this.state.text = dateStr
  28. if (updated != null && Date.parse(updated) > Date.parse(value)) {
  29. const m2 = moment(updated)
  30. this.state.tooltip = "Originally posted: " + dateStr
  31. this.state.text = m2.format("MMM D, YYYY") + " *"
  32. }
  33. break
  34. }
  35. case "author": {
  36. this.state.text = value
  37. this.state.tooltip = "See all stories by " + value
  38. this.state.href = `/story/by-author/${value}/`
  39. break
  40. }
  41. case "title": {
  42. this.state.color = "color-primary"
  43. this.state.text = value
  44. break
  45. }
  46. default: {
  47. this.state.color = "color-menu"
  48. this.state.text = value
  49. break
  50. }
  51. }
  52. }
  53. }