Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Change setTimeout usage around spot drop modal teleportation

Benjamin Bädorf0f08d439d994
diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal-teleport.directive.ts b/frontend/src/app/spot/components/drop-modal/drop-modal-teleport.directive.ts
deleted file mode 100644
index fff38f58ca1..00000000000
--- a/frontend/src/app/spot/components/drop-modal/drop-modal-teleport.directive.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import {
- Directive,
- OnDestroy,
- OnInit,
- TemplateRef,
-} from "@angular/core";
-import { SpotDropModalTeleportationService } from "./drop-modal-teleportation.service";
-
-@Directive({
- selector: 'ng-template[spotDropModalTeleport]'
-})
-export class SpotDropModalTeleportDirective implements OnInit, OnDestroy {
- constructor(
- private teleportationService: SpotDropModalTeleportationService,
- private template: TemplateRef<any>,
- ) { }
-
- ngOnInit() {
- // Teleports the template to the new target portal
- setTimeout(() => {
- this.teleportationService.activate(this.template);
- });
- }
-
- ngOnDestroy() {
- // Clears the portal on destroy whenever the target is defined
- this.teleportationService.clear();
- }
-}
diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
index e7d9b7ef086..ed9519d77c6 100644
--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
@@ -137,28 +137,27 @@ export class SpotDropModalComponent implements OnDestroy {
*/
setTimeout(() => {
this.teleportationService.activate(this.body)
- });
- this.teleportationService
- .hasRenderedFiltered$
- .pipe(
- filter((hasRendered) => hasRendered),
- take(1),
- )
- .subscribe(() => {
- /*
- * We have to set these listeners next tick, because they're so far up the tree.
- * If the open value was set because of a click listener in the trigger slot,
- * that event would reach the event listener added here and close the modal right away.
- */
- setTimeout(() => {
- document.body.addEventListener('click', this.onGlobalClick);
- document.body.addEventListener('keydown', this.onEscape);
- document.body.addEventListener('scroll', this.onScroll, true);
- window.addEventListener('resize', this.onResize);
- window.addEventListener('orientationchange', this.onResize);
-
- this.recalculateAlignment();
+ this.teleportationService
+ .hasRenderedFiltered$
+ .pipe(
+ filter((hasRendered) => hasRendered),
+ take(1),
+ )
+ .subscribe(() => {
+ /*
+ * We have to set these listeners next tick, because they're so far up the tree.
+ * If the open value was set because of a click listener in the trigger slot,
+ * that event would reach the event listener added here and close the modal right away.
+ */
+ setTimeout(() => {
+ document.body.addEventListener('click', this.onGlobalClick);
+ document.body.addEventListener('keydown', this.onEscape);
+ document.body.addEventListener('scroll', this.onScroll, true);
+ window.addEventListener('resize', this.onResize);
+ window.addEventListener('orientationchange', this.onResize);
+
+ this.recalculateAlignment();
const focusCatcherContainer = document.querySelectorAll("[data-modal-focus-catcher-container='true']")[0];
if (focusCatcherContainer) {
@@ -169,36 +168,35 @@ export class SpotDropModalComponent implements OnDestroy {
}
});
});
- }
+ });
+}
- close():void {
- /*
- * The same as with opening; if we don't deactivate the body after
- * one tick, angular will complain because it already rendered the
- * template, but then gets an update to render `null` in the same tick.
- *
- * To make it happy, we update afterwards
- */
- setTimeout(() => {
- this.teleportationService.clear();
-
- document.body.removeEventListener('click', this.onGlobalClick);
- document.body.removeEventListener('keydown', this.onEscape);
- document.body.removeEventListener('scroll', this.onScroll);
- window.removeEventListener('resize', this.onResize);
- window.removeEventListener('orientationchange', this.onResize);
- });
-
- this.teleportationService
- .hasRenderedFiltered$
- .pipe(
+close():void {
+ this._opened = false;
+ this.teleportationService.clear();
+
+ /*
+ * The same as with opening; if we don't deactivate the body after
+ * one tick, angular will complain because it already rendered the
+ * template, but then gets an update to render `null` in the same tick.
+ *
+ * To make it happy, we update afterwards
+ */
+ document.body.removeEventListener('click', this.onGlobalClick);
+ document.body.removeEventListener('keydown', this.onEscape);
+ document.body.removeEventListener('scroll', this.onScroll);
+ window.removeEventListener('resize', this.onResize);
+ window.removeEventListener('orientationchange', this.onResize);
+
+ this.teleportationService
+ .hasRenderedFiltered$
+ .pipe(
filter((hasRendered) => !hasRendered),
take(1),
)
.subscribe(() => {
- this._opened = false;
this.closed.emit();
- this.cdRef.markForCheck();
+ this.cdRef.detectChanges();
});
}