@@ -13,27 +13,28 @@ import androidx.compose.runtime.Composable
1313import androidx.compose.ui.Modifier
1414import androidx.compose.ui.text.style.TextAlign
1515import androidx.compose.ui.unit.dp
16+ import com.powersync.bucket.BucketPriority
1617import com.powersync.demos.Screen
1718import com.powersync.demos.components.Input
1819import com.powersync.demos.components.ListContent
1920import com.powersync.demos.components.Menu
2021import com.powersync.demos.components.WifiIcon
2122import com.powersync.demos.powersync.ListItem
23+ import com.powersync.sync.SyncStatusData
2224
2325@OptIn(ExperimentalMaterial3Api ::class )
2426@Composable
2527internal fun HomeScreen (
2628 modifier : Modifier = Modifier ,
2729 items : List <ListItem >,
2830 inputText : String ,
29- isConnected : Boolean? ,
31+ status : SyncStatusData ,
3032 onSignOutSelected : () -> Unit ,
3133 onItemClicked : (item: ListItem ) -> Unit ,
3234 onItemDeleteClicked : (item: ListItem ) -> Unit ,
3335 onAddItemClicked : () -> Unit ,
3436 onInputTextChanged : (value: String ) -> Unit ,
3537) {
36-
3738 Column (modifier) {
3839 TopAppBar (
3940 title = {
@@ -47,7 +48,7 @@ internal fun HomeScreen(
4748 onSignOutSelected
4849 ) },
4950 actions = {
50- WifiIcon (isConnected ? : false )
51+ WifiIcon (status.connected )
5152 Spacer (modifier = Modifier .width(16 .dp))
5253 }
5354 )
@@ -60,11 +61,20 @@ internal fun HomeScreen(
6061 )
6162
6263 Box (Modifier .weight(1F )) {
63- ListContent (
64- items = items,
65- onItemClicked = onItemClicked,
66- onItemDeleteClicked = onItemDeleteClicked
67- )
64+ // This assumes that the bucket for lists has a priority of 1 (but it will work fine
65+ // with sync rules not defining any priorities at all too).
66+ // When giving lists a higher priority than items, we can have a consistent snapshot of
67+ // lists without items. In the case where many items exist (that might take longer to
68+ // sync initially), this allows us to display lists earlier.
69+ if (status.priorityStatusFor(BucketPriority (1 )).hasSynced == true ) {
70+ ListContent (
71+ items = items,
72+ onItemClicked = onItemClicked,
73+ onItemDeleteClicked = onItemDeleteClicked
74+ )
75+ } else {
76+ Text (" Busy with sync..." )
77+ }
6878 }
6979 }
7080}
0 commit comments