data: Added character list/add/edit/remove
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
characters: input.characters,
|
||||
modal: null,
|
||||
}
|
||||
}
|
||||
|
||||
open(modal) {
|
||||
this.state.modal = modal
|
||||
}
|
||||
|
||||
close() {
|
||||
this.state.modal = null
|
||||
}
|
||||
|
||||
characterRemoved({id}) {
|
||||
this.state.characters = this.state.characters.filter(c => c.id !== id)
|
||||
}
|
||||
|
||||
characterEdited(character, patch) {
|
||||
const characters = this.state.characters.slice()
|
||||
const index = characters.findIndex(c => c.id === character.id)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
characters[index] = Object.assign(characters[index], patch)
|
||||
|
||||
this.state.characters = characters
|
||||
}
|
||||
|
||||
characterAdded(character) {
|
||||
this.state.characters = this.state.characters.concat(character)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") />
|
||||
<main>
|
||||
<character-list characters=state.characters on-removed("characterRemoved") on-edited("characterEdited") />
|
||||
</main>
|
||||
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-added("characterAdded") on-close("close") />
|
||||
Reference in New Issue
Block a user