Skip to content

Commit

Permalink
fix(shares): replace FilePicker in ConversationAvatarEditor
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 26, 2023
1 parent 58da47a commit 222973b
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions src/components/ConversationSettings/ConversationAvatarEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</NcButton>
<NcButton :title="t('settings', 'Choose conversation picture from files')"
:aria-label="t('settings', 'Choose conversation picture from files')"
@click="openFilePicker">
@click="showFilePicker = true">
<template #icon>
<Folder :size="20" />
</template>
Expand Down Expand Up @@ -109,6 +109,14 @@
</div>
</div>
</div>

<FilePickerVue v-if="showFilePicker"
:name="t('spreed', 'Choose your conversation picture')"
:container="container"
:buttons="filePickerButtons"
:multiselect="false"
:mimetype-filter="validMimeTypes"
@close="showFilePicker = false" />
</section>
</template>

Expand All @@ -123,7 +131,8 @@ import Upload from 'vue-material-design-icons/Upload.vue'

import { getRequestToken } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { getFilePickerBuilder, showError } from '@nextcloud/dialogs'
import { showError } from '@nextcloud/dialogs'
import { FilePickerVue } from '@nextcloud/dialogs/filepicker.js'
import { generateUrl } from '@nextcloud/router'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -137,20 +146,14 @@ import { AVATAR } from '../../constants.js'
// eslint-disable-next-line n/no-extraneous-import
import 'cropperjs/dist/cropper.css'

const VALID_MIME_TYPES = ['image/png', 'image/jpeg']

const picker = getFilePickerBuilder(t('spreed', 'Choose your conversation picture'))
.setMultiSelect(false)
.setMimeTypeFilter(VALID_MIME_TYPES)
.setType(1)
.allowDirectories(false)
.build()
const validMimeTypes = ['image/png', 'image/jpeg']

export default {
name: 'ConversationAvatarEditor',

components: {
ConversationIcon,
FilePickerVue,
NcButton,
NcColorPicker,
NcEmojiPicker,
Expand Down Expand Up @@ -187,14 +190,14 @@ export default {
emits: ['avatar-edited'],

setup() {
return { AVATAR }
return { AVATAR, validMimeTypes }
},

data() {
return {
showCropper: false,
showFilePicker: false,
loading: false,
validMimeTypes: VALID_MIME_TYPES,
cropperOptions: {
aspectRatio: 1,
viewMode: 1,
Expand All @@ -211,6 +214,10 @@ export default {
},

computed: {
container() {
return this.$store.getters.getMainContainerSelector()
},

inputId() {
return `account-property-${this.conversation.displayName}`
},
Expand All @@ -222,6 +229,14 @@ export default {
showControls() {
return this.editable && (this.showCropper || this.emojiAvatar)
},

filePickerButtons() {
return [{
label: t('spreed', 'Choose'),
callback: (nodes) => this.handleFileChoose(nodes),
type: 'primary'
}]
},
},

watch: {
Expand Down Expand Up @@ -263,8 +278,12 @@ export default {
reader.readAsDataURL(file)
},

async openFilePicker() {
const path = await picker.pick()
async handleFileChoose(nodes) {
const path = nodes[0]?.path
if (!path) {
return
}

this.loading = true
try {
const { data } = await axios.post(generateUrl('/avatar'), { path })
Expand Down

0 comments on commit 222973b

Please sign in to comment.