diff --git a/marko/page/story-content/components/chapter-meta/component.js b/marko/page/story-content/components/chapter-meta/component.js
index d845544..780b245 100644
--- a/marko/page/story-content/components/chapter-meta/component.js
+++ b/marko/page/story-content/components/chapter-meta/component.js
@@ -1,7 +1,17 @@
const moment = require("moment")
module.exports = class {
- onCreate({kind, weak, value, updated}) {
+ onCreate() {
+ this.state = {text: null, color: "color-menu", href: null, tooltip: null}
+ }
+
+ onInput(input) {
+ if (this.state != null) {
+ this.updateState(input)
+ }
+ }
+
+ updateState({kind, weak, value, updated}) {
this.state = {text: null, color: "color-menu", href: null, tooltip: null}
if (value == null || value == "") {
diff --git a/marko/page/story-content/components/chapter/component.js b/marko/page/story-content/components/chapter/component.js
index fbed954..7448a98 100644
--- a/marko/page/story-content/components/chapter/component.js
+++ b/marko/page/story-content/components/chapter/component.js
@@ -1,5 +1,25 @@
module.exports = class {
onCreate(input) {
- this.state = Object.assign({}, input.chapter)
+ this.state = {
+ modal: null,
+ removed: false,
+ }
+ }
+
+ updateChapter(data) {
+ this.emit("edit", data)
+ }
+
+ removeChapter() {
+ this.state.removed = true
+ this.emit("remove")
+ }
+
+ open(modal) {
+ this.state.modal = modal
+ }
+
+ close() {
+ this.state.modal = null
}
}
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/components/edit-chapter-modal/component.js b/marko/page/story-content/components/chapter/components/edit-chapter-modal/component.js
new file mode 100644
index 0000000..284f398
--- /dev/null
+++ b/marko/page/story-content/components/chapter/components/edit-chapter-modal/component.js
@@ -0,0 +1,77 @@
+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
+ })
+ }
+}
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/components/edit-chapter-modal/index.marko b/marko/page/story-content/components/chapter/components/edit-chapter-modal/index.marko
new file mode 100644
index 0000000..fdf6a39
--- /dev/null
+++ b/marko/page/story-content/components/chapter/components/edit-chapter-modal/index.marko
@@ -0,0 +1,11 @@
+
+ Edit Chapter
+
+ ${state.error}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/components/remove-chapter-modal/component.js b/marko/page/story-content/components/chapter/components/remove-chapter-modal/component.js
new file mode 100644
index 0000000..7ffb4ee
--- /dev/null
+++ b/marko/page/story-content/components/chapter/components/remove-chapter-modal/component.js
@@ -0,0 +1,54 @@
+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
+ })
+ }
+}
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/components/remove-chapter-modal/index.marko b/marko/page/story-content/components/chapter/components/remove-chapter-modal/index.marko
new file mode 100644
index 0000000..0570a34
--- /dev/null
+++ b/marko/page/story-content/components/chapter/components/remove-chapter-modal/index.marko
@@ -0,0 +1,9 @@
+
+ Delete Chapter
+
+ ${state.error}
+
+ This is irreversible!
+
+
+
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/index.marko b/marko/page/story-content/components/chapter/index.marko
index be79045..572be35 100644
--- a/marko/page/story-content/components/chapter/index.marko
+++ b/marko/page/story-content/components/chapter/index.marko
@@ -1,10 +1,19 @@
-
-
+import moment from "moment"
+
+
+
-
-
-
-
+
+
+
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/marko/page/story-content/components/chapter/style.less b/marko/page/story-content/components/chapter/style.less
index c0f36ee..1c37f02 100644
--- a/marko/page/story-content/components/chapter/style.less
+++ b/marko/page/story-content/components/chapter/style.less
@@ -11,4 +11,24 @@
position: relative;
top: -8em;
}
+
+ .options {
+ position: absolute;
+ text-align: right;
+ width: calc(100% - 35.5ch);
+ max-width: 75ch;
+
+ a {
+ display: inline-block;
+ padding: 0 0.5ch;
+
+ opacity: 0.5;
+
+ cursor: pointer;
+ user-select: none;
+ }
+ a:hover {
+ opacity: 1;
+ }
+ }
}
\ No newline at end of file
diff --git a/marko/page/story-content/components/page/component.js b/marko/page/story-content/components/page/component.js
new file mode 100644
index 0000000..51a6752
--- /dev/null
+++ b/marko/page/story-content/components/page/component.js
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/marko/page/story-content/components/page/index.marko b/marko/page/story-content/components/page/index.marko
index cb01f8b..0947198 100644
--- a/marko/page/story-content/components/page/index.marko
+++ b/marko/page/story-content/components/page/index.marko
@@ -1,8 +1,8 @@
-
+
-
${input.story.name}
-
-
+ ${state.story.name}
+
+
\ No newline at end of file
diff --git a/marko/page/story-content/components/story-content-menu/component.js b/marko/page/story-content/components/story-content-menu/component.js
index 1d1b6a9..4fa822f 100644
--- a/marko/page/story-content/components/story-content-menu/component.js
+++ b/marko/page/story-content/components/story-content-menu/component.js
@@ -3,35 +3,32 @@ const moment = require("moment")
module.exports = class {
onCreate(input) {
this.state = {
- chapterTitles: {},
- fdateLink: "",
- fdate: "",
- selectedChapter: ""
+ selectedChapter: "",
+ bullshit: 0,
}
}
onMount() {
this.state.selectedChapter = (window.location.hash||"#").slice(1)
- }
-
- onInput(input) {
- if (input.story.fictionalDate && input.story.fictionalDate.getUTCFullYear() > 10) {
- const fdate = input.story.fictionalDate
-
- this.state.fdateLink = `/story/by-month/${moment(fdate).format("YYYY-MM")}`
- this.state.fdate = moment(fdate).format("MMM D, YYYY")
- }
- for (const chapter of input.story.chapters) {
- let title = "Chapter " + input.story.chapters.indexOf(chapter) + 1
- if (chapter.title) {
- title = chapter.title
- } else if (chapter.fictionalDate && chapter.fictionalDate.getUTCFullYear() > 1) {
- title = moment(chapter.fictionalDate).format("MMM D, YYYY")
+ // Marko is being silly and needs a state change to re-render
+ setInterval(() => {
+ this.state.bullshit++
+ if (this.state.bullshit > 10000) {
+ this.state.bullshit = 0
}
+ }, 250)
+ }
- this.state.chapterTitles[chapter.id] = title
+ chapterTitle(chapter) {
+ let title = "Chapter " + this.input.story.chapters.indexOf(chapter) + 1
+ if (chapter.title) {
+ title = chapter.title
+ } else if (chapter.fictionalDate && chapter.fictionalDate.getUTCFullYear() > 1) {
+ title = moment(chapter.fictionalDate).format("MMM D, YYYY")
}
+
+ return title
}
selectChapter(id) {
diff --git a/marko/page/story-content/components/story-content-menu/index.marko b/marko/page/story-content/components/story-content-menu/index.marko
index fa41f15..1c3694b 100644
--- a/marko/page/story-content/components/story-content-menu/index.marko
+++ b/marko/page/story-content/components/story-content-menu/index.marko
@@ -1,9 +1,6 @@
\ No newline at end of file