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.

80 lines
1.7 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. }
  11. this.updatePost(input)
  12. }
  13. open(modal) {
  14. this.state.modal = modal
  15. }
  16. close() {
  17. this.state.modal = null
  18. }
  19. move(toPosition) {
  20. this.emit("move", toPosition)
  21. }
  22. remove() {
  23. this.state.removed = true
  24. this.emit("remove")
  25. }
  26. edited(data) {
  27. this.emit("edited", data)
  28. }
  29. onInput(input) {
  30. if (this.state == null) {
  31. return
  32. }
  33. this.updatePost(input)
  34. }
  35. updatePost(input) {
  36. this.state.shortName = input.post.nick.split("_").shift()
  37. this.state.name = input.post.nick
  38. this.state.nameSuffix = ""
  39. this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "_")
  40. if (input.post.kind === "text" && !this.state.text.includes("\"")) {
  41. this.state.text = '"' + this.state.text + '"'
  42. }
  43. if (!input.post.nick.startsWith("=")) {
  44. const postNick = input.post.nick.replace("'s", "").replace("s'", "s")
  45. for (const character of input.characters) {
  46. for (const nick of character.nicks) {
  47. if (nick === postNick) {
  48. this.state.name = character.name
  49. this.state.shortName = character.shortName
  50. if (input.post.nick.endsWith("'s") || input.post.nick.endsWith("'")) {
  51. this.state.nameSuffix = (character.shortName.endsWith("s") || character.shortName.endsWith("z")) ? "'" : "'s"
  52. }
  53. return
  54. }
  55. }
  56. }
  57. }
  58. }
  59. kindClass(prefix) {
  60. if (this.input.post == null) {
  61. return
  62. }
  63. return `${prefix}${this.input.post.kind.replace(".", "-")}`
  64. }
  65. }