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.
75 lines
1.3 KiB
75 lines
1.3 KiB
module.exports = class {
|
|
onCreate(input) {
|
|
this.state = {
|
|
story: input.story,
|
|
modal: null,
|
|
removed: false,
|
|
}
|
|
}
|
|
|
|
open(modal) {
|
|
this.state.modal = modal
|
|
}
|
|
|
|
close() {
|
|
this.state.modal = null
|
|
}
|
|
|
|
updateStory(data) {
|
|
this.state.story = Object.assign(Object.assign({}, this.state.story), data)
|
|
}
|
|
|
|
addChapter(chapter) {
|
|
this.state.story.chapters.push(chapter)
|
|
this.refreshStory()
|
|
}
|
|
|
|
updateChapter(id, data) {
|
|
const index = this.state.story.chapters.findIndex(ch => ch.id === id)
|
|
if (index === -1) {
|
|
return
|
|
}
|
|
|
|
for (const key in data) {
|
|
if (!data.hasOwnProperty(key)) {
|
|
continue
|
|
}
|
|
|
|
this.state.story.chapters[index][key] = data[key]
|
|
}
|
|
|
|
this.refreshStory()
|
|
}
|
|
|
|
removeChapter(id) {
|
|
const index = this.state.story.chapters.findIndex(ch => ch.id === id)
|
|
if (index === -1) {
|
|
return
|
|
}
|
|
|
|
this.state.story.chapters.splice(index, 1)
|
|
|
|
this.refreshStory()
|
|
}
|
|
|
|
menuSelect(kind, id) {
|
|
switch (kind) {
|
|
case "add":
|
|
this.open("chapter.add")
|
|
break
|
|
}
|
|
}
|
|
|
|
updateStoryTags(tags) {
|
|
this.state.story.tags = tags
|
|
this.refreshStory()
|
|
}
|
|
|
|
timeToDie() {
|
|
this.state.removed = true
|
|
}
|
|
|
|
refreshStory() {
|
|
this.state.story = Object.assign({}, this.state.story)
|
|
}
|
|
}
|