clean code

This commit is contained in:
Chneemann 2024-06-01 12:31:02 +02:00
parent af86c48aa8
commit c4a6541ccb
3 changed files with 19 additions and 37 deletions

View file

@ -18,7 +18,6 @@ export class AttachmentsComponent {
@Input() openOnSecondaryChat: boolean = false; @Input() openOnSecondaryChat: boolean = false;
@Input() viewWidth: number = 0; @Input() viewWidth: number = 0;
loadingUrl: string = './../../../assets/img/loading.svg'; loadingUrl: string = './../../../assets/img/loading.svg';
cachedImageUrl: string | null = null;
imageUrl: string | null = ''; imageUrl: string | null = '';
constructor( constructor(
@ -31,17 +30,9 @@ export class AttachmentsComponent {
async ngOnInit() { async ngOnInit() {
if (this.filePath) { if (this.filePath) {
// Überprüfen Sie, ob der Bild-URL bereits im Cache vorhanden ist this.imageUrl = await this.downloadFilesService.downloadFiles(
if (!this.cachedImageUrl) {
// Wenn nicht, laden Sie ihn herunter und speichern Sie ihn im Cache
this.cachedImageUrl = await this.downloadFilesService.downloadFiles(
this.filePath this.filePath
); );
console.log('1');
}
// Verwenden Sie den gecachten Bild-URL
this.imageUrl = this.cachedImageUrl;
} }
} }

View file

@ -1,7 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { import {
getDownloadURL, getDownloadURL,
getMetadata,
getStorage, getStorage,
listAll, listAll,
ref, ref,
@ -23,21 +22,21 @@ export class DownloadFilesService {
this.listAllFiles(); this.listAllFiles();
} }
checkChatHasFiles(chatId: string) { async checkChatHasFiles(chatId: string): Promise<string | undefined> {
try {
const storage = getStorage(); const storage = getStorage();
const listRef = ref(storage, `chatFiles/${chatId}`); const listRef = ref(storage, `chatFiles/${chatId}`);
return listAll(listRef)
.then((result) => { const result = await listAll(listRef);
if (result.items.length > 0) { if (result.items.length > 0) {
return result.items[0].fullPath; return result.items[0].fullPath;
} else { } else {
return undefined; return undefined;
} }
}) } catch (error) {
.catch((error) => {
console.error('Error listing files:', error); console.error('Error listing files:', error);
return undefined; return undefined;
}); }
} }
/** /**

View file

@ -1,8 +1,4 @@
import { import { Component, HostListener, OnInit } from '@angular/core';
Component,
HostListener,
OnInit
} from '@angular/core';
import { OverlayService } from '../../../service/overlay.service'; import { OverlayService } from '../../../service/overlay.service';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { SmallBtnComponent } from '../small-btn/small-btn.component'; import { SmallBtnComponent } from '../small-btn/small-btn.component';
@ -19,7 +15,6 @@ export class OverlayComponent implements OnInit {
constructor(private overlayService: OverlayService) {} constructor(private overlayService: OverlayService) {}
/** /**
* Initializes the component and subscribes to overlay data changes. * Initializes the component and subscribes to overlay data changes.
*/ */
@ -29,7 +24,6 @@ export class OverlayComponent implements OnInit {
}); });
} }
/** /**
* Extracts the file type from the file name. * Extracts the file type from the file name.
* @param file The file name. * @param file The file name.
@ -41,7 +35,6 @@ export class OverlayComponent implements OnInit {
return getTag || ''; return getTag || '';
} }
/** /**
* Closes the overlay. * Closes the overlay.
*/ */
@ -49,7 +42,6 @@ export class OverlayComponent implements OnInit {
this.overlayData = ''; this.overlayData = '';
} }
/** /**
* Checks if the contact edit overlay is open and closes it if the click is outside the overlay content. * Checks if the contact edit overlay is open and closes it if the click is outside the overlay content.
* @param event The mouse event. * @param event The mouse event.
@ -59,7 +51,7 @@ export class OverlayComponent implements OnInit {
const targetElement = event.target as HTMLElement; const targetElement = event.target as HTMLElement;
if ( if (
!targetElement.closest('.overlayContent') && !targetElement.closest('.overlayContent') &&
!targetElement.closest('.attachments') !targetElement.closest('.files')
) { ) {
this.onCloseOverlay(); this.onCloseOverlay();
} }