@@ -3,35 +3,47 @@ package com.flipcash.app.pools.internal.list
33import androidx.compose.foundation.Image
44import androidx.compose.foundation.background
55import androidx.compose.foundation.layout.Box
6+ import androidx.compose.foundation.layout.BoxScope
67import androidx.compose.foundation.layout.Column
78import androidx.compose.foundation.layout.Spacer
89import androidx.compose.foundation.layout.WindowInsets
910import androidx.compose.foundation.layout.fillMaxSize
1011import androidx.compose.foundation.layout.fillMaxWidth
1112import androidx.compose.foundation.layout.navigationBars
13+ import androidx.compose.foundation.layout.navigationBarsPadding
1214import androidx.compose.foundation.layout.padding
1315import androidx.compose.foundation.layout.windowInsetsPadding
16+ import androidx.compose.foundation.lazy.LazyColumn
1417import androidx.compose.material.Text
1518import androidx.compose.runtime.Composable
1619import androidx.compose.runtime.LaunchedEffect
17- import androidx.lifecycle.compose.collectAsStateWithLifecycle
1820import androidx.compose.runtime.getValue
1921import androidx.compose.ui.Alignment
2022import androidx.compose.ui.Modifier
2123import androidx.compose.ui.res.painterResource
2224import androidx.compose.ui.res.stringResource
2325import androidx.compose.ui.text.style.TextAlign
2426import androidx.compose.ui.tooling.preview.Preview
27+ import androidx.lifecycle.compose.collectAsStateWithLifecycle
28+ import androidx.paging.LoadState
29+ import androidx.paging.PagingData
30+ import androidx.paging.compose.LazyPagingItems
31+ import androidx.paging.compose.collectAsLazyPagingItems
2532import cafe.adriel.voyager.core.registry.ScreenRegistry
2633import com.flipcash.app.core.NavScreenProvider
34+ import com.flipcash.app.core.pools.Pool
35+ import com.flipcash.app.pools.internal.list.components.PoolSummaryRow
2736import com.flipcash.app.theme.FlipcashDesignSystem
2837import com.flipcash.features.pools.R
2938import com.getcode.navigation.core.LocalCodeNavigator
3039import com.getcode.theme.CodeTheme
3140import com.getcode.ui.theme.ButtonState
3241import com.getcode.ui.theme.CodeButton
42+ import com.getcode.ui.theme.CodeScaffold
3343import kotlinx.coroutines.flow.filterIsInstance
44+ import kotlinx.coroutines.flow.flowOf
3445import kotlinx.coroutines.flow.launchIn
46+ import kotlinx.coroutines.flow.map
3547import kotlinx.coroutines.flow.onEach
3648
3749@Composable
@@ -40,14 +52,20 @@ internal fun PoolListScreen(
4052) {
4153 val navigator = LocalCodeNavigator .current
4254 val state by viewModel.stateFlow.collectAsStateWithLifecycle()
55+ val pools = viewModel.pools.collectAsLazyPagingItems()
4356
44- PoolListScreenContent (state, viewModel::dispatchEvent)
57+ PoolListScreenContent (state, pools, viewModel::dispatchEvent)
4558
4659 LaunchedEffect (viewModel) {
4760 viewModel.eventFlow
4861 .filterIsInstance<PoolListViewModel .Event .OnPoolClicked >()
62+ .map { it.pool }
4963 .onEach {
50-
64+ navigator.push(
65+ ScreenRegistry .get(
66+ NavScreenProvider .HomeScreen .Pools .ChoiceSelection (it.id)
67+ )
68+ )
5169 }.launchIn(this )
5270 }
5371
@@ -63,11 +81,55 @@ internal fun PoolListScreen(
6381@Composable
6482private fun PoolListScreenContent (
6583 state : PoolListViewModel .State ,
84+ pools : LazyPagingItems <Pool >,
85+ dispatch : (PoolListViewModel .Event ) -> Unit
86+ ) {
87+ if (pools.itemCount == 0 && pools.loadState.append is LoadState .NotLoading ) {
88+ Box (
89+ modifier = Modifier .fillMaxSize(),
90+ contentAlignment = Alignment .Center
91+ ) {
92+ EmptyState (dispatch)
93+ }
94+ } else {
95+ CodeScaffold (
96+ bottomBar = {
97+ CodeButton (
98+ onClick = { dispatch(PoolListViewModel .Event .OnCreatePool ) },
99+ text = stringResource(R .string.action_createNewPool),
100+ buttonState = ButtonState .Filled ,
101+ modifier = Modifier
102+ .fillMaxWidth()
103+ .navigationBarsPadding()
104+ .padding(horizontal = CodeTheme .dimens.inset)
105+ .padding(
106+ top = CodeTheme .dimens.grid.x2,
107+ bottom = CodeTheme .dimens.grid.x2
108+ ),
109+ )
110+ }
111+ ) { innerPadding ->
112+ LazyColumn (modifier = Modifier .padding(innerPadding)) {
113+ items(pools.itemCount) { index ->
114+ pools[index]?.let {
115+ PoolSummaryRow (
116+ pool = it,
117+ onClick = { dispatch(PoolListViewModel .Event .OnPoolClicked (it)) }
118+ )
119+ }
120+ }
121+ }
122+ }
123+ }
124+ }
125+
126+ @Composable
127+ private fun BoxScope.EmptyState (
66128 dispatch : (PoolListViewModel .Event ) -> Unit
67129) {
68130 Box (
69131 modifier = Modifier
70- .fillMaxSize ()
132+ .matchParentSize ()
71133 .windowInsetsPadding(WindowInsets .navigationBars),
72134 ) {
73135 Column (
@@ -93,7 +155,7 @@ private fun PoolListScreenContent(
93155 )
94156 Spacer (Modifier .weight(1f ))
95157 CodeButton (
96- onClick = { dispatch(PoolListViewModel .Event .OnCreatePool ) },
158+ onClick = { dispatch(PoolListViewModel .Event .OnCreatePool ) },
97159 text = stringResource(R .string.action_createNewPool),
98160 buttonState = ButtonState .Filled ,
99161 modifier = Modifier
@@ -112,6 +174,7 @@ private fun Preview_EmptyState() {
112174 Box (modifier = Modifier .background(CodeTheme .colors.background)) {
113175 PoolListScreenContent (
114176 state = PoolListViewModel .State (),
177+ pools = flowOf(PagingData .empty<Pool >()).collectAsLazyPagingItems(),
115178 dispatch = {}
116179 )
117180 }
0 commit comments