Commit c0fd0e300786fa560756710190772845cd949008
remove preview when publishing replies and root posts
Ev Bogue committed on 5/25/2018, 9:48:11 PMParent: e3b6a2cde0471d83afe35e6ab1514feee59047cd
Files changed
compose.js | changed |
compose.js | ||
---|---|---|
@@ -52,18 +52,18 @@ | ||
52 | 52 | if (window.location.hash.substring(1) != 'compose') |
53 | 53 | var cancelBtn = h('button.btn', 'Cancel', { |
54 | 54 | onclick: function () { |
55 | 55 | var cancel |
56 | - if (opts.updated) { | |
56 | + if (opts.type == 'updated') { | |
57 | 57 | cancel = document.getElementById(opts.updated.substring(0,10)) |
58 | 58 | var oldMessage = h('div.message__body', tools.markdown(opts.messageText)) |
59 | 59 | cancel.parentNode.replaceChild(oldMessage, cancel) |
60 | 60 | oldMessage.parentNode.appendChild(buttons) |
61 | - } else if (opts.branch) { | |
62 | - cancel = document.getElementById(opts.branch.substring(0,10)) | |
63 | - cancel.parentNode.removeChild(cancel) | |
64 | 61 | } else { |
65 | - cancel = document.getElementById('composer') | |
62 | + if (document.getElementById(opts.branch.substring(0,10))) | |
63 | + cancel = document.getElementById(opts.branch.substring(0,10)) | |
64 | + else | |
65 | + cancel = document.getElementById('composer') | |
66 | 66 | cancel.parentNode.removeChild(cancel) |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -74,63 +74,72 @@ | ||
74 | 74 | |
75 | 75 | var initialButtons = h('span', |
76 | 76 | h('button.btn', 'Preview', { |
77 | 77 | onclick: function () { |
78 | - | |
79 | - var msg = {} | |
80 | - msg.value = { | |
81 | - "author": id, | |
82 | - "content": { | |
83 | - "type": opts.type | |
78 | + if (textarea.value) { | |
79 | + var msg = {} | |
80 | + msg.value = { | |
81 | + "author": id, | |
82 | + "content": { | |
83 | + "type": opts.type | |
84 | + } | |
84 | 85 | } |
85 | - } | |
86 | 86 | |
87 | - if (opts.root) | |
88 | - msg.value.content.root = opts.root | |
89 | - if (opts.original) | |
90 | - msg.value.content.original = opts.original | |
91 | - if (opts.updated) | |
92 | - msg.value.content.updated = opts.updated | |
87 | + if (opts.root) | |
88 | + msg.value.content.root = opts.root | |
89 | + if (opts.original) | |
90 | + msg.value.content.original = opts.original | |
91 | + if (opts.updated) | |
92 | + msg.value.content.updated = opts.updated | |
93 | 93 | |
94 | - msg.value.content.text = textarea.value | |
95 | - console.log(msg) | |
94 | + msg.value.content.text = textarea.value | |
95 | + console.log(msg) | |
96 | 96 | |
97 | - if (opts.type == 'post') | |
98 | - var header = tools.header(msg) | |
99 | - if (opts.type == 'update') | |
100 | - var header = h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))) | |
97 | + if (opts.type == 'post') | |
98 | + var header = tools.header(msg) | |
99 | + if (opts.type == 'update') | |
100 | + var header = h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))) | |
101 | 101 | |
102 | - var preview = h('div', | |
103 | - header, | |
104 | - h('div.message__content', tools.markdown(msg.value.content.text)), | |
105 | - h('button.btn', 'Publish', { | |
106 | - onclick: function () { | |
107 | - sbot.publish(msg.value.content, function (err, msg) { | |
108 | - if(err) throw err | |
109 | - console.log('Published!', msg) | |
110 | - if (opts.type == 'update') { | |
111 | - var originalMessage = document.getElementById(opts.updated.substring(0,10)) | |
112 | - console.log(originalMessage) | |
113 | - opts.messageText = msg.value.content.text | |
114 | - var newMessage = h('div.message__body', | |
115 | - h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))), | |
116 | - h('div', tools.markdown(msg.value.content.text)) | |
117 | - ) | |
118 | - originalMessage.parentNode.replaceChild(newMessage, originalMessage) | |
119 | - newMessage.parentNode.appendChild(buttons) | |
102 | + var preview = h('div', | |
103 | + header, | |
104 | + h('div.message__content', tools.markdown(msg.value.content.text)), | |
105 | + h('button.btn', 'Publish', { | |
106 | + onclick: function () { | |
107 | + if (msg.value.content) { | |
108 | + sbot.publish(msg.value.content, function (err, msg) { | |
109 | + if(err) throw err | |
110 | + console.log('Published!', msg) | |
111 | + if (opts.type == 'update') { | |
112 | + var originalMessage = document.getElementById(opts.updated.substring(0,10)) | |
113 | + console.log(originalMessage) | |
114 | + opts.messageText = msg.value.content.text | |
115 | + var newMessage = h('div.message__body', | |
116 | + h('div.timestamp', 'Edited: ', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))), | |
117 | + h('div', tools.markdown(msg.value.content.text)) | |
118 | + ) | |
119 | + originalMessage.parentNode.replaceChild(newMessage, originalMessage) | |
120 | + newMessage.parentNode.appendChild(buttons) | |
121 | + } else { | |
122 | + if (opts.branch) | |
123 | + cancel = document.getElementById(opts.branch.substring(0,10)) | |
124 | + else | |
125 | + cancel = document.getElementById('composer') | |
126 | + cancel.parentNode.removeChild(cancel) | |
127 | + } | |
128 | + }) | |
120 | 129 | } |
121 | - }) | |
122 | - } | |
123 | - }), | |
124 | - h('button.btn', 'Cancel', { | |
125 | - onclick: function () { | |
126 | - composer.replaceChild(container, composer.firstChild) | |
127 | - container.appendChild(textarea) | |
128 | - container.appendChild(initialButtons) | |
129 | - } | |
130 | - }) | |
131 | - ) | |
132 | - composer.replaceChild(preview, composer.firstChild) | |
130 | + } | |
131 | + }), | |
132 | + h('button.btn', 'Cancel', { | |
133 | + onclick: function () { | |
134 | + composer.replaceChild(container, composer.firstChild) | |
135 | + container.appendChild(textarea) | |
136 | + container.appendChild(initialButtons) | |
137 | + } | |
138 | + }) | |
139 | + ) | |
140 | + composer.replaceChild(preview, composer.firstChild) | |
141 | + } | |
133 | 142 | } |
134 | 143 | }), |
135 | 144 | file_input(function (file) { |
136 | 145 | files.push(file) |
Built with git-ssb-web