From e9188b61cb78873849520dc93466147180050d89 Mon Sep 17 00:00:00 2001 From: Nebojsa Vuksic Date: Tue, 29 Jul 2025 16:04:18 +0200 Subject: [PATCH] Fix UI bugs with reloading weather data --- .../template/weatherApp/services/MyLocationsViewModel.kt | 4 ++++ .../plugins/template/weatherApp/ui/WeatherAppSample.kt | 6 ++---- .../template/weatherApp/ui/components/WeatherDetailsCard.kt | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/MyLocationsViewModel.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/MyLocationsViewModel.kt index a08e821..c876b86 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/MyLocationsViewModel.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/services/MyLocationsViewModel.kt @@ -67,6 +67,8 @@ internal class MyLocationsViewModel(cs: CoroutineScope) : MyLocationsViewModelAp myLocations.value += locationToAdd selectedLocationIndex.value = myLocations.value.lastIndex } + + onReloadWeatherForecast() } override fun onDeleteLocation(locationToDelete: Location) { @@ -77,6 +79,8 @@ internal class MyLocationsViewModel(cs: CoroutineScope) : MyLocationsViewModelAp if (itemIndex in 0..currentSelectedIndex) { selectedLocationIndex.value = (currentSelectedIndex - 1).coerceAtLeast(0) } + + onReloadWeatherForecast() } override fun onLocationSelected(selectedLocationIndex: Int) { diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt index ae40259..f355fa3 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppSample.kt @@ -68,8 +68,6 @@ private fun LeftColumn( ) { val myLocations = myLocationsViewModelApi.myLocationsFlow.collectAsState(emptyList()).value - // TODO Set selected item on initial showing - Column(modifier) { GroupHeader( ComposeTemplateBundle.message("weather.app.my.locations.header.text"), @@ -158,8 +156,8 @@ private fun RightColumn( .fillMaxWidth() .align(Alignment.CenterHorizontally), weatherForecastData - ) { - weatherViewModelApi.onReloadWeatherForecast() + ) { location -> + weatherViewModelApi.onLoadWeatherForecast(location) } } } diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt index 0347950..c1fac51 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/components/WeatherDetailsCard.kt @@ -26,6 +26,7 @@ import org.jetbrains.jewel.ui.icons.AllIconsKeys import org.jetbrains.plugins.template.ComposeTemplateBundle import org.jetbrains.plugins.template.weatherApp.WeatherAppColors import org.jetbrains.plugins.template.weatherApp.model.DailyForecast +import org.jetbrains.plugins.template.weatherApp.model.Location import org.jetbrains.plugins.template.weatherApp.model.WeatherForecastData import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -46,7 +47,7 @@ import java.util.* internal fun WeatherDetailsCard( modifier: Modifier = Modifier, weatherForecastData: WeatherForecastData, - onReloadWeatherData: () -> Unit + onReloadWeatherData: (Location) -> Unit ) { val currentWeatherForecast = weatherForecastData.currentWeatherForecast val isNightTime = isNightTime(currentWeatherForecast.date) @@ -83,7 +84,7 @@ internal fun WeatherDetailsCard( .background(Color.Transparent) .padding(8.dp), tooltip = { Text("Refresh weather data") }, - onClick = { onReloadWeatherData() }, + onClick = { onReloadWeatherData(weatherForecastData.location) }, ) { Icon( key = AllIconsKeys.Actions.Refresh,