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.

43 lines
913 B

  1. const pluralize = require("pluralize")
  2. // TODO: use graphql for this like with story categories
  3. const kinds = ["Character", "Event", "Location", "Organization", "Series"]
  4. module.exports = class {
  5. onCreate(input) {
  6. this.state = {
  7. tags: [],
  8. groups: [],
  9. modal: null,
  10. }
  11. this.update(input.tags)
  12. }
  13. open(modal) {
  14. this.state.modal = modal
  15. }
  16. close() {
  17. this.state.modal = null
  18. }
  19. update(newTags) {
  20. const tags = newTags.map(t => ({
  21. kind: t.kind,
  22. name: t.name,
  23. url: `/story/by-tag/${t.kind}/${encodeURIComponent(t.name)}`
  24. }))
  25. const groups = kinds.map(k => ({
  26. groupClass: "group-" + k.toLowerCase(),
  27. colorClass: "color-tag-" + k.toLowerCase(),
  28. header: pluralize(k),
  29. tags: tags.filter(t => t.kind === k),
  30. }))
  31. this.state = Object.assign({}, this.state, {
  32. tags: tags,
  33. groups: groups,
  34. })
  35. }
  36. }