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.

76 lines
1.6 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. onInput(input) {
  27. if (this.state == null) {
  28. return
  29. }
  30. this.updatePost(input)
  31. }
  32. updatePost(input) {
  33. this.state.shortName = input.post.nick.split("_").shift()
  34. this.state.name = input.post.nick
  35. this.state.nameSuffix = ""
  36. this.state.text = input.post.text.replace(/\x02/g, "**")
  37. if (input.post.kind === "text" && !this.state.text.includes("\"")) {
  38. this.state.text = '"' + this.state.text + '"'
  39. }
  40. if (!input.post.nick.startsWith("=")) {
  41. const postNick = input.post.nick.replace("'s", "").replace("s'", "s")
  42. for (const character of input.characters) {
  43. for (const nick of character.nicks) {
  44. if (nick === postNick) {
  45. this.state.name = character.name
  46. this.state.shortName = character.shortName
  47. if (input.post.nick.endsWith("'s") || input.post.nick.endsWith("'")) {
  48. this.state.nameSuffix = (character.shortName.endsWith("s") || character.shortName.endsWith("z")) ? "'" : "'s"
  49. }
  50. return
  51. }
  52. }
  53. }
  54. }
  55. }
  56. kindClass(prefix) {
  57. if (this.input.post == null) {
  58. return
  59. }
  60. return `${prefix}${this.input.post.kind.replace(".", "-")}`
  61. }
  62. }