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 {
|
import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core";
|
||||||
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",
|
||||||
templateUrl: "./file-metadata.component.html",
|
templateUrl: "./file-metadata.component.html",
|
||||||
styleUrls: ["./file-metadata.component.scss"]
|
styleUrls: ["./file-metadata.component.scss"],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class FileMetadataComponent implements OnInit, OnChanges {
|
export class FileMetadataComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
@Input() file!: File;
|
@Input() file!: File;
|
||||||
public fileMetadata: FileMetadata | undefined;
|
public fileMetadata: FileMetadata | undefined;
|
||||||
public loading = false;
|
|
||||||
|
@ViewChild(BusyIndicatorComponent) busyIndicator!: BusyIndicatorComponent;
|
||||||
|
|
||||||
constructor(private fileService: FileService) {
|
constructor(private fileService: FileService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ngOnInit() {
|
public async ngOnInit() {
|
||||||
this.loading = true;
|
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||||
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)) {
|
||||||
this.loading = true;
|
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||||
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
this.fileMetadata = await this.fileService.getFileMetadata(this.file.id);
|
||||||
this.loading = false;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async saveFileName(name: string) {
|
public async saveFileName(name: string) {
|
||||||
this.loading = true;
|
await this.busyIndicator.wrapAsyncOperation(async () => {
|
||||||
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.loading = false;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue