|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-import { Component } from '@angular/core';
|
|
|
1
|
+import { ChangeDetectorRef, Component } from '@angular/core';
|
|
2
|
2
|
import { Router, RouterLink } from '@angular/router';
|
|
3
|
3
|
import { KakochoService } from '../../services/kakocho-service';
|
|
4
|
4
|
import { DankaService } from '../../services/dankaService';
|
|
|
@@ -46,6 +46,7 @@ export class Dashboard {
|
|
46
|
46
|
private kakochoService: KakochoService,
|
|
47
|
47
|
private dankaService: DankaService,
|
|
48
|
48
|
private router: Router,
|
|
|
49
|
+ private cdr: ChangeDetectorRef,
|
|
49
|
50
|
) {
|
|
50
|
51
|
this.setWeeklyMemorialSummary();
|
|
51
|
52
|
this.setMonthlyMemorialSummary();
|
|
|
@@ -71,6 +72,7 @@ export class Dashboard {
|
|
71
|
72
|
updatedAtLabel: this.formatUpdatedAt(danka.updatedAt),
|
|
72
|
73
|
})),
|
|
73
|
74
|
);
|
|
|
75
|
+ this.cdr.detectChanges();
|
|
74
|
76
|
}
|
|
75
|
77
|
|
|
76
|
78
|
private async setWeeklyMemorialSummary(): Promise<void> {
|
|
|
@@ -97,6 +99,7 @@ export class Dashboard {
|
|
97
|
99
|
return deathDate?.getMonth() === today.getMonth() && deathDate.getDate() === today.getDate();
|
|
98
|
100
|
}).length;
|
|
99
|
101
|
this.upcomingWeeklyMemorialCount = this.weeklyMemorialCount - this.todayMemorialCount;
|
|
|
102
|
+ this.cdr.detectChanges();
|
|
100
|
103
|
}
|
|
101
|
104
|
|
|
102
|
105
|
private async setMonthlyMemorialSummary(): Promise<void> {
|
|
|
@@ -110,6 +113,7 @@ export class Dashboard {
|
|
110
|
113
|
|
|
111
|
114
|
return deathDate.getMonth() === today.getMonth();
|
|
112
|
115
|
}).length;
|
|
|
116
|
+ this.cdr.detectChanges();
|
|
113
|
117
|
}
|
|
114
|
118
|
|
|
115
|
119
|
private async setUpcomingMemorials(): Promise<void> {
|
|
|
@@ -150,6 +154,7 @@ export class Dashboard {
|
|
150
|
154
|
.filter((memorial): memorial is UpcomingMemorial => memorial !== null)
|
|
151
|
155
|
.sort((a, b) => a.date.getTime() - b.date.getTime() || a.title.localeCompare(b.title, 'ja'))
|
|
152
|
156
|
.slice(0, 3);
|
|
|
157
|
+ this.cdr.detectChanges();
|
|
153
|
158
|
}
|
|
154
|
159
|
|
|
155
|
160
|
private isMemorialTarget(deathDate: Date): boolean {
|
|
|
@@ -207,7 +212,7 @@ export class Dashboard {
|
|
207
|
212
|
return nextMemorial ? this.formatDateLabel(nextMemorial, today) : '未設定';
|
|
208
|
213
|
}
|
|
209
|
214
|
|
|
210
|
|
- private formatUpdatedAt(updatedAt: string): string {
|
|
|
215
|
+ private formatUpdatedAt(updatedAt: unknown): string {
|
|
211
|
216
|
const updatedDate = this.parseDate(updatedAt);
|
|
212
|
217
|
const today = this.toDateOnly(new Date());
|
|
213
|
218
|
|
|
|
@@ -253,7 +258,23 @@ export class Dashboard {
|
|
253
|
258
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
254
|
259
|
}
|
|
255
|
260
|
|
|
256
|
|
- private parseDate(value: string): Date | null {
|
|
|
261
|
+ private parseDate(value: unknown): Date | null {
|
|
|
262
|
+ if (!value) {
|
|
|
263
|
+ return null;
|
|
|
264
|
+ }
|
|
|
265
|
+
|
|
|
266
|
+ if (value instanceof Date) {
|
|
|
267
|
+ return value;
|
|
|
268
|
+ }
|
|
|
269
|
+
|
|
|
270
|
+ if (typeof value === 'object' && 'toDate' in value && typeof value.toDate === 'function') {
|
|
|
271
|
+ return value.toDate();
|
|
|
272
|
+ }
|
|
|
273
|
+
|
|
|
274
|
+ if (typeof value !== 'string') {
|
|
|
275
|
+ return null;
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
257
|
278
|
const [year, month, day] = value.split('-').map(Number);
|
|
258
|
279
|
if (!year || !month || !day) {
|
|
259
|
280
|
return null;
|