modules/message/html/compose.jsView |
---|
25 | 25 | var files = [] |
26 | 26 | var filesById = {} |
27 | 27 | var focused = Value(false) |
28 | 28 | var hasContent = Value(false) |
| 29 | + var publishing = Value(false) |
29 | 30 | var getProfileSuggestions = api.profile.async.suggest() |
30 | 31 | var getChannelSuggestions = api.channel.async.suggest() |
31 | 32 | |
32 | 33 | var blurTimeout = null |
47 | 48 | clearTimeout(blurTimeout) |
48 | 49 | blurTimeout = setTimeout(() => focused.set(false), 200) |
49 | 50 | }, |
50 | 51 | 'ev-focus': send(focused.set, true), |
| 52 | + disabled: publishing, |
51 | 53 | placeholder |
52 | 54 | }) |
53 | 55 | |
54 | 56 | var fileInput = api.blob.html.input(file => { |
64 | 66 | fileInput.onclick = function () { |
65 | 67 | hasContent.set(true) |
66 | 68 | } |
67 | 69 | |
68 | | - var publishBtn = h('button', { 'ev-click': publish }, 'Publish') |
| 70 | + var publishBtn = h('button', { |
| 71 | + 'ev-click': publish, |
| 72 | + disabled: publishing |
| 73 | + }, when(publishing, 'Publishing...', 'Publish')) |
69 | 74 | |
70 | 75 | var actions = h('section.actions', [ |
71 | 76 | fileInput, |
72 | 77 | publishBtn |
110 | 115 | |
111 | 116 | |
112 | 117 | |
113 | 118 | function publish () { |
114 | | - publishBtn.disabled = true |
| 119 | + publishing.set(true) |
115 | 120 | |
116 | 121 | meta = extend(resolve(meta), { |
117 | 122 | text: textArea.value, |
118 | 123 | mentions: mentions(textArea.value).map(mention => { |
130 | 135 | if (typeof prepublish === 'function') { |
131 | 136 | meta = prepublish(meta) |
132 | 137 | } |
133 | 138 | } catch (err) { |
134 | | - publishBtn.disabled = false |
| 139 | + publishing.set(false) |
135 | 140 | if (cb) cb(err) |
136 | 141 | else throw err |
137 | 142 | } |
138 | 143 | |
139 | 144 | return api.message.async.publish(meta, done) |
140 | 145 | |
141 | 146 | function done (err, msg) { |
142 | | - publishBtn.disabled = false |
| 147 | + publishing.set(false) |
143 | 148 | if (err) throw err |
144 | 149 | else if (msg) textArea.value = '' |
145 | 150 | if (cb) cb(err, msg) |
146 | 151 | } |