1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , OnDestroy } from '@angular/core' ;
22import { equalArray } from 'src/app/util/util' ;
33import { LoaderService } from 'src/app/service/loader/data-loader.service' ;
44import * as d3 from 'd3' ;
55import { Router , ActivatedRoute } from '@angular/router' ;
66import { Location } from '@angular/common' ;
77import { MatChip } from '@angular/material/chips' ;
8+ import { Subject } from 'rxjs' ;
9+ import { takeUntil , distinctUntilChanged } from 'rxjs/operators' ;
810import * as md from 'markdown-it' ;
911import {
1012 ModalMessageComponent ,
@@ -23,7 +25,7 @@ import { ThemeService } from '../../service/theme.service';
2325 templateUrl : './circular-heatmap.component.html' ,
2426 styleUrls : [ './circular-heatmap.component.css' ] ,
2527} )
26- export class CircularHeatmapComponent implements OnInit {
28+ export class CircularHeatmapComponent implements OnInit , OnDestroy {
2729 Routing : string = '/activity-description' ;
2830 markdown : md = md ( ) ;
2931 maxLevelOfMaturity : number = - 1 ;
@@ -53,6 +55,8 @@ export class CircularHeatmapComponent implements OnInit {
5355 theme : string ;
5456 theme_colors ! : Record < string , string > ;
5557
58+ private destroy$ = new Subject < void > ( ) ;
59+
5660 constructor (
5761 private loader : LoaderService ,
5862 private sectorService : SectorService ,
@@ -126,7 +130,7 @@ export class CircularHeatmapComponent implements OnInit {
126130 } ) ;
127131 } ) ;
128132 // Reactively handle theme changes (if user toggles later)
129- this . themeService . theme$ . subscribe ( ( theme : string ) => {
133+ this . themeService . theme$ . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( theme : string ) => {
130134 const css = getComputedStyle ( document . body ) ;
131135 this . theme_colors = {
132136 background : css . getPropertyValue ( '--heatmap-background' ) . trim ( ) ,
@@ -140,13 +144,20 @@ export class CircularHeatmapComponent implements OnInit {
140144 } ) ;
141145 }
142146
147+ ngOnDestroy ( ) : void {
148+ this . destroy$ . next ( ) ;
149+ this . destroy$ . complete ( ) ;
150+ }
151+
143152 checkUrlFragmentForActivity ( ) {
144153 // Check if there's a URL fragment that might be an activity UUID
145- this . route . fragment . subscribe ( fragment => {
146- if ( fragment && this . dataStore ) {
147- this . navigateToActivityByUuid ( fragment ) ;
148- }
149- } ) ;
154+ this . route . fragment
155+ . pipe ( takeUntil ( this . destroy$ ) , distinctUntilChanged ( ) )
156+ . subscribe ( fragment => {
157+ if ( fragment && this . dataStore ) {
158+ this . navigateToActivityByUuid ( fragment ) ;
159+ }
160+ } ) ;
150161 }
151162
152163 displayMessage ( dialogInfo : DialogInfo ) {
@@ -623,7 +634,11 @@ export class CircularHeatmapComponent implements OnInit {
623634
624635 closeOverlay ( ) {
625636 // Clear the URL fragment when closing overlay
626- this . router . navigate ( [ ] , { relativeTo : this . route , fragment : undefined , queryParamsHandling : 'preserve' } ) ;
637+ this . router . navigate ( [ ] , {
638+ relativeTo : this . route ,
639+ fragment : undefined ,
640+ queryParamsHandling : 'preserve' ,
641+ } ) ;
627642 this . showOverlay = false ;
628643 }
629644
0 commit comments