Add image loading bars

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 2940f8089a
commit cdc0c55053

@ -20,6 +20,7 @@ import { FileGridComponent } from './components/file-grid/file-grid.component';
import {MatSidenavModule} from "@angular/material/sidenav"; import {MatSidenavModule} from "@angular/material/sidenav";
import {MatGridListModule} from "@angular/material/grid-list"; import {MatGridListModule} from "@angular/material/grid-list";
import { FileGridEntryComponent } from './components/file-grid/file-grid-entry/file-grid-entry.component'; import { FileGridEntryComponent } from './components/file-grid/file-grid-entry/file-grid-entry.component';
import {MatProgressBarModule} from "@angular/material/progress-bar";
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -31,21 +32,22 @@ import { FileGridEntryComponent } from './components/file-grid/file-grid-entry/f
FileGridComponent, FileGridComponent,
FileGridEntryComponent, FileGridEntryComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
AppRoutingModule, AppRoutingModule,
BrowserAnimationsModule, BrowserAnimationsModule,
MatCardModule, MatCardModule,
MatListModule, MatListModule,
MatButtonModule, MatButtonModule,
MatToolbarModule, MatToolbarModule,
MatSnackBarModule, MatSnackBarModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
ReactiveFormsModule, ReactiveFormsModule,
MatSidenavModule, MatSidenavModule,
MatGridListModule, MatGridListModule,
], MatProgressBarModule,
],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

@ -1,7 +1,9 @@
<mat-card> <mat-card>
<mat-card-title *ngIf="!!file?.name">{{file?.name}}</mat-card-title> <mat-card-title *ngIf="!!file?.name">{{file?.name}}</mat-card-title>
<mat-card-content> <mat-card-content *ngIf="contentUrl !== undefined">
<img class="entry-image" decoding="async" [src]="contentUrl" alt="image"> <img *ngIf="contentUrl !== undefined" class="entry-image" decoding="async" [src]="contentUrl" alt="File Image">
</mat-card-content> </mat-card-content>
<mat-card-footer>{{file?.mime_type}}, {{file?.hash}}</mat-card-footer> <mat-card-footer>
<mat-progress-bar *ngIf="contentUrl === undefined" mode="indeterminate"></mat-progress-bar>
</mat-card-footer>
</mat-card> </mat-card>

@ -1,9 +1,12 @@
mat-card, mat-card-content { mat-card {
height: 100%; height: calc(100% - 32px);
width: 100%; width: calc(100% - 32px);
padding: 16px;
} }
mat-card-content { mat-card-content {
height: 100%;
width: 100%;
justify-content: center; justify-content: center;
text-align: center; text-align: center;
} }

@ -2,6 +2,7 @@ import {Component, Input, OnInit} from '@angular/core';
import {File} from "../../../models/File"; import {File} from "../../../models/File";
import {FileService} from "../../../services/file/file.service"; import {FileService} from "../../../services/file/file.service";
import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service"; import {ErrorBrokerService} from "../../../services/error-broker/error-broker.service";
import {SafeResourceUrl} from "@angular/platform-browser";
@Component({ @Component({
selector: 'app-file-grid-entry', selector: 'app-file-grid-entry',
@ -11,7 +12,7 @@ import {ErrorBrokerService} from "../../../services/error-broker/error-broker.se
export class FileGridEntryComponent implements OnInit { export class FileGridEntryComponent implements OnInit {
@Input() file: File | undefined; @Input() file: File | undefined;
contentUrl: string | undefined; contentUrl: SafeResourceUrl | undefined;
constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { } constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { }
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {

@ -1,4 +1,4 @@
<mat-grid-list cols="5" rowHeight="1:1"> <mat-grid-list gutterSize="1em" cols="5" rowHeight="1:1">
<mat-grid-tile *ngFor="let file of files"> <mat-grid-tile *ngFor="let file of files">
<app-file-grid-entry [file]="file"></app-file-grid-entry> <app-file-grid-entry [file]="file"></app-file-grid-entry>
</mat-grid-tile> </mat-grid-tile>

@ -21,3 +21,7 @@ mat-drawer-content {
mat-drawer-container { mat-drawer-container {
height: 100%; height: 100%;
} }
app-file-grid {
padding: 1em;
}

@ -1,8 +1,9 @@
import {Inject, Injectable} from '@angular/core'; import {Inject, Injectable, Sanitizer} from '@angular/core';
import {BehaviorSubject} from "rxjs"; import {BehaviorSubject} from "rxjs";
import {File} from "../../models/File"; import {File} from "../../models/File";
import {invoke} from "@tauri-apps/api/tauri"; import {invoke} from "@tauri-apps/api/tauri";
import {DOCUMENT} from "@angular/common"; import {DOCUMENT} from "@angular/common";
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -11,29 +12,20 @@ export class FileService {
displayedFiles = new BehaviorSubject<File[]>([]); displayedFiles = new BehaviorSubject<File[]>([]);
constructor(@Inject(DOCUMENT) private document: Document) { constructor(@Inject(DomSanitizer) private sanitizer: DomSanitizer) {
} }
public async getFiles() { public async getFiles() {
let all_files = await invoke<File[]>("get_all_files"); let all_files = await invoke<File[]>("get_all_files");
this.displayedFiles.next(all_files.slice(0, 50)); this.displayedFiles.next(all_files.slice(70, 100));
} }
public async readFile(hash: string, mime_type: string): Promise<string | undefined> { public async readFile(hash: string, mime_type: string): Promise<SafeResourceUrl> {
const data = await invoke<number[]>("read_file_by_hash", {hash}); const data = await invoke<number[]>("read_file_by_hash", {hash});
const blob = new Blob([new Uint8Array(data)], {type: mime_type}); const blob = new Blob([new Uint8Array(data)], {type: mime_type});
return new Promise<string | undefined>((res, rej) => {
const reader = new FileReader(); const url = URL?.createObjectURL(blob);
reader.onload = (e) => { return this.sanitizer.bypassSecurityTrustResourceUrl(url);
const url = e.target?.result
if (url === null) {
res(undefined);
} else {
res(url as string)
}
};
reader.readAsDataURL(blob);
})
} }
} }

Loading…
Cancel
Save