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.

56 lines
1.3 KiB

  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. characters: input.characters,
  5. modal: null,
  6. }
  7. }
  8. open(modal) {
  9. this.state.modal = modal
  10. }
  11. close() {
  12. this.state.modal = null
  13. }
  14. characterRemoved({id}) {
  15. this.state.characters = this.state.characters.filter(c => c.id !== id)
  16. }
  17. characterEdited(character, patch) {
  18. const characters = this.state.characters.slice()
  19. const index = characters.findIndex(c => c.id === character.id)
  20. if (index === -1) {
  21. return
  22. }
  23. characters[index] = Object.assign({}, characters[index], patch)
  24. this.state.characters = characters
  25. }
  26. characterAdded(character) {
  27. const index = this.state.characters.findIndex(c => c.id === character.id)
  28. if (index !== -1) {
  29. const characters = this.state.characters.slice()
  30. characters[index] = character
  31. this.state.characters = characters
  32. return
  33. }
  34. this.state.characters = this.state.characters.concat(character)
  35. }
  36. characterNicksChanged(character, nicks) {
  37. const characters = this.state.characters.slice()
  38. const index = characters.findIndex(c => c.id === character.id)
  39. if (index === -1) {
  40. return
  41. }
  42. characters[index] = Object.assign(characters[index], {nicks: nicks.slice(), nick: (nicks[0] || "")})
  43. this.state.characters = characters
  44. }
  45. }