Skip to content

Commit

Permalink
Fix fetching album content when navigating
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Oct 19, 2022
1 parent 23b9b35 commit a9cca46
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
35 changes: 29 additions & 6 deletions src/store/albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ const mutations = {
albumNames.forEach(albumName => delete state.albumsFiles[albumName])
},

/**
* Add files to an album.
*
* @param {object} state vuex state
* @param {object} data destructuring object
* @param {string} data.albumName the album id
* @param {string[]} data.fileIds list of files
*/
setAlbumFiles(state, { albumName, fileIds }) {
const albumFiles = state.albumsFiles[albumName] || []
state.albumsFiles = {
...state.albumsFiles,
[albumName]: [
...albumFiles,
...fileIds.filter(fileId => !albumFiles.includes(fileId)), // Filter to prevent duplicate fileId.
],
}

if (state.albums[albumName] !== undefined) {
state.albums[albumName].nbItems = fileIds.length
}
},

/**
* Add files to an album.
*
Expand Down Expand Up @@ -267,12 +290,12 @@ const actions = {
.entries(properties)
.map(([name, value]) => {
switch (typeof value) {
case 'string':
return `<nc:${name}>${value}</nc:${name}>`
case 'object':
return `<nc:${name}>${JSON.stringify(value)}</nc:${name}>`
default:
return ''
case 'string':
return `<nc:${name}>${value}</nc:${name}>`
case 'object':
return `<nc:${name}>${JSON.stringify(value)}</nc:${name}>`
default:
return ''
}
})
.join()
Expand Down
32 changes: 19 additions & 13 deletions src/views/AlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@

<script>
// eslint-disable-next-line node/no-extraneous-import
import { addNewFileMenuEntry } from '@nextcloud/files'
import { addNewFileMenuEntry, removeNewFileMenuEntry } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth'
import { mapActions, mapGetters } from 'vuex'
import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, NcLoadingIcon, isMobile } from '@nextcloud/vue'
import { Upload, UploadPicker } from '@nextcloud/upload'
import { UploadPicker } from '@nextcloud/upload'
import debounce from 'debounce'

import Close from 'vue-material-design-icons/Close'
Expand Down Expand Up @@ -243,6 +243,16 @@ export default {
showEditAlbumForm: false,

loadingAddCollaborators: false,
newFileMenuEntry: {
id: 'album-add',
displayName: t('photos', 'Add photos to this album'),
templateName: '',
if: (context) => context.route === this.$route.name,
/** Existing icon css class */
iconSvgInline: PlusSvg,
/** Function to be run after creation */
handler: () => { this.showAddPhotosModal = true },
},
}
},

Expand Down Expand Up @@ -296,16 +306,12 @@ export default {
},

mounted() {
addNewFileMenuEntry({
id: 'album-add',
displayName: t('photos', 'Add photos to this album'),
templateName: '',
if: (context) => context.route === this.$route.name,
/** Existing icon css class */
iconSvgInline: PlusSvg,
/** Function to be run after creation */
handler: () => { this.showAddPhotosModal = true },
})
this.fetchAlbumContent()
addNewFileMenuEntry(this.newFileMenuEntry)
},

destroyed() {
removeNewFileMenuEntry(this.newFileMenuEntry)
},

methods: {
Expand Down Expand Up @@ -350,7 +356,7 @@ export default {
this.appendFiles(fetchedFiles)

if (fetchedFiles.length > 0) {
await this.$store.commit('addFilesToAlbum', { albumName: this.albumName, fileIdsToAdd: fileIds })
await this.$store.commit('setAlbumFiles', { albumName: this.albumName, fileIds })
}

logger.debug(`[AlbumContent] Fetched ${fileIds.length} new files: `, fileIds)
Expand Down

0 comments on commit a9cca46

Please sign in to comment.