feat/weather-forecast #8

Merged
CodyWan-Kenobi merged 0 commits from refs/pull/8/head into main 2026-05-16 20:38:05 +00:00
CodyWan-Kenobi commented 2026-05-16 09:25:48 +00:00 (Migrated from codeberg.org)

Summary

Adds an opt-in 5-day forecast to the Weather widget. The toggle is a per-widget config (showForecast, default off), so existing widgets continue to show only current conditions unless the user enables it in the widget settings modal.

Uses OpenWeatherMap's /data/2.5/forecast endpoint (same free-tier key as the existing /weather call). The compact header weather widget is unaffected.

What's new

Server (server/src/services/weather.service.ts + server/src/routes/api.routes.ts)

  • New ForecastDay type and getWeatherWithForecast(apiKey, location) that parallel-fetches current + forecast.
  • aggregateDaily() groups the 3-hourly entries by local-day using city.timezone, picks the entry closest to local noon for the icon/description, and computes the day's min/max/mean. Returns up to 5 future days. Today's partial group is skipped if it has too few samples.
  • A transient /forecast failure falls back to current-weather-only — the widget still renders the current block.
  • POST /api/weather accepts an optional includeForecast: boolean; when set, returns the existing fields plus forecast: ForecastDay[]. GET /api/weather is untouched (env-vars-only path used elsewhere).

Client (client/src/components/widgets/WeatherWidget.tsx and friends)

  • WeatherWidget accepts a new showForecast?: boolean prop. When true, requests the forecast and renders a compact 5-row block below the existing Feels-like / Humidity / Location rows. Each row: localized day name (Intl.DateTimeFormat … weekday: 'short'), midday icon, description, hi/lo temperatures respecting the global C/F preference.
  • client/src/types/index.ts gets a ForecastDay interface and Weather.forecast?: ForecastDay[].
  • client/src/services/api.ts getWeather() gains an optional third parameter { includeForecast?: boolean } and forwards it as a body field.
  • Widget config modal (WidgetConfigModal.tsx) adds a "Show 5-day forecast" checkbox in the Weather section, mirroring the Search widget's checkbox pattern. Form-state plumbing in settings/types.ts and WidgetsTab.tsx handles hydrate + save against widget.config.showForecast.

Compatibility

  • App.tsx widget registry, TabbedWidget, and Header.tsx are unchanged.
  • The existing Weather widget config (only apiKey/location previously) gains an optional showForecast field. Existing widget instances render unchanged because showForecast is missing → false.
  • No new dependencies. No package-lock.json change.

Testing

Tested against an OpenWeatherMap free-tier key with location Strathroy,CA:

  • Default state: existing widget unchanged, no extra API call made.
  • Enable "Show 5-day forecast" → widget renders 5 days below the existing details. Day labels match the local calendar; hi/lo temps and icons match openweathermap.org's web view.
  • Toggle off → forecast block disappears, only the current /weather call is made on the next refresh.
  • Direct API smoke test:
    POST /api/weather { apiKey, location, includeForecast: true }
    
    returns existing fields plus forecast: [5 entries].
  • 401 on the forecast call (e.g. invalid key for that endpoint) returns the current weather without a forecast — widget gracefully degrades.

Type check (tsc --noEmit) reports no new errors in either workspace.

Notes for review

  • Forecast aggregation picks the entry closest to local noon for icon + description, which matches the convention used in most home dashboards. Open to switching to "highest hourly probability" / dominant icon if preferred.
  • Today's group is skipped if it has fewer than 3 entries; otherwise the first row is "today" with the remaining hours. Happy to always-skip today for consistency if reviewers prefer.
  • The toggle deliberately doesn't surface in the compact header widget — its space budget can't accommodate a forecast block.
## Summary Adds an opt-in 5-day forecast to the Weather widget. The toggle is a per-widget config (`showForecast`, default off), so existing widgets continue to show only current conditions unless the user enables it in the widget settings modal. Uses OpenWeatherMap's `/data/2.5/forecast` endpoint (same free-tier key as the existing `/weather` call). The compact header weather widget is unaffected. ## What's new **Server** (`server/src/services/weather.service.ts` + `server/src/routes/api.routes.ts`) - New `ForecastDay` type and `getWeatherWithForecast(apiKey, location)` that parallel-fetches current + forecast. - `aggregateDaily()` groups the 3-hourly entries by **local-day** using `city.timezone`, picks the entry closest to local noon for the icon/description, and computes the day's min/max/mean. Returns up to 5 future days. Today's partial group is skipped if it has too few samples. - A transient `/forecast` failure falls back to current-weather-only — the widget still renders the current block. - `POST /api/weather` accepts an optional `includeForecast: boolean`; when set, returns the existing fields plus `forecast: ForecastDay[]`. `GET /api/weather` is untouched (env-vars-only path used elsewhere). **Client** (`client/src/components/widgets/WeatherWidget.tsx` and friends) - `WeatherWidget` accepts a new `showForecast?: boolean` prop. When true, requests the forecast and renders a compact 5-row block below the existing Feels-like / Humidity / Location rows. Each row: localized day name (`Intl.DateTimeFormat … weekday: 'short'`), midday icon, description, hi/lo temperatures respecting the global C/F preference. - `client/src/types/index.ts` gets a `ForecastDay` interface and `Weather.forecast?: ForecastDay[]`. - `client/src/services/api.ts` `getWeather()` gains an optional third parameter `{ includeForecast?: boolean }` and forwards it as a body field. - Widget config modal (`WidgetConfigModal.tsx`) adds a "Show 5-day forecast" checkbox in the Weather section, mirroring the Search widget's checkbox pattern. Form-state plumbing in `settings/types.ts` and `WidgetsTab.tsx` handles hydrate + save against `widget.config.showForecast`. ## Compatibility - `App.tsx` widget registry, `TabbedWidget`, and `Header.tsx` are unchanged. - The existing `Weather` widget config (only `apiKey`/`location` previously) gains an optional `showForecast` field. Existing widget instances render unchanged because `showForecast` is missing → false. - No new dependencies. No `package-lock.json` change. ## Testing Tested against an OpenWeatherMap free-tier key with location `Strathroy,CA`: - Default state: existing widget unchanged, no extra API call made. - Enable "Show 5-day forecast" → widget renders 5 days below the existing details. Day labels match the local calendar; hi/lo temps and icons match openweathermap.org's web view. - Toggle off → forecast block disappears, only the current `/weather` call is made on the next refresh. - Direct API smoke test: ``` POST /api/weather { apiKey, location, includeForecast: true } ``` returns existing fields plus `forecast: [5 entries]`. - 401 on the forecast call (e.g. invalid key for that endpoint) returns the current weather without a forecast — widget gracefully degrades. Type check (`tsc --noEmit`) reports no new errors in either workspace. ## Notes for review - Forecast aggregation picks the entry closest to local noon for icon + description, which matches the convention used in most home dashboards. Open to switching to "highest hourly probability" / dominant icon if preferred. - Today's group is skipped if it has fewer than 3 entries; otherwise the first row is "today" with the remaining hours. Happy to always-skip today for consistency if reviewers prefer. - The toggle deliberately doesn't surface in the compact header widget — its space budget can't accommodate a forecast block.
thelinuxcast commented 2026-05-16 20:37:58 +00:00 (Migrated from codeberg.org)

Again, I'll merge with some fixes to follow.

Again, I'll merge with some fixes to follow.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
thelinuxcast/Homepage!8
No description provided.