Skip to content

Commit 930ffe8

Browse files
committed
Refactor: Code cleanup and formatting
1 parent 0f3c0b6 commit 930ffe8

File tree

14 files changed

+52
-40
lines changed

14 files changed

+52
-40
lines changed

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.developersbreach.kotlindictionarymultiplatform
22

33
import androidx.compose.material.MaterialTheme
4-
import androidx.compose.runtime.*
4+
import androidx.compose.runtime.Composable
55
import com.developersbreach.kotlindictionarymultiplatform.ui.navigation.AppNavigation
66

77
@Composable
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package com.developersbreach.kotlindictionarymultiplatform.core
22

3-
const val API_KEY =""
3+
const val API_KEY = ""

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/KtorHttpClient.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import kotlinx.serialization.json.Json
2020
import kotlinx.serialization.json.decodeFromJsonElement
2121
import kotlinx.serialization.json.jsonObject
2222

23-
2423
object KtorHttpClient {
2524
private val json = Json { ignoreUnknownKeys = true }
2625

@@ -76,33 +75,36 @@ object KtorHttpClient {
7675
},
7776
"required": ["topicId","topicName","intro","syntax","sections"]
7877
}
79-
""".trimIndent()
78+
""".trimIndent(),
8079
)
8180

8281
private val functionDef = FunctionDefinition(
8382
name = "generate_kotlin_topic_details",
8483
description = "Return a fully-featured Kotlin documentation object for a given topic",
85-
parameters = functionSchema
84+
parameters = functionSchema,
8685
)
8786

