feat: add animation for taskOverlayEdit transition and fix bugs in OverlayComponent

This commit is contained in:
Chneemann 2025-04-11 10:14:25 +02:00
parent 19f1a2de5a
commit 64418d6549
3 changed files with 49 additions and 24 deletions

View file

@ -7,31 +7,31 @@
@if (overlayType === "taskOverlay") { @if (overlayType === "taskOverlay") {
<app-task-overlay <app-task-overlay
[overlayData]="overlayData" [overlayData]="overlayData"
(closeDialogEmitter)="onCloseOverlay($event)" (closeDialogEmitter)="onCloseOverlay()"
></app-task-overlay> ></app-task-overlay>
} @if (overlayType === "taskOverlayEdit") { } @if (overlayType === "taskOverlayEdit") {
<app-task-edit-overlay <app-task-edit-overlay
[overlayData]="overlayData" [overlayData]="overlayData"
[overlayType]="overlayType" [overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay($event)" (closeDialogEmitter)="onCloseOverlay()"
></app-task-edit-overlay> ></app-task-edit-overlay>
} @if (overlayType === "newTaskOverlay") { } @if (overlayType === "newTaskOverlay") {
<app-task-edit-overlay <app-task-edit-overlay
[overlayData]="overlayData" [overlayData]="overlayData"
[overlayType]="overlayType" [overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay($event)" (closeDialogEmitter)="onCloseOverlay()"
></app-task-edit-overlay> ></app-task-edit-overlay>
} @if (overlayType === "dialogOverlay") { } @if (overlayType === "dialogOverlay") {
<app-dialog-overlay <app-dialog-overlay
[overlayData]="overlayData" [overlayData]="overlayData"
[overlayType]="overlayType" [overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay($event)" (closeDialogEmitter)="onCloseOverlay()"
></app-dialog-overlay> ></app-dialog-overlay>
} @if (overlayType === "contactOverlay") { } @if (overlayType === "contactOverlay") {
<app-contact-overlay <app-contact-overlay
[overlayData]="overlayData" [overlayData]="overlayData"
[overlayType]="overlayType" [overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay($event)" (closeDialogEmitter)="onCloseOverlay()"
></app-contact-overlay> ></app-contact-overlay>
} }
</div> </div>

View file

@ -24,7 +24,7 @@
transform: scale(1) translateY(0); transform: scale(1) translateY(0);
opacity: 1; opacity: 1;
transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55), transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55),
opacity 0.4s ease-out; opacity 0.3s ease-out;
} }
} }
@ -35,7 +35,7 @@
& > .overlay-content { & > .overlay-content {
transform: scale(0.95) translateY(20px); transform: scale(0.95) translateY(20px);
opacity: 0; opacity: 0;
transition: transform 0.4s ease-in, opacity 0.4s ease-out; transition: transform 0.3s ease-in, opacity 0.3s ease-out;
} }
} }
} }
@ -43,5 +43,5 @@
.overlay-content { .overlay-content {
transform: scale(0.95) translateY(20px); transform: scale(0.95) translateY(20px);
opacity: 0; opacity: 0;
transition: transform 0.4s ease-out, opacity 0.4s ease-out; transition: transform 0.3s ease-out, opacity 0.3s ease-out;
} }

View file

@ -3,7 +3,6 @@ import { OverlayService } from '../../../services/overlay.service';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { TaskOverlayComponent } from './task-overlay/task-overlay.component'; import { TaskOverlayComponent } from './task-overlay/task-overlay.component';
import { TaskEditOverlayComponent } from './task-edit-overlay/task-edit-overlay.component'; import { TaskEditOverlayComponent } from './task-edit-overlay/task-edit-overlay.component';
import { Router } from '@angular/router';
import { DialogOverlayComponent } from './dialog-overlay/dialog-overlay.component'; import { DialogOverlayComponent } from './dialog-overlay/dialog-overlay.component';
import { ContactOverlayComponent } from './contact-overlay/contact-overlay.component'; import { ContactOverlayComponent } from './contact-overlay/contact-overlay.component';
import { Subject, takeUntil } from 'rxjs'; import { Subject, takeUntil } from 'rxjs';
@ -35,7 +34,7 @@ export class OverlayComponent implements OnInit, OnDestroy {
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
constructor(private overlayService: OverlayService, private router: Router) {} constructor(private overlayService: OverlayService) {}
/** /**
* Checks the overlay data observable from the OverlayService and subscribes to it. * Checks the overlay data observable from the OverlayService and subscribes to it.
@ -53,22 +52,21 @@ export class OverlayComponent implements OnInit, OnDestroy {
} }
/** /**
* Subscribes to the overlay data observable from the OverlayService. * Listens to the overlay data observable from the OverlayService
* Updates the overlay type and data when new data is received. * and handles the changes accordingly.
* Sets the overlay as visible with a slight delay if data is present.
* Marks the overlay as closing and invisible if no data is present.
*/ */
listenToOverlayChanges() { listenToOverlayChanges() {
this.overlayService.overlayData$ this.overlayService.overlayData$
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
.subscribe((data) => { .subscribe((data) => {
if (data) { if (data) {
this.overlayType = data.overlay; if (data.overlay === 'taskOverlayEdit') {
this.overlayData = data.data; this.startClosingAnimation(() => {
this.isClosingAnimation = false; this.updateOverlayData(data);
requestAnimationFrame(() => {
this.shouldShowOverlay = true;
}); });
} else {
this.updateOverlayData(data);
}
} else { } else {
this.isClosingAnimation = true; this.isClosingAnimation = true;
this.shouldShowOverlay = false; this.shouldShowOverlay = false;
@ -76,12 +74,35 @@ export class OverlayComponent implements OnInit, OnDestroy {
}); });
} }
/**
* Updates the overlay data from the given data object.
* @param {any} data the data object containing the overlay type and data
*/
updateOverlayData(data: any) {
this.overlayType = data.overlay;
this.overlayData = data.data;
this.isClosingAnimation = false;
this.shouldShowOverlay = true;
}
/**
* Starts the closing animation and calls the given callback function after the animation has finished.
* @param {() => void} callback the callback function to be called after the animation has finished
*/
startClosingAnimation(callback: () => void) {
this.isClosingAnimation = true;
setTimeout(() => {
callback();
this.isClosingAnimation = false;
}, 300);
}
/** /**
* Closes the overlay by clearing the overlay data from the service. * Closes the overlay by clearing the overlay data from the service.
* @param {boolean} close Indicates the close event. * @param {boolean} close Indicates the close event.
*/ */
onCloseOverlay(close: boolean) { onCloseOverlay() {
this.overlayData = close;
this.overlayService.clearOverlayData(); this.overlayService.clearOverlayData();
} }
@ -93,8 +114,12 @@ export class OverlayComponent implements OnInit, OnDestroy {
onDocumentClick(event: MouseEvent) { onDocumentClick(event: MouseEvent) {
const targetElement = event.target as HTMLElement; const targetElement = event.target as HTMLElement;
if (targetElement && targetElement.classList.contains('overlay')) { if (
this.onCloseOverlay(false); targetElement &&
targetElement.classList.contains('overlay') &&
!targetElement.closest('.overlay-content')
) {
this.onCloseOverlay();
} }
} }
} }