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.

49 lines
1021 B

  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, 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 "timestamp": {
  18. const m = moment(value)
  19. if (m.year() < 2) {
  20. break
  21. }
  22. this.state.tooltip = m.format("YYYY-MM-DD HH:mm:ss")
  23. this.state.text = `[${m.format("HH:mm")}]`
  24. break
  25. }
  26. case "author": {
  27. this.state.text = value
  28. this.state.tooltip = "See all stories by " + value
  29. this.state.href = `/story/by-author/${value}/`
  30. break
  31. }
  32. default: {
  33. this.state.color = "color-menu"
  34. this.state.text = value
  35. break
  36. }
  37. }
  38. }
  39. }