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.

84 lines
1.9 KiB

  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. shortName: "",
  5. name: "",
  6. text: "",
  7. nameSuffix: "",
  8. modal: null,
  9. removed: false,
  10. multipart: false,
  11. }
  12. this.updatePost(input)
  13. }
  14. open(modal) {
  15. this.state.modal = modal
  16. }
  17. close() {
  18. this.state.modal = null
  19. }
  20. move(toPosition) {
  21. this.emit("move", toPosition)
  22. }
  23. remove() {
  24. this.state.removed = true
  25. this.emit("remove")
  26. }
  27. edited(data) {
  28. this.emit("edited", data)
  29. }
  30. onInput(input) {
  31. if (this.state == null) {
  32. return
  33. }
  34. const timediff = Date.parse(input.post.time) - Date.parse(input.prev.time)
  35. this.state.multipart = (input.post.nick == input.prev.nick && input.prev.multipart !== false) && (Math.abs(timediff) < 60000);
  36. this.updatePost(input)
  37. }
  38. updatePost(input) {
  39. this.state.shortName = input.post.nick.split("_").shift()
  40. this.state.name = input.post.nick
  41. this.state.nameSuffix = ""
  42. this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "_")
  43. if (input.post.kind === "text" && !this.state.text.includes("\"")) {
  44. this.state.text = '"' + this.state.text + '"'
  45. }
  46. if (!input.post.nick.startsWith("=")) {
  47. const postNick = input.post.nick.replace("'s", "").replace("s'", "s")
  48. for (const character of input.characters) {
  49. for (const nick of character.nicks) {
  50. if (nick === postNick) {
  51. this.state.name = character.name
  52. this.state.shortName = character.shortName
  53. if (input.post.nick.endsWith("'s") || input.post.nick.endsWith("'")) {
  54. this.state.nameSuffix = (character.shortName.endsWith("s") || character.shortName.endsWith("z")) ? "'" : "'s"
  55. }
  56. return
  57. }
  58. }
  59. }
  60. }
  61. }
  62. kindClass(prefix) {
  63. if (this.input.post == null) {
  64. return
  65. }
  66. return `${prefix}${this.input.post.kind.replace(".", "-")}`
  67. }
  68. }