Skip to content

Commit

Permalink
fix: upload photo from files picker to album
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Dec 12, 2023
1 parent 9f73a6a commit 3435074
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/components/FilesPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
<div class="file-picker__actions">
<UploadPicker :accept="allowedMimes"
:context="uploadContext"
:destination="photosLocation"
:destination="album.basename"
:root="uploadContext.root"
:multiple="true"
@uploaded="refreshFiles" />
@uploaded="emitUploadedEvent" />
<NcButton type="primary" :disabled="loading || selectedFileIds.length === 0" @click="emitPickedEvent">
<template #icon>
<ImagePlus v-if="!loading" />
Expand Down Expand Up @@ -95,6 +96,7 @@ import FilesSelectionMixin from '../mixins/FilesSelectionMixin.js'
import FilesByMonthMixin from '../mixins/FilesByMonthMixin.js'
import UserConfig from '../mixins/UserConfig.js'
import allowedMimes from '../services/AllowedMimes.js'
import { getCurrentUser } from '@nextcloud/auth'

export default {
name: 'FilesPicker',
Expand Down Expand Up @@ -124,6 +126,10 @@ export default {
],

props: {
album: {
type: Object,
required: true,
},
// Label to show in the submit button.
destination: {
type: String,
Expand All @@ -143,20 +149,38 @@ export default {
},
},

emits: [
'files-uploaded',
'files-picked',
],

data() {
return {
allowedMimes,
targetMonth: null,
uploadContext: {
route: 'albumpicker',
},
}
},

computed: {
...mapGetters([
'files',
]),

/**
* The upload picker context
* We're uploading to the album folder, and the backend handle
* the writing to the default location as well as the album update.
* The context is also used for the NewFileMenu.
*
* @return {Album&{route: string, root: string}}
*/
uploadContext() {
return {
...this.album,
route: 'albumpicker',
root: `dav/photos/${getCurrentUser()?.uid}/albums`,
}
},
},

watch: {
Expand All @@ -172,8 +196,8 @@ export default {
this.fetchFiles('', {}, this.blacklistIds)
},

refreshFiles() {
this.fetchFiles('', { firstResult: 0 }, [...this.blacklistIds, ...this.fetchedFileIds], true)
emitUploadedEvent() {
this.$emit('files-uploaded')
},

emitPickedEvent() {
Expand Down
7 changes: 7 additions & 0 deletions src/views/AlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@
:name="t('photos', 'Add photos to {albumName}', {albumName: albumName})"
@close="showAddPhotosModal = false">
<FilesPicker v-if="album !== undefined"
:album="album"
:destination="album.basename"
:blacklist-ids="albumFileIds"
@files-uploaded="handleFilesUploaded"
@files-picked="handleFilesPicked" />
</NcModal>

Expand Down Expand Up @@ -351,6 +353,11 @@ export default {
}
},

handleFilesUploaded() {
this.showAddPhotosModal = false
this.onUpload()
},

async handleFilesPicked(fileIds) {
this.showAddPhotosModal = false
await this.addFilesToCollection({ collectionFileName: this.album.filename, fileIdsToAdd: fileIds })
Expand Down
1 change: 1 addition & 0 deletions src/views/SharedAlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
:name="t('photos', 'Add photos to {albumName}', {albumName: albumOriginalName})"
@close="showAddPhotosModal = false">
<FilesPicker v-if="album !== undefined"
:album="album"
:destination="album.basename"
:blacklist-ids="albumFileIds"
:loading="loadingAddFilesToAlbum"
Expand Down

0 comments on commit 3435074

Please sign in to comment.