diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.html b/src/app/components/add-pin-popup/add-pin-popup.component.html index ee3b46e..ec7295e 100644 --- a/src/app/components/add-pin-popup/add-pin-popup.component.html +++ b/src/app/components/add-pin-popup/add-pin-popup.component.html @@ -1,12 +1,3 @@ - - -
([]), @@ -65,7 +66,7 @@ export class AddPinPopupComponent implements OnInit { }); } - onFocus(): void { + onFocus(): void { this.inputFocused = true; } @@ -109,7 +110,7 @@ export class AddPinPopupComponent implements OnInit { debounceTime(200), // Attendre 200ms après la dernière frappe distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente switchMap((query) => { - if(query === null) { + if (query === null) { return of([]); } const trimmedQuery = query.trim(); @@ -154,13 +155,19 @@ export class AddPinPopupComponent implements OnInit { try { const data = await this.exifService.getLocation(files[0]); if (data.latitude !== undefined && data.longitude !== undefined) { - this.autocompleteService.getAddressFromCoordinates(data.latitude, data.longitude).subscribe((address) => { - if (address) { - this.form.get('location')?.setValue(address.display_name); - this.form.get('complete_address')?.setValue(address.display_name); - this.form.get('coordinates')?.setValue([data.latitude, data.longitude]); - } - }); + this.autocompleteService + .getAddressFromCoordinates(data.latitude, data.longitude) + .subscribe((address) => { + if (address) { + this.form.get('location')?.setValue(address.display_name); + this.form + .get('complete_address') + ?.setValue(address.display_name); + this.form + .get('coordinates') + ?.setValue([data.latitude, data.longitude]); + } + }); } } catch (error) { return; @@ -178,34 +185,38 @@ export class AddPinPopupComponent implements OnInit { async submitForm(): Promise { // Marquer tous les champs comme touched pour afficher les erreurs - Object.keys(this.form.controls).forEach(key => { + Object.keys(this.form.controls).forEach((key) => { const control = this.form.get(key); control?.markAsTouched(); }); if (this.form.valid) { - const uploadObservables = await Promise.all(this.files.map(async (file) => { - if(file.size === 0) { - this.uploadError = file.name + ' : ' + 'Image vide'; - return of(null); - } + const uploadObservables = await Promise.all( + this.files.map(async (file) => { + if (file.size === 0) { + this.uploadError = file.name + ' : ' + 'Image vide'; + return of(null); + } - const pictureExifDate = await this.exifService.getDateTime(file); + const pictureExifDate = await this.exifService.getDateTime(file); - return this.imageService.postImage(file, pictureExifDate).pipe( - catchError(error => { - this.uploadError = file.name + ' : ' + error.error.detail || 'Erreur lors de l\'upload de l\'image'; - if (this.dragDropComponent) { - this.dragDropComponent.errorMessage = this.uploadError; - } - return of(null); - }) - ) - })); + return this.imageService.postImage(file, pictureExifDate).pipe( + catchError((error) => { + this.uploadError = + file.name + ' : ' + error.error.detail || + "Erreur lors de l'upload de l'image"; + if (this.dragDropComponent) { + this.dragDropComponent.errorMessage = this.uploadError; + } + return of(null); + }) + ); + }) + ); forkJoin(uploadObservables).subscribe((responses) => { // Vérifier si toutes les réponses sont valides - if (responses.some(response => response === null)) { + if (responses.some((response) => response === null)) { return; // Ne pas continuer si une erreur s'est produite } @@ -217,7 +228,9 @@ export class AddPinPopupComponent implements OnInit { files: this.files, date: this.form.get('date')?.value || null, location: coordinates || [0, 0], // Utiliser les coordonnées pour location - complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value, + complete_address: + this.form.get('complete_address')?.value || + this.form.get('location')?.value, }; // Supprimer le champ coordinates qui n'est pas dans le modèle Pin @@ -236,17 +249,15 @@ export class AddPinPopupComponent implements OnInit { } } - openPinModal() { - this.modalService.openModal(this.modalId); - } - closePinModal() { this.modalService.closeModal(this.modalId); this.form.reset(); this.files = []; this.uploadError = ''; if (this.dragDropComponent) { - this.dragDropComponent.updateFileNamesFromFileList(new DataTransfer().files); + this.dragDropComponent.updateFileNamesFromFileList( + new DataTransfer().files + ); this.dragDropComponent.errorMessage = ''; } } diff --git a/src/app/components/home-navbar/home-navbar.component.html b/src/app/components/home-navbar/home-navbar.component.html index 4ce2815..1396a29 100644 --- a/src/app/components/home-navbar/home-navbar.component.html +++ b/src/app/components/home-navbar/home-navbar.component.html @@ -1,5 +1,6 @@