Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Fix fetching album content when navigating #1406

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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