@@ -13,27 +13,28 @@ import androidx.compose.runtime.Composable
13
13
import androidx.compose.ui.Modifier
14
14
import androidx.compose.ui.text.style.TextAlign
15
15
import androidx.compose.ui.unit.dp
16
+ import com.powersync.bucket.BucketPriority
16
17
import com.powersync.demos.Screen
17
18
import com.powersync.demos.components.Input
18
19
import com.powersync.demos.components.ListContent
19
20
import com.powersync.demos.components.Menu
20
21
import com.powersync.demos.components.WifiIcon
21
22
import com.powersync.demos.powersync.ListItem
23
+ import com.powersync.sync.SyncStatusData
22
24
23
25
@OptIn(ExperimentalMaterial3Api ::class )
24
26
@Composable
25
27
internal fun HomeScreen (
26
28
modifier : Modifier = Modifier ,
27
29
items : List <ListItem >,
28
30
inputText : String ,
29
- isConnected : Boolean? ,
31
+ status : SyncStatusData ,
30
32
onSignOutSelected : () -> Unit ,
31
33
onItemClicked : (item: ListItem ) -> Unit ,
32
34
onItemDeleteClicked : (item: ListItem ) -> Unit ,
33
35
onAddItemClicked : () -> Unit ,
34
36
onInputTextChanged : (value: String ) -> Unit ,
35
37
) {
36
-
37
38
Column (modifier) {
38
39
TopAppBar (
39
40
title = {
@@ -47,7 +48,7 @@ internal fun HomeScreen(
47
48
onSignOutSelected
48
49
) },
49
50
actions = {
50
- WifiIcon (isConnected ? : false )
51
+ WifiIcon (status.connected )
51
52
Spacer (modifier = Modifier .width(16 .dp))
52
53
}
53
54
)
@@ -60,11 +61,20 @@ internal fun HomeScreen(
60
61
)
61
62
62
63
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
+ }
68
78
}
69
79
}
70
80
}
0 commit comments