Fix file metadata not loading when a file is selected initially

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/15/head
trivernis 3 years ago
parent 1c00d2c79f
commit 69f3af1fa5
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -3,7 +3,7 @@
<h1>File Metadata</h1> <h1>File Metadata</h1>
<mat-divider></mat-divider> <mat-divider></mat-divider>
</div> </div>
<app-busy-indicator [blurBackground]="true" [darkenBackground]="false"> <app-busy-indicator [blurBackground]="true" [busy]="this.loading" [darkenBackground]="false">
<div class="file-metadata-entries-scroll-container"> <div class="file-metadata-entries-scroll-container">
<div class="file-metadata-entries"> <div class="file-metadata-entries">
<app-editable-metadata-entry (valueChangeEvent)="this.saveFileName($event)" <app-editable-metadata-entry (valueChangeEvent)="this.saveFileName($event)"
@ -22,7 +22,6 @@
<app-metadata-entry <app-metadata-entry
attributeName="Changed at">{{fileMetadata.change_time | date: 'dd.MM.yy HH:mm:ss'}}</app-metadata-entry> attributeName="Changed at">{{fileMetadata.change_time | date: 'dd.MM.yy HH:mm:ss'}}</app-metadata-entry>
</ng-container> </ng-container>
</div> </div>
</div> </div>
</app-busy-indicator> </app-busy-indicator>

@ -1,8 +1,15 @@
import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core"; import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
OnChanges,
OnInit,
SimpleChanges
} from "@angular/core";
import {File} from "../../../../../api/models/File"; import {File} from "../../../../../api/models/File";
import {FileService} from "../../../../services/file/file.service"; import {FileService} from "../../../../services/file/file.service";
import {FileMetadata} from "../../../../../api/api-types/files"; import {FileMetadata} from "../../../../../api/api-types/files";
import {BusyIndicatorComponent} from "../../app-common/busy-indicator/busy-indicator.component";
@Component({ @Component({
selector: "app-file-metadata", selector: "app-file-metadata",
@ -14,32 +21,34 @@ export class FileMetadataComponent implements OnInit, OnChanges {
@Input() file!: File; @Input() file!: File;
public fileMetadata: FileMetadata | undefined; public fileMetadata: FileMetadata | undefined;
public loading: boolean = false;
@ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent; constructor(private changeDetector: ChangeDetectorRef, private fileService: FileService) {
constructor(private fileService: FileService) {
} }
public async ngOnInit() { public async ngOnInit() {
await this.busyIndicator.wrapAsyncOperation(async () => { this.loading = true;
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
}); this.changeDetector.markForCheck();
this.loading = false;
} }
public async ngOnChanges(changes: SimpleChanges) { public async ngOnChanges(changes: SimpleChanges) {
if (changes["file"] && (!this.fileMetadata || this.fileMetadata.file_id != this.file.id)) { if (changes["file"] && (!this.fileMetadata || this.fileMetadata.file_id != this.file.id)) {
await this.busyIndicator.wrapAsyncOperation(async () => { this.loading = true;
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id); this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
}); this.changeDetector.markForCheck();
this.loading = false;
} }
} }
public async saveFileName(name: string) { public async saveFileName(name: string) {
await this.busyIndicator.wrapAsyncOperation(async () => { this.loading = true;
const newFile = await this.fileService.updateFileName(this.file.id, name); const newFile = await this.fileService.updateFileName(this.file.id, name);
if (this.fileMetadata) { if (this.fileMetadata) {
this.fileMetadata.name = newFile.name; this.fileMetadata.name = newFile.name;
this.changeDetector.markForCheck();
} }
}); this.loading = false;
} }
} }

Loading…
Cancel
Save