|
1 | 1 | <script> |
2 | 2 | import KPIValue from '../../components/KPIValue.svelte'; |
3 | 3 | import KPIChange from '../../components/KPIChange.svelte'; |
4 | | - import { DateParam, SensorParam } from '../../stores/params'; |
5 | | - import { formatDateDayOfWeek } from '../../formats'; |
| 4 | + import { SensorParam } from '../../stores/params'; |
6 | 5 | import SensorUnit from '../../components/SensorUnit.svelte'; |
7 | | - import IndicatorAnnotations from '../../components/IndicatorAnnotations.svelte'; |
8 | 6 | import MaxDateHint from '../../blocks/MaxDateHint.svelte'; |
9 | | - import IndicatorWarning from '../../blocks/IndicatorWarning.svelte'; |
| 7 | + import NoRecentDataWarning from '../../blocks/NoRecentDataWarning.svelte'; |
10 | 8 | import { defaultDeathSensor, defaultCasesSensor, defaultHospitalSensor, metaDataManager } from '../../stores'; |
11 | | - import IndicatorFallbackWarning from '../../blocks/IndicatorFallbackWarning.svelte'; |
| 9 | + import { onMount, beforeUpdate } from 'svelte'; |
12 | 10 |
|
13 | 11 | /** |
14 | 12 | * @type {import("../../stores/params").DateParam} |
|
27 | 25 | $: DEATHS = new SensorParam($defaultDeathSensor, $metaDataManager); |
28 | 26 | $: HOSPITAL_ADMISSION = new SensorParam($defaultHospitalSensor, $metaDataManager); |
29 | 27 |
|
30 | | - function fetchFallback(fetcher, sensor, region, trend) { |
31 | | - return trend.then((t) => { |
32 | | - if (t && t.value != null) { |
33 | | - return t; |
34 | | - } |
35 | | - return fetcher.fetch1Sensor1Region1DateTrend(sensor, region, DateParam.box(sensor.timeFrame.max)); |
36 | | - }); |
37 | | - } |
38 | | -
|
39 | 28 | $: trends = fetcher.fetchNSensors1Region1DateTrend([CASES, HOSPITAL_ADMISSION, DEATHS], region, date); |
40 | 29 | $: casesTrend = trends[0]; |
41 | | - $: hospitalTrend = fetchFallback(fetcher, HOSPITAL_ADMISSION, region, trends[1]); |
| 30 | + $: hospitalTrend = trends[1]; |
42 | 31 | $: deathTrend = trends[2]; |
43 | | -</script> |
44 | 32 |
|
45 | | -<IndicatorWarning sensor={CASES} {date} {region} {fetcher} /> |
46 | | -<IndicatorAnnotations {date} {region} sensor={CASES} range="sparkLine" /> |
| 33 | + let minMaxDate = new Date(); |
| 34 | +
|
| 35 | + onMount(() => { |
| 36 | + [CASES, HOSPITAL_ADMISSION].map((s) => { |
| 37 | + if (s.timeFrame.max < minMaxDate) { |
| 38 | + minMaxDate = s.timeFrame.max; |
| 39 | + } |
| 40 | + }); |
| 41 | + let urlSearchParams = new URLSearchParams(window.location.search); |
| 42 | + if (!urlSearchParams.has('date')) { |
| 43 | + // if no date is specified in the URL, default to the latest day before today with data from all 3 highlighted indicators |
| 44 | + date.set(minMaxDate); |
| 45 | + } |
| 46 | + }); |
| 47 | +
|
| 48 | + // warningType is indicator of which exact warning message should be shown. |
| 49 | + // By default, when user opens page with no specified date, the date will be set to the latest date we have data for all 3 indicators. |
| 50 | + // In this case, warningType should be set to 1. |
| 51 | + // In case selected date is set to future date (date > minMaxDate, where we don't have recent data for all 3 indicators), the warningType will be set to 2 |
| 52 | + // which has different warning message. |
| 53 | + // In case selected date is set to some date which is < minMaxDate, the warningType will be set to 0 which means that we will not show |
| 54 | + // any warning message. |
| 55 | +
|
| 56 | + // warningType should be set in beforeUpdate() method, to guess correct warningType. |
| 57 | +
|
| 58 | + let warningType = 1; |
| 59 | + beforeUpdate(() => { |
| 60 | + if (date.value > minMaxDate) { |
| 61 | + warningType = 2; |
| 62 | + } else if (date.value < minMaxDate) { |
| 63 | + warningType = 0; |
| 64 | + } else { |
| 65 | + warningType = 1; |
| 66 | + } |
| 67 | + }); |
| 68 | +</script> |
47 | 69 |
|
48 | | -<p> |
49 | | - On {formatDateDayOfWeek(date.value)} |
50 | | - <MaxDateHint sensor={CASES.value} suffix="," {fetcher} /> |
51 | | - the {CASES.valueUnit}s were: |
52 | | -</p> |
| 70 | +<NoRecentDataWarning {minMaxDate} {date} {warningType} /> |
53 | 71 |
|
54 | 72 | <div class="mobile-three-col"> |
55 | 73 | <div class="mobile-kpi"> |
56 | | - <h3>Doctor Visits</h3> |
| 74 | + <h3> |
| 75 | + Doctor Visits |
| 76 | + <MaxDateHint sensor={CASES.value} {fetcher} /> |
| 77 | + </h3> |
57 | 78 | <div> |
58 | 79 | {#await casesTrend} |
59 | 80 | <KPIValue value={null} loading /> |
|
66 | 87 | </div> |
67 | 88 | </div> |
68 | 89 | <div class="mobile-kpi"> |
69 | | - <h3>Hospital Admissions</h3> |
| 90 | + <h3> |
| 91 | + Hospital Admissions |
| 92 | + <MaxDateHint sensor={HOSPITAL_ADMISSION.value} {fetcher} /> |
| 93 | + </h3> |
70 | 94 | <div> |
71 | 95 | {#await hospitalTrend} |
72 | 96 | <KPIValue value={null} loading /> |
73 | 97 | {:then d} |
74 | | - <KPIValue value={d ? d.value : null} asterisk={d != null && (d.value == null || d.date < date.value)} /> |
| 98 | + <KPIValue value={d ? d.value : null} /> |
75 | 99 | {/await} |
76 | 100 | </div> |
77 | 101 | <div class="sub"> |
78 | 102 | <SensorUnit sensor={HOSPITAL_ADMISSION} long /> |
79 | 103 | </div> |
80 | 104 | </div> |
81 | 105 | <div class="mobile-kpi"> |
82 | | - <h3>Deaths</h3> |
| 106 | + <h3> |
| 107 | + Deaths |
| 108 | + <MaxDateHint sensor={DEATHS.value} {fetcher} /> |
| 109 | + </h3> |
83 | 110 | <div> |
84 | 111 | {#await deathTrend} |
85 | 112 | <KPIValue value={null} loading /> |
|
111 | 138 | {#await hospitalTrend} |
112 | 139 | <KPIChange value={null} loading /> |
113 | 140 | {:then d} |
114 | | - <KPIChange |
115 | | - value={d && d.value != null && !Number.isNaN(d.value) ? d.change : null} |
116 | | - asterisk={d != null && (d.value == null || d.date < date.value)} |
117 | | - /> |
| 141 | + <KPIChange value={d && d.value != null && !Number.isNaN(d.value) ? d.change : null} /> |
118 | 142 | {/await} |
119 | 143 | </div> |
120 | 144 | <div class="sub">Relative change to 7 days ago</div> |
|
130 | 154 | <div class="sub">Relative change to 7 days ago</div> |
131 | 155 | </div> |
132 | 156 | </div> |
133 | | - |
134 | | -<IndicatorFallbackWarning trend={hospitalTrend} date={date.value} level={region.level} sensor={HOSPITAL_ADMISSION} /> |
|
0 commit comments