Change change detection of file gallery and metadata
Signed-off-by: trivernis <trivernis@protonmail.com>pull/3/head
parent
232c12ed8b
commit
6073a6517f
@ -1,48 +1,45 @@
|
||||
import {
|
||||
Component,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnInit,
|
||||
SimpleChanges
|
||||
} from "@angular/core";
|
||||
import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core";
|
||||
import {File} from "../../../../../api/models/File";
|
||||
import {FileService} from "../../../../services/file/file.service";
|
||||
import {FileMetadata} from "../../../../../api/api-types/files";
|
||||
import {BusyIndicatorComponent} from "../../app-common/busy-indicator/busy-indicator.component";
|
||||
|
||||
@Component({
|
||||
selector: "app-file-metadata",
|
||||
templateUrl: "./file-metadata.component.html",
|
||||
styleUrls: ["./file-metadata.component.scss"]
|
||||
styleUrls: ["./file-metadata.component.scss"],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class FileMetadataComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input() file!: File;
|
||||
public fileMetadata: FileMetadata | undefined;
|
||||
public loading = false;
|
||||
|
||||
@ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent;
|
||||
|
||||
constructor(private fileService: FileService) {
|
||||
}
|
||||
|
||||
public async ngOnInit() {
|
||||
this.loading = true;
|
||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||
this.loading = false;
|
||||
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||
});
|
||||
}
|
||||
|
||||
public async ngOnChanges(changes:SimpleChanges) {
|
||||
public async ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes["file"] && (!this.fileMetadata || this.fileMetadata.file_id != this.file.id)) {
|
||||
this.loading = true;
|
||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||
this.loading = false;
|
||||
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async saveFileName(name: string) {
|
||||
this.loading = true;
|
||||
const newFile = await this.fileService.updateFileName(this.file.id, name);
|
||||
if (this.fileMetadata) {
|
||||
this.fileMetadata.name = newFile.name;
|
||||
}
|
||||
this.loading = false;
|
||||
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||
const newFile = await this.fileService.updateFileName(this.file.id, name);
|
||||
if (this.fileMetadata) {
|
||||
this.fileMetadata.name = newFile.name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue