1- import { Component , ChangeDetectionStrategy , inject , signal , effect } from '@angular/core' ;
1+ import { Component , ChangeDetectionStrategy , inject , signal , computed , effect } from '@angular/core' ;
22import { Router } from '@angular/router' ;
33
44import { PainDataService } from '../../services/pain-data.service' ;
5+ import { ShareService } from '../../services/share.service' ;
56import { getPainType } from '../../models/pain-types' ;
67import { BodyViewerComponent } from '../body-viewer/body-viewer.component' ;
78
@@ -17,6 +18,7 @@ const COMMENT_KEY = 'pain-mapper:report-comment';
1718export class ReportComponent {
1819 readonly painData = inject ( PainDataService ) ;
1920 private readonly router = inject ( Router ) ;
21+ private readonly share = inject ( ShareService ) ;
2022
2123 readonly zones = this . painData . zones ;
2224 readonly today = new Date ( ) . toLocaleDateString ( 'fr-FR' , {
@@ -30,7 +32,18 @@ export class ReportComponent {
3032 readonly showViewer = signal ( false ) ;
3133 readonly overviewImages = this . painData . overviewImages ;
3234
35+ readonly copied = signal ( false ) ;
36+ readonly shareUrl = computed ( ( ) => this . zones ( ) . length > 0 ? this . share . getShareUrl ( this . zones ( ) ) : null ) ;
37+
3338 constructor ( ) {
39+ const shared = this . share . extractFromFragment ( ) ;
40+ if ( shared ) {
41+ this . painData . loadZones ( shared ) ;
42+ this . painData . reportImages . set ( new Map ( ) ) ;
43+ this . painData . overviewImages . set ( null ) ;
44+ this . share . clearFragment ( ) ;
45+ }
46+
3447 const needsZones = this . painData . reportImages ( ) . size === 0 && this . painData . zones ( ) . length > 0 ;
3548 const needsOverview = ! this . painData . overviewImages ( ) ;
3649 if ( needsZones || needsOverview ) {
@@ -78,4 +91,12 @@ export class ReportComponent {
7891 print ( ) : void {
7992 window . print ( ) ;
8093 }
94+
95+ async copyShareLink ( ) : Promise < void > {
96+ const url = this . share . getShareUrl ( this . zones ( ) ) ;
97+ await navigator . clipboard . writeText ( url ) ;
98+ this . copied . set ( true ) ;
99+ setTimeout ( ( ) => this . copied . set ( false ) , 2000 ) ;
100+ }
101+
81102}
0 commit comments