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.

61 lines
1.3 KiB

  1. const {tagApi} = require("../../../../../rpdata/api/Tag")
  2. module.exports = class {
  3. onCreate() {
  4. this.state = {
  5. values: {
  6. name: "",
  7. kind: "Character",
  8. },
  9. tags: [],
  10. suggestions: [],
  11. }
  12. }
  13. onMount() {
  14. tagApi.list().then(list => {
  15. this.state.tags = list
  16. }).catch(err => {})
  17. this.getEl("name").addEventListener("keydown", ev => {
  18. setTimeout(() => {
  19. const name = this.getEl("name").value
  20. const kind = this.getEl("kind").value
  21. const search = name.toLowerCase()
  22. this.state.values = {name, kind}
  23. this.state.suggestions = []
  24. const suggestions = this.state.tags.filter(t => t.name.toLowerCase().includes(search))
  25. if (suggestions.length > 0 && suggestions.length < 20) {
  26. if (suggestions.length > 1 || suggestions[0].name !== name) {
  27. this.state.suggestions = suggestions
  28. }
  29. }
  30. }, 100)
  31. })
  32. }
  33. add(tag) {
  34. this.state.values = {
  35. kind: "Event",
  36. name: "",
  37. }
  38. this.emit("add", tag)
  39. }
  40. change(key, ev) {
  41. const value = ev.target.value
  42. this.state.values[key] = value
  43. }
  44. applySuggestion(tag) {
  45. this.state.values = {
  46. name: tag.name,
  47. kind: tag.kind,
  48. }
  49. this.state.suggestions = []
  50. }
  51. }