Skip to content

Commit b0ba5c5

Browse files
committed
fix minor warnings in demo app
1 parent e2f3397 commit b0ba5c5

1 file changed

Lines changed: 69 additions & 65 deletions

File tree

  • demo-common/src/commonMain/kotlin/com/seanproctor/datatable/demo

demo-common/src/commonMain/kotlin/com/seanproctor/datatable/demo/App.kt

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,54 @@ fun App(onRowClick: (Int) -> Unit) {
9292
val colorEven = MaterialTheme.colorScheme.surfaceBright
9393
val colorOdd = MaterialTheme.colorScheme.surfaceDim
9494
val scrollState = remember(selectedIndex) { DataTableState() }
95-
if (selectedIndex == 0) {
96-
Box {
97-
DataTable(
95+
when (selectedIndex) {
96+
0 -> {
97+
Box {
98+
DataTable(
99+
columns = columns,
100+
state = scrollState,
101+
sortColumnIndex = sortColumnIndex,
102+
sortAscending = sortAscending,
103+
modifier = Modifier.fillMaxWidth().padding(16.dp),
104+
footer = {
105+
Box {
106+
Text(
107+
modifier = Modifier.align(Alignment.CenterEnd),
108+
text = "Footer",
109+
maxLines = 1,
110+
overflow = TextOverflow.Ellipsis,
111+
style = MaterialTheme.typography.titleLarge
112+
)
113+
}
114+
}
115+
) {
116+
generateTable(
117+
colorEven = colorEven,
118+
colorOdd = colorOdd,
119+
data = sortedData,
120+
onRowClick = onRowClick,
121+
)
122+
}
123+
VerticalScrollbar(
124+
adapter = rememberScrollbarAdapter(scrollState.verticalScrollState),
125+
style = defaultMaterialScrollbarStyle(),
126+
modifier = Modifier.fillMaxHeight().align(Alignment.CenterEnd),
127+
)
128+
HorizontalScrollbar(
129+
adapter = rememberScrollbarAdapter(scrollState.horizontalScrollState),
130+
style = defaultMaterialScrollbarStyle(),
131+
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter)
132+
)
133+
}
134+
}
135+
1 -> {
136+
PaginatedDataTable(
98137
columns = columns,
99-
state = scrollState,
138+
state = rememberPaginatedDataTableState(5),
100139
sortColumnIndex = sortColumnIndex,
101140
sortAscending = sortAscending,
102141
modifier = Modifier.fillMaxWidth().padding(16.dp),
103-
footer = {
104-
Box {
105-
Text(
106-
modifier = Modifier.align(Alignment.CenterEnd),
107-
text = "Footer",
108-
maxLines = 1,
109-
overflow = TextOverflow.Ellipsis,
110-
style = MaterialTheme.typography.titleLarge
111-
)
112-
}
113-
}
142+
logger = { println(it) }
114143
) {
115144
generateTable(
116145
colorEven = colorEven,
@@ -119,65 +148,40 @@ fun App(onRowClick: (Int) -> Unit) {
119148
onRowClick = onRowClick,
120149
)
121150
}
122-
VerticalScrollbar(
123-
adapter = rememberScrollbarAdapter(scrollState.verticalScrollState),
124-
style = defaultMaterialScrollbarStyle(),
125-
modifier = Modifier.fillMaxHeight().align(Alignment.CenterEnd),
126-
)
127-
HorizontalScrollbar(
128-
adapter = rememberScrollbarAdapter(scrollState.horizontalScrollState),
129-
style = defaultMaterialScrollbarStyle(),
130-
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter)
131-
)
132151
}
133-
} else if (selectedIndex == 1) {
134-
PaginatedDataTable(
135-
columns = columns,
136-
state = rememberPaginatedDataTableState(5),
137-
sortColumnIndex = sortColumnIndex,
138-
sortAscending = sortAscending,
139-
modifier = Modifier.fillMaxWidth().padding(16.dp),
140-
logger = { println(it) }
141-
) {
142-
generateTable(
143-
colorEven = colorEven,
144-
colorOdd = colorOdd,
145-
data = sortedData,
146-
onRowClick = onRowClick,
147-
)
148-
}
149-
} else {
150-
LazyPaginatedDataTable(
151-
columns = columns,
152-
state = rememberPaginatedDataTableState(initialPageSize = 5, initialCount = sortedData.size),
153-
sortColumnIndex = sortColumnIndex,
154-
sortAscending = sortAscending,
155-
modifier = Modifier.fillMaxWidth().padding(16.dp),
156-
logger = { println(it) },
157-
fetchPage = { state ->
158-
val fromIndex = state.pageIndex * state.pageSize
159-
val toIndex = min(fromIndex + state.pageSize, sortedData.size)
160-
val subset = sortedData.subList(fromIndex, toIndex)
161-
subset.forEachIndexed { index, rowData ->
162-
row {
163-
onClick = { onRowClick(fromIndex + index) }
164-
cell { }
165-
cell {
166-
Text(rowData.text, maxLines = 1, overflow = TextOverflow.Ellipsis)
167-
}
168-
cell {
169-
Text(rowData.value.toString())
152+
else -> {
153+
LazyPaginatedDataTable(
154+
columns = columns,
155+
state = rememberPaginatedDataTableState(initialPageSize = 5, initialCount = sortedData.size),
156+
sortColumnIndex = sortColumnIndex,
157+
sortAscending = sortAscending,
158+
modifier = Modifier.fillMaxWidth().padding(16.dp),
159+
logger = { println(it) },
160+
fetchPage = { state ->
161+
val fromIndex = state.pageIndex * state.pageSize
162+
val toIndex = min(fromIndex + state.pageSize, sortedData.size)
163+
val subset = sortedData.subList(fromIndex, toIndex)
164+
subset.forEachIndexed { index, rowData ->
165+
row {
166+
onClick = { onRowClick(fromIndex + index) }
167+
cell { }
168+
cell {
169+
Text(rowData.text, maxLines = 1, overflow = TextOverflow.Ellipsis)
170+
}
171+
cell {
172+
Text(rowData.value.toString())
173+
}
170174
}
171175
}
172176
}
173-
}
174-
)
177+
)
178+
}
175179
}
176180
}
177181
}
178182
}
179183

180-
fun DataTableScope.generateTable(
184+
private fun DataTableScope.generateTable(
181185
colorEven: Color,
182186
colorOdd: Color,
183187
data: List<DemoData>,

0 commit comments

Comments
 (0)