From cc8d2db6a3c7f12209661adff5237a34fcf7ec72 Mon Sep 17 00:00:00 2001 From: Alexander Cobleigh Date: Tue, 13 Oct 2020 11:14:15 +0200 Subject: [PATCH] extract preview code into generatePreview --- src/views/index.js | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/views/index.js b/src/views/index.js index 415cd7e..bee26ac 100644 --- a/src/views/index.js +++ b/src/views/index.js @@ -812,15 +812,7 @@ exports.publishView = () => { ); }; -exports.previewView = ({authorMeta, text, contentWarning, blobId}) => { - if (typeof blobId !== "boolean") { - // TODO: filename?! - // TODO: mime type guessing for just link / !image / / audio: ? - text += "\n![your new blob]("+blobId+")" - } - - const rawHtml = markdown(text); - +const generatePreview = ({ authorMeta, text, contentWarning }) => { // craft message that looks like it came from the db const msg = { key: "%non-existant.preview", @@ -848,6 +840,29 @@ exports.previewView = ({authorMeta, text, contentWarning, blobId}) => { const ago = Date.now() - Number(ts); const prettyAgo = prettyMs(ago, { compact: true }); lodash.set(msg, "value.meta.timestamp.received.since", prettyAgo); + return section({ class: "post-preview" }, + post({msg}), + + // doesn't need blobs, preview adds them to the text + form( + { action: "/publish", method: "post" }, + input({ + name: "contentWarning", + type: "hidden", + value: contentWarning, + }), + input({ + name: "text", + type: "hidden", + value: text, + }), + button({ type: "submit" }, i18n.publish), + ), + ) +} + +exports.previewView = ({ authorMeta, text, contentWarning }) => { + const rawHtml = markdown(text); return template( i18n.preview, @@ -885,24 +900,11 @@ exports.previewView = ({authorMeta, text, contentWarning, blobId}) => { }) ), button({ type: "submit" }, i18n.preview), - ), - - // doesn't need blobs, preview adds them to the text - form( - { action: "/publish", method: "post" }, - input({ - name: "contentWarning", - type: "hidden", - value: contentWarning, - }), - input({ - name: "text", - type: "hidden", - value: text, - }), - button({ type: "submit" }, i18n.publish), - ), + label({ class: "file-button", for: "blob"}, "Attach files"), + input({ type: "file", id: "blob", name: "blob" }) + ) ), + generatePreview({ authorMeta, text, contentWarning }), p(i18n.publishCustomInfo({ href: "/publish/custom" })) ); };