1212import type { Folder , Header , View } from ' @nextcloud/files'
1313import type { PropType } from ' vue'
1414
15+ import PQueue from ' p-queue'
16+
1517import logger from ' ../logger.ts'
1618
1719/**
@@ -36,6 +38,14 @@ export default {
3638 required: true ,
3739 },
3840 },
41+ setup() {
42+ // Create a queue to ensure that the header is only rendered once at a time
43+ const queue = new PQueue ({ concurrency: 1 })
44+
45+ return {
46+ queue ,
47+ }
48+ },
3949 computed: {
4050 enabled() {
4151 return this .header .enabled ?.(this .currentFolder , this .currentView ) ?? true
@@ -46,19 +56,45 @@ export default {
4656 if (! enabled ) {
4757 return
4858 }
49- this .header .updated (this .currentFolder , this .currentView )
59+ // If the header is enabled, we need to render it
60+ logger .debug (` Enabled ${this .header .id } FilesListHeader ` , { header: this .header })
61+ this .queueUpdate (this .currentFolder , this .currentView )
5062 },
51- currentFolder() {
52- this .header .updated (this .currentFolder , this .currentView )
63+ currentFolder(folder : Folder ) {
64+ // This method can be used to queue an update of the header
65+ // It will ensure that the header is only updated once at a time
66+ this .queueUpdate (folder , this .currentView )
67+ },
68+ currentView(view : View ) {
69+ this .queueUpdate (this .currentFolder , view )
5370 },
5471 },
72+
5573 mounted() {
5674 logger .debug (` Mounted ${this .header .id } FilesListHeader ` , { header: this .header })
57- this .header .render (this .$refs .mount as HTMLElement , this .currentFolder , this .currentView )
75+ const initialRender = () => this .header .render (this .$refs .mount as HTMLElement , this .currentFolder , this .currentView )
76+ this .queue .add (initialRender ).then (() => {
77+ logger .debug (` Rendered ${this .header .id } FilesListHeader ` , { header: this .header })
78+ }).catch ((error ) => {
79+ logger .error (` Error rendering ${this .header .id } FilesListHeader ` , { header: this .header , error })
80+ })
5881 },
59-
6082 destroyed() {
6183 logger .debug (` Destroyed ${this .header .id } FilesListHeader ` , { header: this .header })
6284 },
85+
86+ methods: {
87+ queueUpdate(currentFolder : Folder , currentView : View ) {
88+ // This method can be used to queue an update of the header
89+ // It will ensure that the header is only updated once at a time
90+ this .queue .add (() => this .header .updated (currentFolder , currentView ))
91+ .then (() => {
92+ logger .debug (` Updated ${this .header .id } FilesListHeader ` , { header: this .header })
93+ })
94+ .catch ((error ) => {
95+ logger .error (` Error updating ${this .header .id } FilesListHeader ` , { header: this .header , error })
96+ })
97+ },
98+ },
6399}
64100 </script >
0 commit comments