logs-content: Added remove modal, fixed move up/down mutations

This commit is contained in:
2018-09-30 14:21:04 +02:00
parent 6cb1043004
commit ba2b827119
8 changed files with 122 additions and 7 deletions
@@ -41,7 +41,11 @@ module.exports = class {
this.state.log = Object.assign({}, this.state.log)
}
movePost(post, toPosition) {
movePost(post, toPosition, relative) {
if (relative) {
toPosition = post.position + toPosition
}
postApi.move({id: post.id, toPosition}).then(patches => {
this.patch(patches)
}).catch(err => {
@@ -49,6 +53,23 @@ module.exports = class {
})
}
removePost(post) {
postApi.remove({id: post.id}).then(() => {
this.state.log.posts = this.state.log.posts.filter(p => p.id !== post.id)
for (const p of this.state.log.posts) {
if (p.position > post.position) {
p.position--
}
}
this.state.log = Object.assign({}, this.state.log)
}).catch(errs => {
console.warn("Failed to delete:", errs)
this.state.error = "Failed to delete: " + (errs.message || errs[0].message)
})
}
get title() {
if (this.state.log.title) {
return this.state.log.title
@@ -2,6 +2,13 @@
<main>
<div class="logs-content">
<h1 class="color-primary">${component.title}</h1>
<post for(post in state.log.posts) on-move("movePost", post) post=post characters=state.log.characters last=(post.position === state.log.posts.length) />
<post for(post in state.log.posts)
key=post.id
on-move("movePost", post)
on-remove("removePost", post)
post=post
characters=state.log.characters
last=(post.position === state.log.posts.length)
/>
</div>
</main>