diff --git a/composeApp/build/generated/compose/resourceGenerator/kotlin/HomeScreen.kt b/composeApp/build/generated/compose/resourceGenerator/kotlin/HomeScreen.kt index 96ac150..30ab945 100644 --- a/composeApp/build/generated/compose/resourceGenerator/kotlin/HomeScreen.kt +++ b/composeApp/build/generated/compose/resourceGenerator/kotlin/HomeScreen.kt @@ -90,7 +90,8 @@ class HomeScreen: Screen { println(names) println(newMap) if (newMap.isNotEmpty()) { - pokemap = newMap + println("Updating map") + pokemap = newMap; } } } diff --git a/composeApp/src/commonMain/kotlin/App.kt b/composeApp/src/commonMain/kotlin/App.kt index e925210..abb0f6e 100644 --- a/composeApp/src/commonMain/kotlin/App.kt +++ b/composeApp/src/commonMain/kotlin/App.kt @@ -35,7 +35,7 @@ import pokedex.composeapp.generated.resources.water import java.net.URL import java.util.Locale -var pokemap = ArrayList() +var pokemap by mutableStateOf>(arrayListOf()) val apiString = "https://pokeapi.co/api/v2/pokemon/" @OptIn(ExperimentalResourceApi::class) @@ -112,12 +112,14 @@ suspend fun loadPokemonData(startId: Int, endId: Int): List { } suspend fun loadPokemonDataFromName(name: String): Pokemon? { - println("fetching api, name: ${name}") - if (name.equals("")) return null - var json: JSONObject = JSONObject("{}") + val trimmedName = name.trim() + println("fetching api, name: $name") + if (trimmedName == "") return null + var json: JSONObject try { - json = JSONObject(URL(apiString + name).readText()); + json = JSONObject(URL(apiString + trimmedName).readText()); } catch (e: Exception) { + println(e) return null } val sprites = json.optJSONObject("sprites") @@ -135,8 +137,4 @@ suspend fun loadPokemonDataFromName(name: String): Pokemon? { pokemap.add(pokemon) return pokemon -} - -fun getPokeMap(): ArrayList { - return pokemap } \ No newline at end of file