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() viewWidth: number = 0;
loadingUrl: string = './../../../assets/img/loading.svg';
cachedImageUrl: string | null = null;
imageUrl: string | null = '';
constructor(
@ -31,17 +30,9 @@ export class AttachmentsComponent {
async ngOnInit() {
if (this.filePath) {
// Überprüfen Sie, ob der Bild-URL bereits im Cache vorhanden ist
if (!this.cachedImageUrl) {
// Wenn nicht, laden Sie ihn herunter und speichern Sie ihn im Cache
this.cachedImageUrl = await this.downloadFilesService.downloadFiles(
this.imageUrl = await this.downloadFilesService.downloadFiles(
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 {
getDownloadURL,
getMetadata,
getStorage,
listAll,
ref,
@ -23,21 +22,21 @@ export class DownloadFilesService {
this.listAllFiles();
}
checkChatHasFiles(chatId: string) {
async checkChatHasFiles(chatId: string): Promise<string | undefined> {
try {
const storage = getStorage();
const listRef = ref(storage, `chatFiles/${chatId}`);
return listAll(listRef)
.then((result) => {
const result = await listAll(listRef);
if (result.items.length > 0) {
return result.items[0].fullPath;
} else {
return undefined;
}
})
.catch((error) => {
} catch (error) {
console.error('Error listing files:', error);
return undefined;
});
}
}
/**

View file

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