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 20, 2022
1 parent b69e156 commit e739e51
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_AlbumContent_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_AlbumContent_vue.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

23 changes: 23 additions & 0 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
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 e739e51

Please sign in to comment.