1
- import { ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef , HostListener , Input , Signal , ViewChild , WritableSignal , computed , effect , inject , signal } from '@angular/core' ;
1
+ import { AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef , HostListener , Input , Signal , ViewChild , WritableSignal , computed , inject , signal } from '@angular/core' ;
2
2
import { CompositionEpisode } from '../../../common/common-read' ;
3
3
import { ViewerService , DomManipulationService } from '../../data-access' ;
4
4
import { ActivatedRoute , Router } from '@angular/router' ;
5
5
import { LangService } from '../../data-access/lang.service' ;
6
- import { DialogComponent } from '../dialog/dialog.component' ;
7
6
import { DomSanitizer } from '@angular/platform-browser' ;
8
7
import { Playlist , PlaylistItem } from '../../../playlist/data-access/playlist.service' ;
9
8
import { EmbedHalperService } from '../../data-access/embed-halper.service' ;
10
9
import { DownloadService } from '../../data-access/download.service' ;
11
- import { Base64 } from '../../utils' ;
10
+
11
+ const CHTNK_LOAD_EVENT_NAME = 'chtnkload'
12
+ const CHTNK_CHANGE_PAGE_EVENT_NAME = 'changepage' ;
13
+ const CHTNK_NSFW_CHOICE_EVENT_NAME = 'nsfwchoice'
14
+ const CHTNK_LIST_RESPONCE_EVENT_NAME = 'listresponse'
15
+ const CHTNK_LIST_REQUEST_EVENT_NAME = 'listrequest'
12
16
13
17
@Component ( {
14
18
selector : 'app-viewer' ,
@@ -22,32 +26,28 @@ import { Base64 } from '../../utils';
22
26
] ,
23
27
changeDetection : ChangeDetectionStrategy . OnPush
24
28
} )
25
- export class ViewerComponent {
29
+ export class ViewerComponent implements AfterViewInit {
26
30
readonly separator : string = '│'
27
31
showNsfw : WritableSignal < boolean > = signal ( false ) ;
28
32
29
33
@Input ( ) episode : CompositionEpisode | undefined = undefined ;
30
-
31
34
@Input ( ) playlist : Playlist = [ ] ;
32
35
@Input ( ) playlistLink : string = "" ;
33
36
@Input ( ) currentPlaylistItem : PlaylistItem | undefined ;
34
37
35
- cdr = inject ( ChangeDetectorRef )
36
-
37
38
initListFromParrentWindow ( ) {
38
39
if ( ! this . embedHelper . isEmbedded ( ) ) return
39
40
40
- this . embedHelper . postMessage ( { } , 'listrequest' ) ;
41
+ this . embedHelper . postMessage ( this . currentPlaylistItem , CHTNK_LIST_REQUEST_EVENT_NAME ) ;
41
42
42
43
window . addEventListener ( 'message' , ( { data} ) => {
43
- if ( data . event != "listresponse" ) return ;
44
+ if ( data . event != CHTNK_LIST_RESPONCE_EVENT_NAME ) return ;
44
45
45
46
this . playlist = data . data as Playlist // !!!
46
47
47
48
this . cdr . detectChanges ( )
48
49
49
50
} , false ) ;
50
-
51
51
}
52
52
53
53
getCyrrentIndex ( ) {
@@ -78,7 +78,6 @@ export class ViewerComponent {
78
78
79
79
constructor ( private el : ElementRef , public viewer : ViewerService , private dm : DomManipulationService , private router : Router , public lang : LangService ) {
80
80
this . initHotKeys ( )
81
- this . initListFromParrentWindow ( ) ;
82
81
}
83
82
84
83
toggleFullScreen = ( ) => this . dm . toggleFullScreen ( this . el . nativeElement )
@@ -94,6 +93,8 @@ export class ViewerComponent {
94
93
ngAfterViewInit ( ) {
95
94
this . viewElement . set ( this . viewRef . nativeElement ) ;
96
95
this . initActiveIndexes ( )
96
+ this . embedHelper . postMessage ( this . currentPlaylistItem , CHTNK_LOAD_EVENT_NAME ) ;
97
+ this . initListFromParrentWindow ( ) ;
97
98
}
98
99
99
100
activeIndexs : WritableSignal < number [ ] > = signal ( [ ] )
@@ -126,7 +127,7 @@ export class ViewerComponent {
126
127
this . embedHelper . postMessage ( {
127
128
total : this . episode ?. images . length ,
128
129
current : activeIndxs . map ( i => i + 1 )
129
- } , 'changepage' ) ;
130
+ } , CHTNK_CHANGE_PAGE_EVENT_NAME ) ;
130
131
131
132
}
132
133
@@ -218,12 +219,12 @@ export class ViewerComponent {
218
219
219
220
onAgree ( ) {
220
221
this . showNsfw . set ( true ) ;
221
- this . embedHelper . postMessage ( true , 'nsfwchoice' ) ;
222
+ this . embedHelper . postMessage ( true , CHTNK_NSFW_CHOICE_EVENT_NAME ) ;
222
223
}
223
224
224
225
onDisagree ( ) {
225
226
this . showNsfw . set ( false ) ;
226
- this . embedHelper . postMessage ( false , 'nsfwchoice' ) ;
227
+ this . embedHelper . postMessage ( false , CHTNK_NSFW_CHOICE_EVENT_NAME ) ;
227
228
228
229
if ( ! this . embedHelper . isEmbedded ( ) )
229
230
this . router . navigate ( [ '/' ] )
@@ -246,6 +247,7 @@ export class ViewerComponent {
246
247
dl : DownloadService = inject ( DownloadService ) ;
247
248
sanitizer : DomSanitizer = inject ( DomSanitizer ) ;
248
249
embedHelper = inject ( EmbedHalperService ) ;
250
+ cdr = inject ( ChangeDetectorRef )
249
251
250
252
//#endregion
251
253
0 commit comments