Skip to content

Commit c4de99d

Browse files
authored
Merge pull request #94 from joreilly/molecule
molecule code cleanup
2 parents a50aec4 + c4bfe39 commit c4de99d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/viewmodel/CountryDetailsViewModel.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ open class CountryDetailsViewModel : ViewModel(), KoinComponent {
6666
var selectedCountry by remember { mutableStateOf<Country?>(null) }
6767
var selectedYear by remember { mutableStateOf("2022") }
6868

69-
var countryEmissionInfo by remember { mutableStateOf<CountryEmissionsInfo?>(null) }
70-
var countryAssetEmissionsList by remember { mutableStateOf<List<CountryAssetEmissionsInfo>>(emptyList()) }
71-
7269
LaunchedEffect(Unit) {
7370
events.collect { event ->
7471
when (event) {
@@ -81,9 +78,13 @@ open class CountryDetailsViewModel : ViewModel(), KoinComponent {
8178
LaunchedEffect(selectedCountry, selectedYear) {
8279
selectedCountry?.let { country ->
8380
uiState = CountryDetailsUIState.Loading
84-
countryEmissionInfo = climateTraceRepository.fetchCountryEmissionsInfo(country.alpha3, selectedYear).firstOrNull()
85-
countryAssetEmissionsList = climateTraceRepository.fetchCountryAssetEmissionsInfo(country.alpha3)
86-
uiState = CountryDetailsUIState.Success(country, selectedYear, countryEmissionInfo, countryAssetEmissionsList)
81+
try {
82+
val countryEmissionInfo = climateTraceRepository.fetchCountryEmissionsInfo(country.alpha3, selectedYear).firstOrNull()
83+
val countryAssetEmissionsList = climateTraceRepository.fetchCountryAssetEmissionsInfo(country.alpha3)
84+
uiState = CountryDetailsUIState.Success(country, selectedYear, countryEmissionInfo, countryAssetEmissionsList)
85+
} catch (e: Exception) {
86+
uiState = CountryDetailsUIState.Error("Error retrieving data from backend")
87+
}
8788
}
8889
}
8990

0 commit comments

Comments
 (0)