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.

68 lines
1.4 KiB

  1. module.exports = class {
  2. onCreate() {
  3. this.state = {
  4. filters: [],
  5. filtered: false,
  6. }
  7. }
  8. onInput(input) {
  9. if (!input.filter) {
  10. this.state.filters = []
  11. this.state.filtered = false
  12. return
  13. }
  14. const filters = []
  15. const {characters, channels, events, search} = input.filter
  16. if (search != null) {
  17. filters.push({
  18. type: "search",
  19. key: "search",
  20. icon: "T",
  21. color: "color-text",
  22. text: search,
  23. })
  24. }
  25. for (const character of (characters || [])) {
  26. filters.push({
  27. type: "characters",
  28. key: character,
  29. icon: "C",
  30. color: "color-tag-character",
  31. id: character,
  32. text: (input.characters.find(c => c.id === character) || {name: "Unknown ("+character+")"}).name,
  33. })
  34. }
  35. for (const channel of (channels || [])) {
  36. filters.push({
  37. type: "channels",
  38. key: channel.replace(/'/g, "__"),
  39. icon: "#",
  40. color: "color-tag-location",
  41. id: channel,
  42. text: channel,
  43. })
  44. }
  45. for (const event of (events || [])) {
  46. filters.push({
  47. type: "events",
  48. key: event.replace(/['\s\.]/g, "__"),
  49. icon: "E",
  50. color: "color-tag-event",
  51. id: event,
  52. text: event,
  53. })
  54. }
  55. this.state.filters = filters
  56. this.state.filtered = (filters.length > 0)
  57. }
  58. select(value) {
  59. this.emit("select", value)
  60. }
  61. }