Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions src/components/PhotosPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
</template>

<script lang='ts'>
import type { File } from '@nextcloud/files'

import { getCurrentUser } from '@nextcloud/auth'
import { t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'
Expand Down Expand Up @@ -153,7 +155,7 @@
*/
open: {
type: Boolean,
default: true,

Check warning on line 158 in src/components/PhotosPicker.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Boolean prop should only be defaulted to false
},

/**
Expand All @@ -172,7 +174,7 @@

// List of file ids to not show.
blacklistIds: {
type: Array as PropType<number[]>,
type: Array as PropType<string[]>,
default: () => [],
},

Expand Down Expand Up @@ -229,11 +231,15 @@
},

getFiles() {
this.fetchFiles({}, this.blacklistIds)
this.fetchFiles({}, this.shouldShowFile)
},

refreshFiles() {
this.fetchFiles({ firstResult: 0 }, [...this.blacklistIds, ...this.fetchedFileIds], true)
this.fetchFiles({ firstResult: 0 }, this.shouldShowFile, true)
},

shouldShowFile(file: File) {
return file.attributes['mount-type'] === '' && !this.blacklistIds.includes(file.fileid?.toString() ?? '')
},

emitPickedEvent() {
Expand Down
14 changes: 10 additions & 4 deletions src/mixins/FetchFilesMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { File } from '@nextcloud/files'

import { showError } from '@nextcloud/dialogs'
import { defaultRootPath } from '@nextcloud/files/dav'
import { t } from '@nextcloud/l10n'
Expand Down Expand Up @@ -39,11 +41,11 @@ export default defineComponent({
methods: {
/**
* @param options - Options to pass to getPhotos.
* @param blacklist - Array of ids to filter out.
* @param filter - Function to filter out some files.
* @param force - Force fetching even if doneFetchingFiles is true
* @return The next batch of data depending on global offset.
*/
async fetchFiles(options: Partial<PhotoSearchOptions> = {}, blacklist: number[] = [], force: boolean = false): Promise<number[]> {
async fetchFiles(options: Partial<PhotoSearchOptions> = {}, filter?: (file: File) => boolean, force: boolean = false): Promise<number[]> {
if ((this.doneFetchingFiles && !force) || this.loadingFiles) {
return []
}
Expand All @@ -58,7 +60,7 @@ export default defineComponent({
const numberOfImagesPerBatch = 200

// Load next batch of images
const fetchedFiles = await getPhotos({
let fetchedFiles = await getPhotos({
firstResult: this.fetchedFileIds.length,
nbResults: numberOfImagesPerBatch,
...options,
Expand All @@ -70,11 +72,15 @@ export default defineComponent({
this.doneFetchingFiles = true
}

if (filter !== undefined) {
fetchedFiles = fetchedFiles.filter(filter)
}

const fileIds = fetchedFiles
.map((file) => file.fileid as number)
.filter((fileId) => !this.fetchedFileIds.includes(fileId)) // Filter to prevent duplicate fileIds.

this.fetchedFileIds.push(...fileIds.filter((fileId) => !blacklist.includes(fileId)))
this.fetchedFileIds.push(...fileIds)

this.$store.dispatch('appendFiles', fetchedFiles)

Expand Down
Loading