story-content: Added edit/delete chapters
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
story: input.story
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
||||
removeChapter(id) {
|
||||
const index = this.state.story.chapters.findIndex(ch => ch.id === id)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
this.state.story.chapters.splice(index, 1)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
<story-content-menu story=input.story selected=(input.selected || {}) user=input.user />
|
||||
<story-content-menu key="menu" story=state.story selected=(input.selected || {}) user=input.user />
|
||||
<main>
|
||||
<div class="story-content">
|
||||
<h1 class="color-primary">${input.story.name}</h1>
|
||||
<story-tags tags=input.story.tags />
|
||||
<chapter for(chapter in input.story.chapters) key=chapter.id chapter=chapter />
|
||||
<h1 class="color-primary">${state.story.name}</h1>
|
||||
<story-tags tags=state.story.tags />
|
||||
<chapter for(chapter in state.story.chapters) key=chapter.id chapter=chapter on-edit("updateChapter", chapter.id) on-remove("removeChapter", chapter.id)/>
|
||||
</div>
|
||||
</main>
|
||||
Reference in New Issue
Block a user