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.

47 lines
1.1 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. this.state.characters = this.state.characters.concat(character)
  28. }
  29. characterNicksChanged(character, nicks) {
  30. const characters = this.state.characters.slice()
  31. const index = characters.findIndex(c => c.id === character.id)
  32. if (index === -1) {
  33. return
  34. }
  35. characters[index] = Object.assign(characters[index], {nicks: nicks.slice(), nick: (nicks[0] || "")})
  36. this.state.characters = characters
  37. }
  38. }