|
|
@ -0,0 +1,35 @@ |
|
|
|
const pluralize = require("pluralize") |
|
|
|
|
|
|
|
// TODO: use graphql for this like with story categories
|
|
|
|
const kinds = ["Character", "Event", "Location", "Organization", "Series"] |
|
|
|
|
|
|
|
module.exports = class { |
|
|
|
onCreate(input) { |
|
|
|
this.state = { |
|
|
|
tags: [], |
|
|
|
groups: [], |
|
|
|
} |
|
|
|
|
|
|
|
this.update(input.tags) |
|
|
|
} |
|
|
|
|
|
|
|
update(newTags) { |
|
|
|
const tags = newTags.map(t => ({ |
|
|
|
kind: t.kind, |
|
|
|
name: t.name, |
|
|
|
url: `/story/by-tag/${t.kind}/${encodeURIComponent(t.name)}` |
|
|
|
})) |
|
|
|
|
|
|
|
const groups = kinds.map(k => ({ |
|
|
|
groupClass: "group-" + k.toLowerCase(), |
|
|
|
colorClass: "color-tag-" + k.toLowerCase(), |
|
|
|
header: pluralize(k), |
|
|
|
tags: tags.filter(t => t.kind === k), |
|
|
|
})) |
|
|
|
|
|
|
|
this.state = Object.assign({}, this.state, { |
|
|
|
tags: tags, |
|
|
|
groups: groups, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |