Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions apps/files/src/eventbus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare module '@nextcloud/event-bus' {
'files:favorites:removed': Node
'files:favorites:added': Node

'files:filters:changed': undefined

'files:node:created': Node
'files:node:deleted': Node
'files:node:updated': Node
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/filters/HiddenFilesFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HiddenFilesFilter extends FileListFilter {

constructor() {
super('files:hidden', 0)
this.showHidden = loadState<UserConfig>('files', 'config', { show_hidden: false }).show_hidden
this.showHidden = loadState<Partial<UserConfig>>('files', 'config', { show_hidden: false }).show_hidden

subscribe('files:config:updated', ({ key, value }) => {
if (key === 'show_hidden') {
Expand Down
7 changes: 6 additions & 1 deletion apps/files/src/filters/TypeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ class TypeFilter extends FileListFilter {

public setPresets(presets?: ITypePreset[]) {
this.currentPresets = presets ?? []
this.currentInstance!.$props.presets = presets
if (this.currentInstance !== undefined) {
// could be called before the instance was created
// (meaning the files list is not mounted yet)
this.currentInstance.$props.presets = presets
}

this.filterUpdated()

const chips: IFileListFilterChip[] = []
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/store/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { FilterUpdateChipsEvent, IFileListFilter, IFileListFilterChip } from '@nextcloud/files'
import { subscribe } from '@nextcloud/event-bus'
import { emit, subscribe } from '@nextcloud/event-bus'
import { getFileListFilters } from '@nextcloud/files'
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
Expand All @@ -20,7 +20,6 @@ function isFileListFilterWithUi(value: IFileListFilter): value is Required<IFile
export const useFiltersStore = defineStore('filters', () => {
const chips = ref<Record<string, IFileListFilterChip[]>>({})
const filters = ref<IFileListFilter[]>([])
const filtersChanged = ref(false)

/**
* Currently active filter chips
Expand Down Expand Up @@ -77,7 +76,7 @@ export const useFiltersStore = defineStore('filters', () => {
* @private
*/
function onFilterUpdate() {
filtersChanged.value = true
emit('files:filters:changed')
}

/**
Expand Down Expand Up @@ -122,7 +121,6 @@ export const useFiltersStore = defineStore('filters', () => {
chips,
filters,
filtersWithUI,
filtersChanged,

// getters / computed
activeChips,
Expand Down
14 changes: 3 additions & 11 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,6 @@ export default defineComponent({
&& this.currentFolder && (this.currentFolder.permissions & Permission.SHARE) !== 0
},

filtersChanged() {
return this.filtersStore.filtersChanged
},

showCustomEmptyView() {
return !this.loading && this.isEmptyDir && this.currentView?.emptyView !== undefined
},
Expand Down Expand Up @@ -516,13 +512,6 @@ export default defineComponent({
// Also refresh the filtered content
this.filterDirContent()
},

filtersChanged() {
if (this.filtersChanged) {
this.filterDirContent()
this.filtersStore.filtersChanged = false
}
},
},

async mounted() {
Expand All @@ -532,6 +521,9 @@ export default defineComponent({
// reload on settings change
subscribe('files:config:updated', this.fetchContent)

// filter content if filter were changed
subscribe('files:filters:changed', this.filterDirContent)

// Finally, fetch the current directory contents
await this.fetchContent()
if (this.fileId) {
Expand Down
Loading