Skip to content

Commit 4671239

Browse files
cameroncookecodex
andcommitted
fix(example): Address Weather review follow-ups
Plumb dew point and location subtitles through the Weather example and make cancelled location searches clear their current loading state safely. Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent b254883 commit 4671239

11 files changed

Lines changed: 33 additions & 10 deletions

example_projects/Weather/Schemas/weather-report.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"feelsLikeC": {
2727
"type": "integer"
2828
},
29+
"dewPointC": {
30+
"type": "integer"
31+
},
2932
"condition": {
3033
"type": "string",
3134
"enum": [
@@ -160,6 +163,7 @@
160163
"highC",
161164
"lowC",
162165
"feelsLikeC",
166+
"dewPointC",
163167
"condition",
164168
"solarProgress",
165169
"sunrise",
@@ -347,6 +351,9 @@
347351
"feelsLikeC": {
348352
"type": "integer"
349353
},
354+
"dewPointC": {
355+
"type": "integer"
356+
},
350357
"condition": {
351358
"type": "string",
352359
"enum": [
@@ -481,6 +488,7 @@
481488
"highC",
482489
"lowC",
483490
"feelsLikeC",
491+
"dewPointC",
484492
"condition",
485493
"solarProgress",
486494
"sunrise",

example_projects/Weather/Weather/ContentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct ContentView: View {
5151
if let report, let selectedLocation {
5252
AtmosWeatherScreen(
5353
locationName: selectedLocation.name,
54+
locationSubtitle: selectedLocation.subtitle,
5455
current: report.current,
5556
hourly: report.hourly,
5657
daily: report.daily,

example_projects/Weather/Weather/Models/WeatherModels.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct CurrentWeather: Equatable, Identifiable, Sendable {
106106
let highC: Int
107107
let lowC: Int
108108
let feelsLikeC: Int
109+
let dewPointC: Int
109110
let condition: WeatherCondition
110111
let solarProgress: SolarDayProgress
111112
let sunrise: LocalClockTime

example_projects/Weather/Weather/Services/MockWeatherDTOFactories.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,39 @@ extension CurrentWeatherDTO {
8585
case .clearDay:
8686
CurrentWeatherDTO(
8787
id: "weather-current-loc-current-san-francisco",
88-
temperatureC: 18, highC: 20, lowC: 12, feelsLikeC: 17, condition: .mostlySunny,
88+
temperatureC: 18, highC: 20, lowC: 12, feelsLikeC: 17, dewPointC: 9, condition: .mostlySunny,
8989
solarProgress: .daylight(0.62), sunrise: clock(6, 18), sunset: clock(19, 42), airQualityIndex: 38, airQualityCategory: .good,
9090
uvIndex: 6, uvCategory: .high, windKph: 13, windDirectionDegrees: 292, humidity: 64,
9191
visibilityKilometers: 16.1, pressureMillibars: 1018, pressureTrend: .rising, precipChance: 5
9292
)
9393
case .rainy:
9494
CurrentWeatherDTO(
9595
id: "weather-current-loc-us-or-portland",
96-
temperatureC: 11, highC: 13, lowC: 9, feelsLikeC: 9, condition: .lightRain,
96+
temperatureC: 11, highC: 13, lowC: 9, feelsLikeC: 9, dewPointC: 8, condition: .lightRain,
9797
solarProgress: .daylight(0.45), sunrise: clock(6, 42), sunset: clock(19, 18), airQualityIndex: 22, airQualityCategory: .good,
9898
uvIndex: 1, uvCategory: .low, windKph: 23, windDirectionDegrees: 225, humidity: 89,
9999
visibilityKilometers: 9.7, pressureMillibars: 1006, pressureTrend: .falling, precipChance: 78
100100
)
101101
case .snowy:
102102
CurrentWeatherDTO(
103103
id: "weather-current-loc-us-co-aspen",
104-
temperatureC: -4, highC: -2, lowC: -10, feelsLikeC: -8, condition: .lightSnow,
104+
temperatureC: -4, highC: -2, lowC: -10, feelsLikeC: -8, dewPointC: -7, condition: .lightSnow,
105105
solarProgress: .daylight(0.50), sunrise: clock(7, 14), sunset: clock(17, 38), airQualityIndex: 18, airQualityCategory: .good,
106106
uvIndex: 2, uvCategory: .low, windKph: 10, windDirectionDegrees: 0, humidity: 78,
107107
visibilityKilometers: 6.4, pressureMillibars: 1022, pressureTrend: .steady, precipChance: 65
108108
)
109109
case .night:
110110
CurrentWeatherDTO(
111111
id: "weather-current-loc-is-reykjavik",
112-
temperatureC: 3, highC: 6, lowC: 1, feelsLikeC: 1, condition: .clearNight,
112+
temperatureC: 3, highC: 6, lowC: 1, feelsLikeC: 1, dewPointC: 0, condition: .clearNight,
113113
solarProgress: .afterSunset, sunrise: clock(5, 46), sunset: clock(20, 24), airQualityIndex: 12, airQualityCategory: .good,
114114
uvIndex: 0, uvCategory: .none, windKph: 6, windDirectionDegrees: 45, humidity: 71,
115115
visibilityKilometers: 16.1, pressureMillibars: 1014, pressureTrend: .steady, precipChance: 8
116116
)
117117
case .stormy:
118118
CurrentWeatherDTO(
119119
id: "weather-current-loc-us-la-new-orleans",
120-
temperatureC: 22, highC: 26, lowC: 20, feelsLikeC: 24, condition: .thunderstorms,
120+
temperatureC: 22, highC: 26, lowC: 20, feelsLikeC: 24, dewPointC: 19, condition: .thunderstorms,
121121
solarProgress: .daylight(0.78), sunrise: clock(6, 8), sunset: clock(19, 52), airQualityIndex: 55, airQualityCategory: .moderate,
122122
uvIndex: 3, uvCategory: .moderate, windKph: 35, windDirectionDegrees: 180, humidity: 86,
123123
visibilityKilometers: 4.8, pressureMillibars: 998, pressureTrend: .falling, precipChance: 92

example_projects/Weather/Weather/Services/WeatherClientDTOs.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct CurrentWeatherDTO: Codable, Equatable, Sendable {
3434
let highC: Int
3535
let lowC: Int
3636
let feelsLikeC: Int
37+
let dewPointC: Int
3738
let condition: WeatherConditionDTO
3839
let solarProgress: SolarDayProgressDTO
3940
let sunrise: LocalClockTimeDTO
@@ -202,6 +203,7 @@ extension CurrentWeather {
202203
highC: dto.highC,
203204
lowC: dto.lowC,
204205
feelsLikeC: dto.feelsLikeC,
206+
dewPointC: dto.dewPointC,
205207
condition: WeatherCondition(dto: dto.condition),
206208
solarProgress: try SolarDayProgress(dto: dto.solarProgress),
207209
sunrise: try LocalClockTime(dto: dto.sunrise),

example_projects/Weather/Weather/Views/AtmosWeatherScreen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct AtmosWeatherScreen: View {
44
let locationName: String
5+
let locationSubtitle: String
56
let current: CurrentWeather
67
let hourly: [HourlyForecast]
78
let daily: [DailyForecast]
@@ -17,7 +18,7 @@ struct AtmosWeatherScreen: View {
1718

1819
ScrollView {
1920
VStack(spacing: 0) {
20-
WeatherHeroView(locationName: locationName, current: current, units: units)
21+
WeatherHeroView(locationName: locationName, locationSubtitle: locationSubtitle, current: current, units: units)
2122

2223
VStack(spacing: 10) {
2324
HourlyForecastCard(forecasts: hourly, current: current, units: units)

example_projects/Weather/Weather/Views/Overlays/LocationPickerView.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ struct LocationPickerView: View {
197197
isLoading = true
198198
searchErrorMessage = nil
199199
let currentQuery = query
200+
defer {
201+
if currentQuery == query {
202+
isLoading = false
203+
}
204+
}
200205

201206
do {
202207
let matches = try await weatherService.searchLocations(matching: currentQuery)
@@ -207,8 +212,6 @@ struct LocationPickerView: View {
207212
results = []
208213
searchErrorMessage = "Search is unavailable right now."
209214
}
210-
211-
isLoading = false
212215
}
213216

214217
private func isSaved(_ location: WeatherLocation) -> Bool {

example_projects/Weather/Weather/Views/Sections/ConditionGrid.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct ConditionGrid: View {
1515
ConditionTile(title: "UV INDEX", value: "\(current.uvIndex)", caption: current.uvLabel, current: current) {
1616
UVViz(value: current.uvIndex, theme: current.theme)
1717
}
18-
ConditionTile(title: "HUMIDITY", value: "\(current.humidity)%", caption: "Dew point: \(WeatherUnitFormatter.temperature(9, units: units))°", current: current) {
18+
ConditionTile(title: "HUMIDITY", value: "\(current.humidity)%", caption: "Dew point: \(WeatherUnitFormatter.temperature(current.dewPointC, units: units))°", current: current) {
1919
FilledBar(value: Double(current.humidity) / 100, theme: current.theme)
2020
}
2121
ConditionTile(

example_projects/Weather/Weather/Views/Sections/WeatherHeroView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct WeatherHeroView: View {
44
let locationName: String
5+
let locationSubtitle: String
56
let current: CurrentWeather
67
let units: WeatherUnits
78

@@ -12,7 +13,7 @@ struct WeatherHeroView: View {
1213
.tracking(-0.3)
1314
.accessibilityIdentifier("weather.heroLocation")
1415

15-
Text("My Location")
16+
Text(locationSubtitle)
1617
.font(.system(size: 13))
1718
.tracking(0.2)
1819
.foregroundStyle(current.theme.foregroundMuted)

example_projects/Weather/WeatherTests/Fixtures/weather-report-loc-current-san-francisco.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"highC": 20,
66
"lowC": 12,
77
"feelsLikeC": 17,
8+
"dewPointC": 9,
89
"condition": "mostly_sunny",
910
"solarProgress": {
1011
"kind": "daylight",
@@ -84,6 +85,7 @@
8485
"highC": 13,
8586
"lowC": 9,
8687
"feelsLikeC": 9,
88+
"dewPointC": 8,
8789
"condition": "light_rain",
8890
"solarProgress": {
8991
"kind": "daylight",

0 commit comments

Comments
 (0)