fun withLocationAdded()

in src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppViewModel.kt [122:135]


    fun withLocationAdded(locationToAdd: Location): LocationsUIState {
        val existingIndex = locations.indexOf(locationToAdd)
        return if (existingIndex >= 0) {
            // Location exists, just select it
            LocationsUIState(locations = locations, selectedIndex = existingIndex)
        } else {
            // Add a new location and select it
            val newLocations = locations + locationToAdd
            LocationsUIState(
                locations = newLocations,
                selectedIndex = newLocations.lastIndex
            )
        }
    }