diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts index 718953f..f7b06ec 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.ts @@ -42,6 +42,30 @@ export class FileGalleryComponent implements OnChanges, OnInit { tabService.selectedTab.subscribe(() => this.adjustElementSizes()); } + async ngOnInit(): Promise { + if (!this.selectedFile || this.files.indexOf( + this.selectedFile.data) < 0) { + await this.onEntrySelect( + this.getPreselectedEntry() ?? this.entries[0]) + } + } + + public async ngOnChanges(changes: SimpleChanges): Promise { + if (changes["files"]) { + this.entries = this.files.map( + f => new Selectable(f, f.hash == this.selectedFile?.data.hash)); + const selectedIndex = this.files.findIndex( + f => f.hash === this.selectedFile?.data.hash); + + if (!this.selectedFile || selectedIndex < 0) { + await this.onEntrySelect( + this.getPreselectedEntry() ?? this.entries[0]) + } else { + await this.onEntrySelect(this.entries[selectedIndex]) + } + } + } + /** * Called when a new entry is selected * @param {Selectable} entry @@ -75,30 +99,6 @@ export class FileGalleryComponent implements OnChanges, OnInit { } } - async ngOnInit(): Promise { - if (!this.selectedFile || this.files.indexOf( - this.selectedFile.data) < 0) { - await this.onEntrySelect( - this.getPreselectedEntry() ?? this.entries[0]) - } - } - - public async ngOnChanges(changes: SimpleChanges): Promise { - if (changes["files"]) { - this.entries = this.files.map( - f => new Selectable(f, f.hash == this.selectedFile?.data.hash)); - const selectedIndex = this.files.findIndex( - f => f.hash === this.selectedFile?.data.hash); - - if (!this.selectedFile || selectedIndex < 0) { - await this.onEntrySelect( - this.getPreselectedEntry() ?? this.entries[0]) - } else { - await this.onEntrySelect(this.entries[selectedIndex]) - } - } - } - /** * Selects the previous item in the gallery * @returns {Promise} diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html index 10e598e..6a62c74 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.html @@ -1,5 +1,5 @@