1
1
import { AsyncPipe } from '@angular/common' ;
2
- import { ChangeDetectionStrategy , Component , inject , OnInit } from '@angular/core' ;
2
+ import { ChangeDetectionStrategy , Component , inject , input , OnInit } from '@angular/core' ;
3
3
import { ActivatedRoute , RouterLink } from '@angular/router' ;
4
4
import { APIGetTextRequest , APIUser } from '@grpc/spec.pb' ;
5
5
import { TextClient } from '@grpc/spec.pbsc' ;
6
6
import { PageEnvService } from '@services/page-env.service' ;
7
7
import { UserService } from '@services/user' ;
8
8
import * as JsDiff from 'diff' ;
9
- import { combineLatest , EMPTY , Observable , of } from 'rxjs' ;
9
+ import { combineLatest , EMPTY , Observable } from 'rxjs' ;
10
10
import { catchError , debounceTime , distinctUntilChanged , map , switchMap } from 'rxjs/operators' ;
11
11
12
12
import { ToastsService } from '../../toasts/toasts.service' ;
@@ -37,7 +37,22 @@ interface InfoText {
37
37
38
38
@Component ( {
39
39
changeDetection : ChangeDetectionStrategy . OnPush ,
40
- imports : [ RouterLink , UserComponent , AsyncPipe ] ,
40
+ imports : [ ] ,
41
+ selector : 'app-info-text-diff' ,
42
+ template :
43
+ `<pre class="diff">@for (i of diff(); track i) {` +
44
+ `@if (i.removed) {<del>{{i.value}}</del>}` +
45
+ `@if (i.added) {<ins>{{i.value}}</ins>}` +
46
+ `@if (!i.added && !i.removed) {{{i.value}}}` +
47
+ `}</pre>` ,
48
+ } )
49
+ export class InfoTextDiffComponent {
50
+ readonly diff = input . required < Diff [ ] > ( ) ;
51
+ }
52
+
53
+ @Component ( {
54
+ changeDetection : ChangeDetectionStrategy . OnPush ,
55
+ imports : [ RouterLink , UserComponent , AsyncPipe , InfoTextDiffComponent ] ,
41
56
selector : 'app-info-text' ,
42
57
templateUrl : './text.component.html' ,
43
58
} )
@@ -78,7 +93,7 @@ export class InfoTextComponent implements OnInit {
78
93
? {
79
94
revision : response . current . revision ,
80
95
text : response . current . text ,
81
- user$ : response . current . userId ? this . #userService. getUser$ ( response . current . userId ) : of ( null ) ,
96
+ user$ : this . #userService. getUser$ ( response . current . userId ) ,
82
97
}
83
98
: null ,
84
99
diff : JsDiff . diffChars ( response . prev ?. text ? response . prev . text : '' , response . current ?. text ?? '' ) as Diff [ ] ,
@@ -93,7 +108,7 @@ export class InfoTextComponent implements OnInit {
93
108
? {
94
109
revision : response . prev . revision ,
95
110
text : response . prev . text ,
96
- user$ : response . prev . userId ? this . #userService. getUser$ ( response . prev . userId ) : of ( null ) ,
111
+ user$ : this . #userService. getUser$ ( response . prev . userId ) ,
97
112
}
98
113
: null ,
99
114
} ) ) ,
0 commit comments