Skip to content

Commit 462d8c3

Browse files
committed
add year as parameter
1 parent b644107 commit 462d8c3

File tree

13 files changed

+27
-10
lines changed

13 files changed

+27
-10
lines changed

composeApp/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ kotlin {
5454
implementation(compose.foundation)
5555
implementation(compose.material3)
5656
implementation(compose.ui)
57+
implementation(compose.components.resources)
58+
implementation(compose.components.uiToolingPreview)
5759

60+
5861
implementation(libs.koin.core)
5962
implementation(libs.koin.compose)
6063

@@ -87,6 +90,14 @@ kotlin {
8790
appleMain.dependencies {
8891
implementation(libs.ktor.client.darwin)
8992
}
93+
94+
95+
val desktopTest by getting
96+
97+
// Adds the desktop test dependency
98+
desktopTest.dependencies {
99+
implementation(compose.desktop.currentOs)
100+
}
90101
}
91102
}
92103

composeApp/src/androidMain/kotlin/dev/johnoreilly/climatetrace/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ class CountryListScreen : Screen {
7777
}
7878
}
7979

80-

composeApp/src/commonMain/kotlin/App.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import androidx.compose.runtime.Composable
33
import cafe.adriel.voyager.navigator.Navigator
44
import dev.johnoreilly.climatetrace.di.commonModule
55
import dev.johnoreilly.climatetrace.ui.ClimateTraceScreen
6+
import org.jetbrains.compose.ui.tooling.preview.Preview
67
import org.koin.compose.KoinApplication
78

89

10+
@Preview
911
@Composable
1012
fun App() {
1113
KoinApplication(application = {

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/remote/ClimateTraceApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ClimateTraceApi(
7474
suspend fun fetchAssets() = client.get("$baseUrl/assets").body<AssetsResult>()
7575

7676
suspend fun fetchCountryAssets(countryCode: String) = client.get("$baseUrl/assets?countries=$countryCode").body<AssetsResult>()
77-
suspend fun fetchCountryEmissionsInfo(countryCode: String) = client.get("$baseUrl/country/emissions?since=2022&to=2022&countries=$countryCode").body<List<CountryEmissionsInfo>>()
77+
suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = client.get("$baseUrl/country/emissions?since=$year&to=$year&countries=$countryCode").body<List<CountryEmissionsInfo>>()
7878

7979
suspend fun fetchCountryAssetEmissionsInfo(countryCode: String) = client.get("$baseUrl/assets/emissions?countries=$countryCode").body<Map<String, List<CountryAssetEmissionsInfo>>>()[countryCode]
8080
}

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/ui/ClimateTraceScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ClimateTraceScreen: Screen {
110110
Spacer(modifier = Modifier.width(1.dp).fillMaxWidth())
111111
CountryInfoDetailedView(
112112
country = selectedCountry,
113+
year = viewModel.year,
113114
countryEmissionInfo = countryEmissionInfo,
114115
countryAssetEmissionsList = countryAssetEmissions,
115116
isLoading = isLoadingCountryDetails
@@ -135,6 +136,7 @@ class ClimateTraceScreen: Screen {
135136
Box(Modifier.fillMaxHeight()) {
136137
CountryInfoDetailedView(
137138
country = viewModel.selectedCountry.value,
139+
year = viewModel.year,
138140
countryEmissionInfo = countryEmissionInfo,
139141
countryAssetEmissionsList = countryAssetEmissions,
140142
isLoading = isLoadingCountryDetails
@@ -287,4 +289,3 @@ fun CountryRow(
287289
}
288290

289291

290-

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/ui/CountryEmissionsScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ data class CountryEmissionsScreen(val country: Country) : Screen {
5050
Column(Modifier.padding(it)) {
5151
CountryInfoDetailedView(
5252
country,
53+
viewModel.year,
5354
countryEmissionInfo,
5455
countryAssetEmissions,
5556
isLoadingCountryDetails

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/ui/CountryInfoDetailedView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import dev.johnoreilly.climatetrace.remote.CountryEmissionsInfo
2424
@Composable
2525
fun CountryInfoDetailedView(
2626
country: Country?,
27+
year: String,
2728
countryEmissionInfo: CountryEmissionsInfo?,
2829
countryAssetEmissionsList: List<CountryAssetEmissionsInfo>?,
2930
isLoading: Boolean
@@ -77,7 +78,7 @@ fun CountryInfoDetailedView(
7778
val co2 = (countryEmissionInfo.emissions.co2 / 1_000_000).toInt()
7879
val percentage = (countryEmissionInfo.emissions.co2 / countryEmissionInfo.worldEmissions.co2).toPercent(2)
7980

80-
Text(text = "co2 = $co2 Million Tonnes (2022)")
81+
Text(text = "co2 = $co2 Million Tonnes ($year)")
8182
Text(text = "rank = ${countryEmissionInfo.rank} ($percentage)")
8283

8384
Spacer(modifier = Modifier.size(16.dp))

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import org.koin.core.component.inject
1616
open class ClimateTraceViewModel : KMMViewModel(), KoinComponent {
1717
private val climateTraceApi: ClimateTraceApi by inject()
1818

19+
var year: String = "2022"
20+
1921
private val _countryList = MutableStateFlow<List<Country>>(viewModelScope, emptyList())
2022
@NativeCoroutinesState
2123
val countryList = _countryList.asStateFlow()
@@ -44,7 +46,7 @@ open class ClimateTraceViewModel : KMMViewModel(), KoinComponent {
4446
selectedCountry.value = country
4547
isLoadingCountryDetails.value = true
4648
viewModelScope.coroutineScope.launch {
47-
countryEmissionInfo.value = climateTraceApi.fetchCountryEmissionsInfo(country.alpha3).firstOrNull()
49+
countryEmissionInfo.value = climateTraceApi.fetchCountryEmissionsInfo(country.alpha3, year).firstOrNull()
4850
countryAssetEmissions.value = climateTraceApi.fetchCountryAssetEmissionsInfo(country.alpha3)
4951
isLoadingCountryDetails.value = false
5052
}

composeApp/src/iosMain/kotlin/MainViewController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fun CountryListViewController(onCountryClicked: (country: Country) -> Unit) = Co
2323
}
2424

2525

26-
fun CountryInfoDetailedViewController(country: Country) = ComposeUIViewController {
26+
fun CountryInfoDetailedViewController(country: Country, year: String) = ComposeUIViewController {
2727
val viewModel = koinInject<ClimateTraceViewModel>()
2828
val countryEmissionInfo by viewModel.countryEmissionInfo.collectAsState()
2929
val countryAssetEmissions by viewModel.countryAssetEmissions.collectAsState()
@@ -33,5 +33,5 @@ fun CountryInfoDetailedViewController(country: Country) = ComposeUIViewControlle
3333
viewModel.fetchCountryDetails(country)
3434
}
3535

36-
CountryInfoDetailedView(country, countryEmissionInfo, countryAssetEmissions, isLoadingCountryDetails)
36+
CountryInfoDetailedView(country, year, countryEmissionInfo, countryAssetEmissions, isLoadingCountryDetails)
3737
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)