Fix UI bugs with reloading weather data

This commit is contained in:
Nebojsa Vuksic 2025-07-29 16:04:18 +02:00
parent da436500bf
commit e9188b61cb
3 changed files with 9 additions and 6 deletions

View File

@ -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) {

View File

@ -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)
}
}
}

View File

@ -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,