From 564192c76df46deb6d35504e0f2f6674fe9f8ab0 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 23 Sep 2018 13:08:55 +0200 Subject: [PATCH] story-content: Added remove story modal, added annotations --- marko/components/annotation/index.marko | 3 + marko/components/annotation/style.less | 36 ++++++++++++ .../components/page/component.js | 5 ++ .../story-content/components/page/index.marko | 13 ++++- .../story-content/components/page/style.less | 23 ++++++++ .../remove-story-modal/component.js | 56 +++++++++++++++++++ .../components/remove-story-modal/index.marko | 9 +++ middleware/locals.js | 12 ++-- routes/story/by-tag.js | 2 +- rpdata/api/Story.js | 18 ++++++ 10 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 marko/components/annotation/index.marko create mode 100644 marko/components/annotation/style.less create mode 100644 marko/page/story-content/components/remove-story-modal/component.js create mode 100644 marko/page/story-content/components/remove-story-modal/index.marko diff --git a/marko/components/annotation/index.marko b/marko/components/annotation/index.marko new file mode 100644 index 0000000..a8259c7 --- /dev/null +++ b/marko/components/annotation/index.marko @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/marko/components/annotation/style.less b/marko/components/annotation/style.less new file mode 100644 index 0000000..00800c2 --- /dev/null +++ b/marko/components/annotation/style.less @@ -0,0 +1,36 @@ +div.annotation { + outline: 1px solid; + padding: 0.25em 1ch; + margin-bottom: 1em; + + h2 { + font-size: 1em; + margin: 0; + text-align: center; + border-bottom: 0.25px dotted; + margin-bottom: 0.25em; + padding-bottom: 0.25em; + } + + p { + margin-top: 0.5em; + } + p:first-of-type { + margin: 0; + } +} + +div.annotation-level-info { + background-color: rgba(0, 31, 63, 0.5); + color: #08F; +} + +div.annotation-level-warning { + background-color: rgba(63, 31, 0, 0.5); + color: #F80; +} + +div.annotation-level-error { + background-color: rgba(63, 7, 0, 0.5); + color: #F10; +} \ 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 index 6d837f8..ae1b90b 100644 --- a/marko/page/story-content/components/page/component.js +++ b/marko/page/story-content/components/page/component.js @@ -3,6 +3,7 @@ module.exports = class { this.state = { story: input.story, modal: null, + removed: false, } } @@ -60,6 +61,10 @@ module.exports = class { this.refreshStory() } + timeToDie() { + this.state.removed = true + } + refreshStory() { this.state.story = Object.assign({}, this.state.story) } diff --git a/marko/page/story-content/components/page/index.marko b/marko/page/story-content/components/page/index.marko index 8a342bf..6f493b5 100644 --- a/marko/page/story-content/components/page/index.marko +++ b/marko/page/story-content/components/page/index.marko @@ -1,11 +1,22 @@
-

${state.story.name}

+
+

${state.story.name}

+ Edit + Remove +
+ +

+ This story has been removed. Your browser has not refreshed the page yet, + so you can still read it (or back it up) before leaving the page. +

+
+
\ No newline at end of file diff --git a/marko/page/story-content/components/page/style.less b/marko/page/story-content/components/page/style.less index 2ea76a4..8afacbf 100644 --- a/marko/page/story-content/components/page/style.less +++ b/marko/page/story-content/components/page/style.less @@ -7,4 +7,27 @@ font-weight: 200; text-align: center; } + + .header { + text-align: center; + vertical-align: middle; + margin-bottom: 1em; + + h1 { + vertical-align: middle; + display: block; + margin-bottom: 0; + } + + a { + vertical-align: middle; + display: inline-block; + padding: 0.5em 0.5ch 0.5em 0.5ch; + opacity: 0.5; + } + a:hoverĀ { + cursor: pointer; + opacity: 1; + } + } } \ No newline at end of file diff --git a/marko/page/story-content/components/remove-story-modal/component.js b/marko/page/story-content/components/remove-story-modal/component.js new file mode 100644 index 0000000..d4ba922 --- /dev/null +++ b/marko/page/story-content/components/remove-story-modal/component.js @@ -0,0 +1,56 @@ +const moment = require("moment") + +const {storyApi} = require("../../../../../rpdata/api/Story") + +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() { + this.state.loading = true + + storyApi.remove({id: this.input.story.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/remove-story-modal/index.marko b/marko/page/story-content/components/remove-story-modal/index.marko new file mode 100644 index 0000000..d123e62 --- /dev/null +++ b/marko/page/story-content/components/remove-story-modal/index.marko @@ -0,0 +1,9 @@ + +

Delete Story

+ +

${state.error}

+ +

Deletion is final!

+ + +
\ No newline at end of file diff --git a/middleware/locals.js b/middleware/locals.js index 3c612c6..d4d5720 100644 --- a/middleware/locals.js +++ b/middleware/locals.js @@ -3,11 +3,15 @@ module.exports = (req, res, next) => { res.markoAsync = async(template, input) => { const locals = Object.assign((res.locals || {}), input) - for (const key in locals) { - const value = locals[key] - if (value instanceof Promise) { - locals[key] = await value + try { + for (const key in locals) { + const value = locals[key] + if (value instanceof Promise) { + locals[key] = await value + } } + } catch(err) { + return res.status(404).json(err) } return res.marko(template, locals) diff --git a/routes/story/by-tag.js b/routes/story/by-tag.js index 41609ea..94570a8 100644 --- a/routes/story/by-tag.js +++ b/routes/story/by-tag.js @@ -12,7 +12,7 @@ router.get("/:tagkind/:tagname", common, async(req, res) => { const tag = new Tag(req.params.tagkind, req.params.tagname) res.markoAsync(listTemplate, { - stories: storyApi.list({tags: tag}), + stories: storyApi.list({tags: [tag]}), menuTags: [tag], selected: {tag: `${tag.kind}:${tag.name}`}, }) diff --git a/rpdata/api/Story.js b/rpdata/api/Story.js index 2196e47..ac1f20b 100644 --- a/rpdata/api/Story.js +++ b/rpdata/api/Story.js @@ -184,6 +184,24 @@ const storyApi = { return removeStoryTag }) }, + + /** + * Call `removeStory(input)` mutation, returns the id. + * + * @param {{id:string}} input + * @returns {Promise<{id:string}>} + */ + remove(input) { + return query(` + mutation RemoveStory($input: StoryRemoveInput!) { + removeStory(input:$input) { + id + } + } + `, {input}, {permissions: ["member", "story.remove"]}).then(({removeStory}) => { + return removeStory + }) + }, } module.exports = {storyApi, Story} \ No newline at end of file