8887
/**
8988
* Calls the OpenAI ChatCompletion with function-calling to get topic details.
9089
* @param topicId the topic identifier, e.g. "variables".
9190
* @param apiKey your OpenAI API key.
9291
*/
93-
suspend fun generateTopicDetails(topicId: String, apiKey: String): KotlinTopicDetails {
92+
suspend fun generateTopicDetails(
93+
topicId: String,
94+
apiKey: String,
95+
): KotlinTopicDetails {
9496
// Prepare messages
9597
val messages = listOf(
9698
ChatMessage("system", "You are a Kotlin documentation generator."),
97-
ChatMessage("user", "Generate full Kotlin documentation for topic \"$topicId\".")
99+
ChatMessage("user", "Generate full Kotlin documentation for topic \"$topicId\"."),
98100
)
99101

100102
// Build request body
101103
val request = ChatCompletionRequest(
102104
model = "gpt-4o-mini",
103105
messages = messages,
104106
functions = listOf(functionDef),
105-
functionCall = mapOf("name" to functionDef.name)
107+
functionCall = mapOf("name" to functionDef.name),
106108
)
107109

108110
// Execute HTTP request

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/KotlinTopicDetails.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,65 @@ data class KotlinTopicDetails(
1313
val sections: List<Section>,
1414
val pitfalls: List<String> = emptyList(),
1515
val relatedTopics: List<String> = emptyList(),
16-
val metadata: Map<String, JsonElement> = emptyMap()
16+
val metadata: Map<String, JsonElement> = emptyMap(),
1717
)
1818

1919
@Serializable
2020
data class Syntax(
2121
val signature: String,
22-
val notes: String? = null
22+
val notes: String? = null,
2323
)
2424

2525
@Serializable
2626
data class Section(
2727
val heading: String? = null,
2828
val content: String? = null,
29-
val codeExamples: List<CodeExample> = emptyList()
29+
val codeExamples: List<CodeExample> = emptyList(),
3030
)
3131

3232
@Serializable
3333
data class CodeExample(
3434
val description: String? = null,
3535
val code: String,
36-
val language: String = "kotlin"
36+
val language: String = "kotlin",
3737
)
3838

3939
// --- Request/Response schema for OpenAI Chat Completion ---
4040
@Serializable
4141
data class ChatMessage(
4242
val role: String,
43-
val content: String
43+
val content: String,
4444
)
4545

4646
@Serializable
4747
data class FunctionDefinition(
4848
val name: String,
4949
val description: String,
50-
val parameters: JsonElement
50+
val parameters: JsonElement,
5151
)
5252

5353
@Serializable
5454
data class FunctionCall(
5555
val name: String,
56-
val arguments: String
56+
val arguments: String,
5757
)
5858

5959
@Serializable
6060
data class ChatCompletionChoice(
61-
val message: ChatCompletionResponseMessage
61+
val message: ChatCompletionResponseMessage,
6262
)
6363

6464
@Serializable
6565
data class ChatCompletionResponseMessage(
6666
val role: String,
6767
val content: String? = null,
6868
@SerialName("function_call")
69-
val functionCall: FunctionCall? = null
69+
val functionCall: FunctionCall? = null,
7070
)
7171

7272
@Serializable
7373
data class ChatCompletionResponse(
74-
val choices: List<ChatCompletionChoice>?
74+
val choices: List<ChatCompletionChoice>?,
7575
)
7676

7777
@Serializable
@@ -80,5 +80,5 @@ data class ChatCompletionRequest(
8080
val messages: List<ChatMessage>,
8181
val functions: List<FunctionDefinition>,
8282
@SerialName("function_call")
83-
val functionCall: Map<String, String>
83+
val functionCall: Map<String, String>,
8484
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.developersbreach.kotlindictionarymultiplatform.data.topic.model
22

33
data class Topic(
4-
val name: String
4+
val name: String,
55
)

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/repository/TopicRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ object TopicRepository {
1818
Topic("Delegation"),
1919
Topic("Sealed Classes"),
2020
Topic("Generics"),
21-
Topic("Annotations")
21+
Topic("Annotations"),
2222
)
2323
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fun AppNavigation(
1616
startDestination: AppDestinations = AppDestinations.TopicList,
1717
) {
1818
val navController = rememberNavController()
19-
val actions = remember(navController) { NavigationActions(navController) }
19+
val actions = remember(navController) { NavigationAction(navController) }
2020

2121
NavHost(
2222
navController = navController,
@@ -28,7 +28,7 @@ fun AppNavigation(
2828
onTopicClick = { selectedTopicId ->
2929
actions.navigateToDetail(selectedTopicId)
3030
},
31-
viewModel = viewModel
31+
viewModel = viewModel,
3232
)
3333
}
3434

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.navigation
22

33
import androidx.navigation.NavHostController
44

5-
class NavigationActions(private val navController: NavHostController) {
5+
class NavigationAction(private val navController: NavHostController) {
66

77
val navigateToDetail: (String) -> Unit = { topicId ->
88
navController.navigate(AppDestinations.Detail(topicId))

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailScreen.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
package com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail
22

3-
import androidx.compose.runtime.*
4-
import androidx.compose.material.*
5-
import androidx.compose.foundation.layout.*
6-
import androidx.compose.foundation.lazy.*
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.foundation.layout.Spacer
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.layout.height
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.lazy.LazyColumn
9+
import androidx.compose.material.CircularProgressIndicator
10+
import androidx.compose.material.MaterialTheme
11+
import androidx.compose.material.Text
12+
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.collectAsState
14+
import androidx.compose.runtime.getValue
715
import androidx.compose.ui.Alignment
816
import androidx.compose.ui.Modifier
917
import androidx.compose.ui.unit.dp
18+
import androidx.compose.foundation.lazy.items
1019

1120
@Composable
1221
fun DetailScreen(viewModel: DetailViewModel) {
1322
val topicState by viewModel.state.collectAsState()
1423
println("check topicState: $topicState")
1524

16-
1725
topicState?.let { topic ->
1826
println("Topic data fetched: $topic")
1927
LazyColumn(modifier = Modifier.padding(16.dp)) {

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.developersbreach.kotlindictionarymultiplatform.core.API_KEY
1313
import com.developersbreach.kotlindictionarymultiplatform.ui.navigation.AppDestinations
1414

1515
class DetailViewModel(
16-
savedStateHandle: SavedStateHandle
16+
savedStateHandle: SavedStateHandle,
1717
) : ViewModel() {
1818

1919
private val topicId = savedStateHandle.toRoute<AppDestinations.Detail>().topicId

0 commit comments

Comments
 (0)