story-content: Fixed update weirdness, moved edit/remove modals up

This commit is contained in:
2018-09-22 11:48:04 +02:00
parent c40ac40ab5
commit a560752eb8
7 changed files with 12 additions and 12 deletions
@@ -1,77 +0,0 @@
const moment = require("moment")
const {chapterApi} = require("../../../../../../../rpdata/api/Chapter")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
title: "",
source: "",
fictionalDate: "",
},
}
this.first = false
}
onInput(input) {
if (input.chapter && !this.first) {
let {fictionalDate, title, source} = input.chapter
if (fictionalDate != null) {
fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY")
}
this.state.values = {fictionalDate, title, source}
}
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.first = false
this.emit("close")
}
save() {
const values = this.state.values
let fictionalDate = new Date(values.fictionalDate + " UTC")
if (values.fictionalDate != "") {
if (Number.isNaN(fictionalDate)) {
this.state.error = `Could not parse ${values.fictionalDate} as date`
return
}
} else {
fictionalDate = null
}
const input = {id: this.input.chapter.id, title: values.title, source: values.source}
if (fictionalDate != null) {
input.fictionalDate = fictionalDate
} else {
input.clearFictionalDate = true
}
chapterApi.editChapter(input).then(data => {
this.emit("edit", data)
this.emit("close")
}).catch(errs => {
console.warn("Failed to edit:", errs)
this.state.error = "Failed to edit: " + errs[0].message
}).then(() => {
this.state.loading = false
})
}
}
@@ -1,11 +0,0 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<h1>Edit Chapter</h1>
<p key="error" class="color-error">${state.error}</p>
<input key="title" placeholder="Title" class="big" on-change("change", "title") value=state.values.title />
<input key="icdate" placeholder="IC Date" on-change("change", "fictionalDate") value=state.values.fictionalDate />
<textarea key="source" placeholder="Content" class="tall" on-change("change", "source") value=state.values.source />
<button disabled=state.loading on-click("save")>Save</button>
</modal>
@@ -1,54 +0,0 @@
const moment = require("moment")
const {chapterApi} = require("../../../../../../../rpdata/api/Chapter")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
title: "",
source: "",
fictionalDate: "",
},
}
}
onInput(input) {
if (input.chapter && !this.first) {
let {fictionalDate, title, source} = input.chapter
if (fictionalDate != null) {
fictionalDate = moment.utc(fictionalDate).format("MMM D, YYYY")
}
this.state.values = {fictionalDate, title, source}
}
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.emit("close")
}
doIt() {
chapterApi.removeChapter({id: this.input.chapter.id}).then(() => {
this.emit("remove")
this.emit("close")
}).catch(errs => {
console.warn("Failed to delete:", errs)
this.state.error = "Failed to delete: " + errs.message || errs[0].message
}).then(() => {
this.state.loading = false
})
}
}
@@ -1,9 +0,0 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) notification closable on-close("close") on-open("open") >
<h1>Delete Chapter</h1>
<p class="color-error">${state.error}</p>
<p class="color-danger">This is irreversible!</p>
<button disabled=state.loading on-click("doIt")>Yes, do it!</button>
</modal>
@@ -1,6 +1,6 @@
import moment from "moment"
<div class="story-chapter" if(!state.removed)>
<div class="story-chapter">
<a class="anchor" id=input.chapter.id />
<div class="metadata">
<div class="options color-menu">