@@ -14,6 +14,15 @@ const HOLIDAY_API_KEY = '8eb2582d-3a4c-4fc5-94c8-3e21487d4e23';
14
14
// change this to your own country
15
15
const COUNTRY_CODE = 'US' ;
16
16
17
+ interface Holiday {
18
+ date : string ;
19
+ name : string ;
20
+ }
21
+
22
+ type CalendarEventWithMeta = CalendarEvent <
23
+ { type : 'holiday' ; holiday : Holiday } | { type : 'normal' }
24
+ > ;
25
+
17
26
@Component ( {
18
27
selector : 'mwl-demo-component' ,
19
28
changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -24,7 +33,7 @@ export class DemoComponent implements OnInit {
24
33
25
34
viewDate = startOfYear ( subYears ( new Date ( ) , 1 ) ) ;
26
35
27
- events : CalendarEvent [ ] = [ ] ;
36
+ events : CalendarEventWithMeta [ ] = [ ] ;
28
37
29
38
constructor ( private http : HttpClient , private cdr : ChangeDetectorRef ) { }
30
39
@@ -34,22 +43,23 @@ export class DemoComponent implements OnInit {
34
43
35
44
private fetchHolidays ( ) {
36
45
this . http
37
- . get < { holidays : { date : string ; name : string } [ ] } > (
38
- 'https://holidayapi.com/v1/holidays' ,
39
- {
40
- params : {
41
- country : COUNTRY_CODE ,
42
- year : String ( new Date ( ) . getFullYear ( ) - 1 ) ,
43
- key : HOLIDAY_API_KEY ,
44
- } ,
45
- }
46
- )
46
+ . get < { holidays : Holiday [ ] } > ( 'https://holidayapi.com/v1/holidays' , {
47
+ params : {
48
+ country : COUNTRY_CODE ,
49
+ year : String ( new Date ( ) . getFullYear ( ) - 1 ) ,
50
+ key : HOLIDAY_API_KEY ,
51
+ } ,
52
+ } )
47
53
. subscribe ( ( { holidays } ) => {
48
54
this . events = holidays . map ( ( holiday ) => {
49
55
return {
50
56
start : new Date ( holiday . date ) ,
51
57
title : holiday . name ,
52
58
allDay : true ,
59
+ meta : {
60
+ type : 'holiday' ,
61
+ holiday,
62
+ } ,
53
63
} ;
54
64
} ) ;
55
65
this . cdr . markForCheck ( ) ;
0 commit comments