Skip to content

Commit

Permalink
Properly append uploaded photos without fetchiung for the full folder
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Sep 1, 2022
1 parent 3c0ca63 commit 18e9fb6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/services/FileInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { getCurrentUser } from '@nextcloud/auth'
import client from './DavClient'
import request from './DavRequest'
import { genFileInfo } from '../utils/fileUtils'

/**
* Get a file info
*
* @param {string} path the path relative to the user root
* @return {FileInfo} the file info
*/
export default async function(path) {
// getDirectoryContents doesn't accept / for root
const fixedPath = path === '/' ? '' : path

const prefixPath = `/files/${getCurrentUser().uid}`

// fetch listing
const response = await client.stat(prefixPath + fixedPath, {
data: request,
details: true,
})

return genFileInfo(response.data)
}
31 changes: 31 additions & 0 deletions src/store/folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ const mutations = {
Vue.set(state.paths, path, fileid)
}
},

/**
* Append files to a folder
*
* @param {object} state vuex state
* @param {object} data destructuring object
* @param {number} data.fileid id of this folder
* @param {Array} data.files list of files to add
*/
addFilesToFolder(state, { fileid, files }) {
if (fileid >= 0 && files.length > 0) {
// and sort by last modified
const list = files
.sort((a, b) => sortCompare(a, b, 'lastmod'))
.filter(file => file.fileid >= 0)
.map(file => file.fileid)
Vue.set(state.folders, fileid, [...list, ...state.folders[fileid]])
}
},
}

const getters = {
Expand Down Expand Up @@ -99,6 +118,18 @@ const actions = {
addPath(context, { path, fileid }) {
context.commit('addPath', { path, fileid })
},

/**
* Append files to a folder
*
* @param {object} context vuex context
* @param {object} data destructuring object
* @param {number} data.fileid id of this folder
* @param {Array} data.files list of files to add
*/
addFilesToFolder(context, { fileid, files }) {
context.commit('addFilesToFolder', { fileid, files })
},
}

export default { state, mutations, getters, actions }
1 change: 1 addition & 0 deletions src/views/Folders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<script>
import { mapGetters } from 'vuex'
import { UploadPicker } from '@nextcloud/upload'
import { getCurrentUser } from '@nextcloud/auth'
import NcEmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'
import VirtualGrid from 'vue-virtual-grid'
Expand Down

0 comments on commit 18e9fb6

Please sign in to comment.