Images in pin modals !!!!

tutorial
Alix JEUDI--LEMOINE 1 month ago
parent b9088e8d3d
commit 3b4203a8ad

@ -64,7 +64,7 @@
class="relative h-40 mt-2 overflow-hidden rounded-lg flex items-center justify-center" class="relative h-40 mt-2 overflow-hidden rounded-lg flex items-center justify-center"
> >
<div <div
*ngFor="let image of pin.files; let index = index" *ngFor="let imageUrl of imageUrls; let index = index"
[class]=" [class]="
'absolute inset-0 transition-opacity duration-700 ease-in-out' + 'absolute inset-0 transition-opacity duration-700 ease-in-out' +
(index === currentIndex ? ' opacity-100' : ' opacity-0') (index === currentIndex ? ' opacity-100' : ' opacity-0')
@ -74,7 +74,7 @@
class="relative h-40 overflow-hidden rounded-lg flex items-center justify-center" class="relative h-40 overflow-hidden rounded-lg flex items-center justify-center"
> >
<img <img
[src]="image" [src]="imageUrl"
(load)="onImageLoad()" (load)="onImageLoad()"
[hidden]="!imageLoaded" [hidden]="!imageLoaded"
class="object-contain max-h-full max-w-full h-full w-auto mx-auto" class="object-contain max-h-full max-w-full h-full w-auto mx-auto"
@ -83,8 +83,7 @@
*ngIf="!imageLoaded" *ngIf="!imageLoaded"
class="relative inset-0 bg-gray-200 w-52 h-40 mt-2 overflow-hidden rounded-lg flex items-center justify-center" class="relative inset-0 bg-gray-200 w-52 h-40 mt-2 overflow-hidden rounded-lg flex items-center justify-center"
> >
<!-- animate-pulse can be use --> <span class="text-gray-500">Loading image...</span>
<span class="text-gray-500">Image not working</span>
</div> </div>
</div> </div>
</div> </div>

@ -6,29 +6,51 @@ import { ModalService } from '../../services/modal/modal.service';
import { PinService } from '../../services/pin/pin.service'; import { PinService } from '../../services/pin/pin.service';
import { ConfirmModalComponent } from '../confirm-modal/confirm-modal.component'; import { ConfirmModalComponent } from '../confirm-modal/confirm-modal.component';
import { EditPinPopupComponent } from '../edit-pin-popup/edit-pin-popup.component'; import { EditPinPopupComponent } from '../edit-pin-popup/edit-pin-popup.component';
import { ImageService } from '../../services/image/image.service';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
@Component({ @Component({
selector: 'app-pin-marker', selector: 'app-pin-marker',
templateUrl: './pin-marker.component.html', templateUrl: './pin-marker.component.html',
imports: [CommonModule, EditPinPopupComponent, ConfirmModalComponent], imports: [CommonModule, EditPinPopupComponent, ConfirmModalComponent],
standalone: true
}) })
export class PinMarkerComponent { export class PinMarkerComponent {
@Input() pin!: Pin; @Input() pin!: Pin;
@Input() marker!: L.Marker; @Input() marker!: L.Marker;
currentIndex: number = 0; currentIndex: number = 0;
imageUrls: SafeUrl[] = [];
imageLoaded = false;
constructor( constructor(
private pinService: PinService, private pinService: PinService,
private modalService: ModalService private modalService: ModalService,
private imageService: ImageService,
private sanitizer: DomSanitizer
) {} ) {}
ngOnInit() {
this.loadImages();
}
loadImages() {
this.pin.files.forEach(imageId => {
this.imageService.getImage(imageId).subscribe(blob => {
const objectUrl = URL.createObjectURL(blob);
const safeUrl = this.sanitizer.bypassSecurityTrustUrl(objectUrl);
this.imageUrls.push(safeUrl);
if (this.imageUrls.length === this.pin.files.length) {
this.imageLoaded = true;
}
});
});
}
onClosePopup() { onClosePopup() {
this.marker.closePopup(); this.marker.closePopup();
} }
imageLoaded = false;
onImageLoad() { onImageLoad() {
this.imageLoaded = true; this.imageLoaded = true;
} }
@ -62,10 +84,17 @@ export class PinMarkerComponent {
prevSlide(): void { prevSlide(): void {
this.currentIndex = this.currentIndex =
(this.currentIndex - 1 + this.pin.files.length) % this.pin.files.length; (this.currentIndex - 1 + this.imageUrls.length) % this.imageUrls.length;
} }
nextSlide(): void { nextSlide(): void {
this.currentIndex = (this.currentIndex + 1) % this.pin.files.length; this.currentIndex = (this.currentIndex + 1) % this.imageUrls.length;
}
ngOnDestroy() {
// Clean up object URLs to prevent memory leaks
this.imageUrls.forEach(url => {
URL.revokeObjectURL(url.toString());
});
} }
} }

Loading…
Cancel
Save