Skip to content

Commit f940c6d

Browse files
committed
enh: use filepicker vue component
Signed-off-by: Hamza Mahjoubi <[email protected]>
1 parent 3d46921 commit f940c6d

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

src/components/ComposerAttachments.vue

+50-12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
multiple
5252
style="display: none;"
5353
@change="onLocalAttachmentSelected">
54+
<FilePicker v-if="isAttachementPickerOpen"
55+
:title="t('mail','Choose a file to add as attachment')"
56+
:buttons="attachementPickerButtons"
57+
:filter-fn="filterAttachements"
58+
@close="()=>isAttachementPickerOpen = false" />
59+
<FilePicker v-if="isLinkPickerOpen"
60+
:title="t('mail','Choose a file to share as a link')"
61+
:multiselect="false"
62+
:buttons="linkPickerButtons"
63+
:filter-fn="filterAttachements"
64+
@close="()=>isLinkPickerOpen = false" />
5465
</div>
5566
</template>
5667

@@ -60,7 +71,8 @@ import trimStart from 'lodash/fp/trimCharsStart.js'
6071
import { getRequestToken } from '@nextcloud/auth'
6172
import { formatFileSize } from '@nextcloud/files'
6273
import prop from 'lodash/fp/prop.js'
63-
import { getFilePickerBuilder, showWarning } from '@nextcloud/dialogs'
74+
import { showWarning } from '@nextcloud/dialogs'
75+
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
6476
import sumBy from 'lodash/fp/sumBy.js'
6577
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
6678

@@ -87,6 +99,7 @@ const mimes = [
8799
export default {
88100
name: 'ComposerAttachments',
89101
components: {
102+
FilePicker,
90103
ComposerAttachment,
91104
ChevronDown,
92105
ChevronUp,
@@ -113,6 +126,23 @@ export default {
113126
attachments: [],
114127
isToggle: false,
115128
hasNextLine: false,
129+
isAttachementPickerOpen: false,
130+
isLinkPickerOpen: false,
131+
attachementPickerButtons: [
132+
{
133+
label: t('mail', 'Choose'),
134+
callback: this.onAddCloudAttachment,
135+
type: 'primary',
136+
},
137+
],
138+
linkPickerButtons: [
139+
{
140+
label: t('mail', 'Choose'),
141+
callback: this.onAddCloudAttachmentLink,
142+
type: 'primary',
143+
},
144+
],
145+
116146
}
117147
},
118148
computed: {
@@ -163,8 +193,8 @@ export default {
163193
},
164194
created() {
165195
this.bus.on('on-add-local-attachment', this.onAddLocalAttachment)
166-
this.bus.on('on-add-cloud-attachment', this.onAddCloudAttachment)
167-
this.bus.on('on-add-cloud-attachment-link', this.onAddCloudAttachmentLink)
196+
this.bus.on('on-add-cloud-attachment', this.openAttachementPicker)
197+
this.bus.on('on-add-cloud-attachment-link', this.OpenctLinkPicker)
168198
this.bus.on('on-add-message-as-attachment', this.onAddMessageAsAttachment)
169199
this.value.map(attachment => {
170200
this.attachments.push({
@@ -180,6 +210,17 @@ export default {
180210
})
181211
},
182212
methods: {
213+
filterAttachements(node) {
214+
const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
215+
const downloadPermissions = downloadShareAttribute !== undefined ? downloadShareAttribute.enabled : true
216+
return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
217+
},
218+
openAttachementPicker() {
219+
this.isAttachementPickerOpen = true
220+
},
221+
OpenctLinkPicker() {
222+
this.isLinkPickerOpen = true
223+
},
183224
onAddLocalAttachment() {
184225
this.$refs.localAttachments.click()
185226
},
@@ -285,11 +326,10 @@ export default {
285326

286327
return done
287328
},
288-
async onAddCloudAttachment() {
289-
const picker = getFilePickerBuilder(t('mail', 'Choose a file to add as attachment')).setMultiSelect(true).build()
290-
329+
async onAddCloudAttachment(nodes) {
291330
try {
292-
const paths = await picker.pick(t('mail', 'Choose a file to add as attachment'))
331+
const paths = nodes.map(node => node.path)
332+
this.cloudAttachement = false
293333
// maybe fiiled front with placeholder loader...?
294334
const filesFromCloud = await Promise.all(paths.map(getFileData))
295335

@@ -332,12 +372,10 @@ export default {
332372
logger.error('could not choose a file as attachment', { error })
333373
}
334374
},
335-
async onAddCloudAttachmentLink() {
336-
const picker = getFilePickerBuilder(t('mail', 'Choose a file to share as a link')).build()
337-
375+
async onAddCloudAttachmentLink(nodes) {
338376
try {
339-
const path = await picker.pick(t('mail', 'Choose a file to share as a link'))
340-
const url = await shareFile(path, getRequestToken())
377+
this.cloudAttachementLink = false
378+
const url = await shareFile(nodes[0].path, getRequestToken())
341379

342380
this.appendToBodyAtCursor(`<a href="${url}">${url}</a>`)
343381
} catch (error) {

0 commit comments

Comments
 (0)