diff --git a/components.json b/components.json index c8f04c6..c6f9bd1 100644 --- a/components.json +++ b/components.json @@ -6,7 +6,7 @@ }, "aliases": { "components": "$lib/components", - "utils": "$lib/utils", + "utils": "$lib/utils/ui", "ui": "$lib/components/ui", "hooks": "$lib/hooks", "lib": "$lib" diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..10a385b --- /dev/null +++ b/cspell.json @@ -0,0 +1,5 @@ +{ + "userWords": [ + "ConfigInterface" + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 64531c5..fc375fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "open-meteo-weather", "version": "0.0.1", "dependencies": { + "@openmeteo/sdk": "^1.23.0", "highcharts": "^12.4.0", "mode-watcher": "^1.1.0", "openmeteo": "^1.2.3" diff --git a/package.json b/package.json index cc36e3b..d6e0dfb 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "vitest-browser-svelte": "^2.0.1" }, "dependencies": { + "@openmeteo/sdk": "^1.23.0", "highcharts": "^12.4.0", "mode-watcher": "^1.1.0", "openmeteo": "^1.2.3" diff --git a/src/lib/components/ui/alert/alert-description.svelte b/src/lib/components/ui/alert/alert-description.svelte index ceccee5..cc805d7 100644 --- a/src/lib/components/ui/alert/alert-description.svelte +++ b/src/lib/components/ui/alert/alert-description.svelte @@ -1,6 +1,6 @@ @@ -304,10 +358,10 @@ style="min-height: 256px" class="weather-week gap-md-2 mb-4 flex flex-col md:flex-row" > - {#await weatherDaily then wd} - {#each wd.daily.time as time, index (index)} + {#if weatherDaily} + {#each weatherDaily.time as time, index (index)} {@const selected = time.getDate() === selectedDay.getDate()} - {#if !isNaN(wd.daily.temperature_2m_max.values(index).toFixed(1))} + {#if !isNaN(weatherDaily.temperature_2m_max.values(index)!)} = ($params.temperature_unit === 'celsius' ? 30 : 104) ? 'white' : 'black'}`} + class="weather-temp-max flex min-w-16.25 justify-center rounded-t p-1 text-sm" + style={`background-color: ${getColor(weatherDaily.temperature_2m_max.values(index)!, $params.temperature_unit)}; color: ${weatherDaily.temperature_2m_min.values(index)! < ($params.temperature_unit === 'celsius' ? 4 : 7) || weatherDaily.temperature_2m_min.values(index)! >= ($params.temperature_unit === 'celsius' ? 30 : 104) ? 'white' : 'black'}`} > - {wd.daily.temperature_2m_max.values(index).toFixed(1)} + {weatherDaily.temperature_2m_max.values(index)!.toFixed(1)} {$params.temperature_unit === 'celsius' ? '°C' : '°F'} = ($params.temperature_unit === 'celsius' ? 30 : 104) ? 'white' : 'black'}`} + class="weather-temp-min flex min-w-16.25 justify-center rounded-b p-1 text-sm" + style={`background: ${getColor(weatherDaily.temperature_2m_min.values(index)!, $params.temperature_unit)}; color: ${weatherDaily.temperature_2m_min.values(index)! < ($params.temperature_unit === 'celsius' ? 4 : 7) || weatherDaily.temperature_2m_min.values(index)! >= ($params.temperature_unit === 'celsius' ? 30 : 104) ? 'white' : 'black'}`} > - {wd.daily.temperature_2m_min.values(index).toFixed(1)} + {weatherDaily.temperature_2m_min.values(index)!.toFixed(1)} {$params.temperature_unit === 'celsius' ? '°C' : '°F'} @@ -368,7 +422,7 @@ - {Number(wd.daily.sunshine_duration.values(index) / 3600).toFixed(0)}h + {Number(weatherDaily.sunshine_duration.values(index)! / 3600).toFixed(0)}h @@ -381,7 +435,7 @@ - {Number(wd.daily.precipitation_sum.values(index)).toFixed( + {Number(weatherDaily.precipitation_sum.values(index)).toFixed( 1 )}{$params.precipitation_unit === 'mm' ? 'mm' : "'"} @@ -389,9 +443,9 @@ {/if} {/each} - {:catch error} - {error.message} - {/await} + {:else} + Loading... + {/if} @@ -410,7 +464,7 @@ Weather Week {location.name} - {#await weather then weather} + {#if weather && weather.entries[0] && weather.entries[0].values} + {@const tempVal = weather.entries[0].values?.[index] ?? '0'} @@ -475,7 +529,7 @@ xlink:href="/images/weather-icons/wi-{weather.hourlyTime[index].getHours() > 6 && weather.hourlyTime[index].getHours() < 21 ? 'day' - : 'night'}-{weatherCodes[weatherCodesHourly[index]]}.svg#Layer_1" + : 'night'}-{weatherCodes[weatherCodesHourly?.[index] ?? 0]}.svg#Layer_1" > @@ -490,7 +544,7 @@ >Temp graph {#each weather.indexes as index, j (j)} - {@const temp = weather.entries[0].values[index]} + {@const temp = Number(weather.entries[0].values?.[index])} {#if !isNaN(temp)} {#each weather.indexes as index, j (j)} - {#if !isNaN(entry.values[index])} + {@const val = entry.values?.[index]} + {@const valNum = Number(val)} + {@const bgColor = getColor(valNum, $params.temperature_unit)} + {#if val !== undefined && !isNaN(valNum)} + {entry.name === 'precipitation' || entry.name === 'temperature_2m' - ? entry.values[index].toFixed(1) - : entry.values[index]}{val} {/if} {/each} @@ -577,7 +611,7 @@ >Wind Dir. {#each weather.indexes as index, j (j)} - {#if !isNaN(weather.windDirections[index])} + {#if weather.windDirections && !isNaN(weather.windDirections[index])} @@ -616,7 +650,7 @@ Sunset: {pad(sunset.getHours())}:{pad(sunset.getMinutes())} - {/await} + {/if}
{error.message}
Loading...