Skip to content

Commit 5b61b4d

Browse files
committed
Created TopicScreen for displaying list of topics
1 parent 60f8280 commit 5b61b4d

File tree

1 file changed

+58
-0
lines changed
  • composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic
2+
3+
import androidx.compose.foundation.clickable
4+
import androidx.compose.foundation.layout.fillMaxSize
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.lazy.LazyColumn
8+
import androidx.compose.foundation.lazy.items
9+
import androidx.compose.material.Card
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
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.unit.dp
17+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
18+
19+
@Composable
20+
fun TopicScreen(
21+
onTopicClick: (String) -> Unit,
22+
viewModel: TopicViewModel
23+
) {
24+
val topics by viewModel.topics.collectAsState()
25+
26+
LazyColumn(
27+
modifier = Modifier
28+
.fillMaxSize()
29+
.padding(16.dp)
30+
) {
31+
items(topics) { topic ->
32+
TopicItem(topic = topic, onClick = {
33+
println("Topic clicked: ${topic.name}")
34+
onTopicClick(topic.name)
35+
})
36+
}
37+
}
38+
}
39+
40+
41+
@Composable
42+
fun TopicItem(topic: Topic, onClick: () -> Unit) {
43+
println("Rendering topic item: ${topic.name}")
44+
45+
Card(
46+
elevation = 4.dp,
47+
modifier = Modifier
48+
.fillMaxWidth()
49+
.padding(vertical = 8.dp)
50+
.clickable { onClick() }
51+
) {
52+
Text(
53+
text = topic.name,
54+
style = MaterialTheme.typography.h6,
55+
modifier = Modifier.padding(16.dp)
56+
)
57+
}
58+
}

0 commit comments

Comments
 (0)