git ssb

16+

Dominic / patchbay



Commit 820c6a9e100a474ed87382b2e85bf5efc6040e78

add ssb-blob-files (to replace blob.html.input)

mixmix committed on 10/3/2018, 7:58:42 AM
Parent: 05b26d3ebd80deaf194ceb9accd043342c1d9f3a

Files changed

message/html/compose.jschanged
message/html/compose.mcsschanged
package-lock.jsonchanged
package.jsonchanged
message/html/compose.jsView
@@ -1,23 +1,25 @@
1-const { h, when, send, resolve, Value, computed } = require('mutant')
1 +const { h, when, send, resolve, Value, Array: MutantArray, computed } = require('mutant')
22 const nest = require('depnest')
33 const ssbMentions = require('ssb-mentions')
44 const extend = require('xtend')
55 const addSuggest = require('suggest-box')
6 +const blobFiles = require('ssb-blob-files')
67
78 exports.gives = nest('message.html.compose')
89
910 exports.needs = nest({
1011 'about.async.suggest': 'first',
1112 'channel.async.suggest': 'first',
1213 'emoji.async.suggest': 'first',
1314 'meme.async.suggest': 'first',
14- 'blob.html.input': 'first',
15 + // 'blob.html.input': 'first', // TODO extract fileInput creator below out into patchcore
1516 'message.html.confirm': 'first',
1617 'drafts.sync.get': 'first',
1718 'drafts.sync.set': 'first',
1819 'drafts.sync.remove': 'first',
19- 'settings.obs.get': 'first'
20 + 'settings.obs.get': 'first',
21 + 'sbot.obs.connection': 'first'
2022 })
2123
2224 exports.create = function (api) {
2325 return nest({ 'message.html.compose': compose })
@@ -92,46 +94,60 @@
9294 hasContent.set(true)
9395 }
9496
9597 var isPrivate = location.page === 'private' ||
96- (location.key && !location.value) ||
97- (location.value && location.value.private)
98 + (location.key && !location.value) ||
99 + (location.value && location.value.private)
98100
99- var warningMessage = Value(null)
100- var warning = h('section.warning',
101- { className: when(warningMessage, '-open', '-closed') },
102- [
103- h('div.warning', warningMessage),
104- h('div.close', { 'ev-click': () => warningMessage.set(null) }, 'x')
105- ]
106- )
107- var fileInput = api.blob.html.input(file => {
108- const megabytes = file.size / 1024 / 1024
109- if (megabytes >= 5) {
110- const rounded = Math.floor(megabytes * 100) / 100
111- warningMessage.set([
101 + var warningMessages = MutantArray([])
102 + var warning = computed(warningMessages, msgs => {
103 + if (!msgs.length) return
104 +
105 + return h('section.warnings', msgs.map((m, i) => {
106 + return h('div.warning', [
112107 h('i.fa.fa-exclamation-triangle'),
113- h('strong', file.name),
114- ` is ${rounded}MB - the current limit is 5MB`
108 + h('div.message', m),
109 + h('i.fa.fa-times', { 'ev-click': () => warningMessages.deleteAt(i) })
115110 ])
111 + }))
112 + })
113 +
114 + var fileInput = h('input', {
115 + type: 'file',
116 + // accept,
117 + attributes: { multiple: true },
118 + 'ev-click': () => hasContent.set(true),
119 + 'ev-change': (ev) => {
120 + warningMessages.set([])
121 +
122 + const files = ev.target.files
123 + const opts = {
124 + stripExif: api.settings.obs.get('patchbay.removeExif', true),
125 + isPrivate
126 + }
127 + blobFiles(files, api.sbot.obs.connection, opts, afterBlobed)
128 + }
129 + })
130 + function afterBlobed (err, result) {
131 + if (err) {
132 + console.error(err)
133 + warningMessages.push(err.message)
116134 return
117135 }
118136
119- files.push(file)
120- filesById[file.link] = file
137 + files.push(result)
138 + filesById[result.link] = result
121139
122140 const pos = textArea.selectionStart
123- const embed = file.type.match(/^image/) ? '!' : ''
141 + const embed = result.type.match(/^image/) ? '!' : ''
124142 const spacer = embed ? '\n' : ' '
125- const insertLink = spacer + embed + '[' + file.name + ']' + '(' + file.link + ')' + spacer
143 + const insertLink = spacer + embed + '[' + result.name + ']' + '(' + result.link + ')' + spacer
126144
127145 textArea.value = textArea.value.slice(0, pos) + insertLink + textArea.value.slice(pos)
128146
129- console.log('added:', file)
130- }, { private: isPrivate, removeExif: api.settings.obs.get('patchbay.removeExif', true) })
147 + console.log('added:', result)
148 + }
131149
132- fileInput.onclick = () => hasContent.set(true)
133-
134150 var publishBtn = h('button', { 'ev-click': publish }, isPrivate ? 'Reply' : 'Publish')
135151
136152 var actions = h('section.actions', [
137153 fileInput,
@@ -164,9 +180,9 @@
164180 addSuggest(channelInput, (inputText, cb) => {
165181 if (inputText[0] === '#') {
166182 api.channel.async.suggest(inputText.slice(1), cb)
167183 }
168- }, {cls: 'PatchSuggest'})
184 + }, { cls: 'PatchSuggest' })
169185 channelInput.addEventListener('suggestselect', ev => {
170186 channelInput.value = ev.detail.id // HACK : this over-rides the markdown value
171187 })
172188
@@ -177,9 +193,9 @@
177193 if (char === '@') api.about.async.suggest(wordFragment, feedIdsInThread, cb)
178194 if (char === '#') api.channel.async.suggest(wordFragment, cb)
179195 if (char === ':') api.emoji.async.suggest(wordFragment, cb)
180196 if (char === '&') api.meme.async.suggest(wordFragment, cb)
181- }, {cls: 'PatchSuggest'})
197 + }, { cls: 'PatchSuggest' })
182198
183199 return composer
184200
185201 // scoped
message/html/compose.mcssView
@@ -26,32 +26,30 @@
2626 cursor: not-allowed
2727 }
2828 }
2929
30- section.warning {
30 + section.warnings {
3131 color: #fff
32- background-color: red
3332
34- height: 0
35- padding: 0 .5rem
36- transition: all ease-in .1s
33 + div.warning {
34 + background-color: red
35 + padding: .5rem
36 + margin-bottom: 5px
3737
38- display: flex
39- justify-content: space-between
38 + display: flex
39 + justify-content: start
40 + align-items: center
4041
42 + i.fa-exclamation-triangle { margin-right: .5rem }
4143
42- -open {
43- padding: .5rem
44- height: initial
45- }
44 + div.message {
45 + flex-grow: 1
46 + font-weight: 600
47 + margin-right: .3rem
48 + }
4649
47- i.fa { margin-right: .5rem }
48- div.warning {
49- strong { margin-right: .3rem }
50 + i.fa-times { cursor: pointer }
5051 }
51- div.close {
52- cursor: pointer
53- }
5452 }
5553
5654 section.actions {
5755 display: flex
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 308826 bytes
New file size: 309622 bytes
package.jsonView
@@ -87,8 +87,9 @@
8787 "scuttlebot": "^12.0.0",
8888 "setimmediate": "^1.0.5",
8989 "ssb-about": "^0.1.2",
9090 "ssb-backlinks": "^0.7.3",
91 + "ssb-blob-files": "^1.0.0",
9192 "ssb-blobs": "^1.1.5",
9293 "ssb-chess": "^2.4.1",
9394 "ssb-chess-db": "^1.0.4",
9495 "ssb-config": "^2.3.0",

Built with git-ssb-web