Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class SyncIntegrationTest {
),
)

turbine.waitFor { it.priorityStatusFor(priority).hasSynced == true }
turbine.waitFor { it.statusForPriority(priority).hasSynced == true }
expectUserCount(priorityNo + 1)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ class SyncIntegrationTest {
// Connect to the same database again
database = openDb()
assertFalse { database.currentStatus.hasSynced == true }
assertTrue { database.currentStatus.priorityStatusFor(BucketPriority(1)).hasSynced == true }
assertTrue { database.currentStatus.statusForPriority(BucketPriority(1)).hasSynced == true }
database.close()
syncLines.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ internal class PowerSyncDatabaseImpl(
if (priority == null) {
{ it.hasSynced == true }
} else {
{ it.priorityStatusFor(priority).hasSynced == true }
{ it.statusForPriority(priority).hasSynced == true }
}

if (predicate(currentStatus)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public interface SyncStatusData {
/**
* Status information for whether buckets in [priority] have been synchronized.
*/
public fun priorityStatusFor(priority: BucketPriority): PriorityStatusEntry {
public fun statusForPriority(priority: BucketPriority): PriorityStatusEntry {
val byDescendingPriorities = priorityStatusEntries.sortedByDescending { it.priority }

for (entry in byDescendingPriorities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class SyncStreamTest {
),
)

turbine.waitFor { it.priorityStatusFor(priority).hasSynced == true }
turbine.waitFor { it.statusForPriority(priority).hasSynced == true }

verifySuspend(order) {
if (priorityNo == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun App() {
}
val db = remember { PowerSyncDatabase(driverFactory, schema) }
val syncStatus = db.currentStatus
val status = syncStatus.asFlow().collectAsState(initial = null)
val status by syncStatus.asFlow().collectAsState(syncStatus)

val navController = remember { NavController(Screen.Home) }
val authViewModel = remember {
Expand Down Expand Up @@ -87,7 +87,7 @@ fun App() {
HomeScreen(
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background),
items = items,
isConnected = status.value?.connected,
status = status,
onSignOutSelected = { handleSignOut() },
inputText = listsInputText,
onItemClicked = handleOnItemClicked,
Expand All @@ -106,7 +106,7 @@ fun App() {
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background),
navController = navController,
items = todoItems,
isConnected = status.value?.connected,
isConnected = status.connected,
inputText = todosInputText,
onItemClicked = todos.value::onItemClicked,
onItemDoneChanged = todos.value::onItemDoneChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.powersync.bucket.BucketPriority
import com.powersync.demos.Screen
import com.powersync.demos.components.Input
import com.powersync.demos.components.ListContent
import com.powersync.demos.components.Menu
import com.powersync.demos.components.WifiIcon
import com.powersync.demos.powersync.ListItem
import com.powersync.sync.SyncStatusData

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun HomeScreen(
modifier: Modifier = Modifier,
items: List<ListItem>,
inputText: String,
isConnected: Boolean?,
status: SyncStatusData,
onSignOutSelected: () -> Unit,
onItemClicked: (item: ListItem) -> Unit,
onItemDeleteClicked: (item: ListItem) -> Unit,
onAddItemClicked: () -> Unit,
onInputTextChanged: (value: String) -> Unit,
) {

Column(modifier) {
TopAppBar(
title = {
Expand All @@ -47,7 +48,7 @@ internal fun HomeScreen(
onSignOutSelected
) },
actions = {
WifiIcon(isConnected ?: false)
WifiIcon(status.connected)
Spacer(modifier = Modifier.width(16.dp))
}
)
Expand All @@ -60,11 +61,20 @@ internal fun HomeScreen(
)

Box(Modifier.weight(1F)) {
ListContent(
items = items,
onItemClicked = onItemClicked,
onItemDeleteClicked = onItemDeleteClicked
)
// This assumes that the bucket for lists has a priority of 1 (but it will work fine
// with sync rules not defining any priorities at all too).
// When giving lists a higher priority than items, we can have a consistent snapshot of
// lists without items. In the case where many items exist (that might take longer to
// sync initially), this allows us to display lists earlier.
if (status.statusForPriority(BucketPriority(1)).hasSynced == true) {
ListContent(
items = items,
onItemClicked = onItemClicked,
onItemDeleteClicked = onItemDeleteClicked
)
} else {
Text("Busy with sync...")
}
}
}
}
2 changes: 1 addition & 1 deletion demos/supabase-todolist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
It is a simple to-do list application demonstrating use of the PowerSync Kotlin Mutiplatform SDK together
with [Supabase](https://supabase.com/) in a basic Kotlin Multiplatform Compose App.

Supported KMP targets: Android and iOS.
Supported KMP targets: Android, iOS and Desktop (JVM).

## Setting up your development environment

Expand Down
2 changes: 1 addition & 1 deletion demos/supabase-todolist/desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kotlin {
sourceSets {
jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(project(":shared"))
implementation(projects.shared)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions demos/supabase-todolist/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ junit = "4.13.2"

compose = "1.6.11"
compose-preview = "1.7.2"
lifecycle = "2.8.2"

# plugins
android-gradle-plugin = "8.5.1"
Expand Down Expand Up @@ -49,13 +50,15 @@ ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "kto
ktor-client-contentnegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }

androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" }
androidx-material = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose-preview" }
compose-lifecycle = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "android-gradle-plugin" }
Expand Down
18 changes: 0 additions & 18 deletions demos/supabase-todolist/iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
7555FF79242A565900829871 /* Resources */,
F85CB1118929364A9C6EFABC /* Frameworks */,
3C5ACF3A4AAFF294B2A5839B /* [CP] Embed Pods Frameworks */,
79E17356D7D971831C2A4119 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -231,23 +230,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
79E17356D7D971831C2A4119 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
2 changes: 1 addition & 1 deletion demos/supabase-todolist/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rootProject.name = "supabase-todolist"

include(":androidApp")
include(":shared")
//include(":desktopApp")
include(":desktopApp")

includeBuild("../..") {
dependencySubstitution {
Expand Down
10 changes: 6 additions & 4 deletions demos/supabase-todolist/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = "1.0-SNAPSHOT"
kotlin {
androidTarget()

// jvm()
jvm()
iosX64()
iosArm64()
iosSimulatorArm64()
Expand Down Expand Up @@ -48,16 +48,18 @@ kotlin {
implementation(compose.material)
implementation(compose.components.resources)
implementation(compose.materialIconsExtended)
implementation(libs.compose.lifecycle)
}
androidMain.dependencies {
api(libs.androidx.activity.compose)
api(libs.androidx.appcompat)
api(libs.androidx.core)
}

// jvmMain.dependencies {
// implementation(compose.desktop.common)
// }
jvmMain.dependencies {
implementation(compose.desktop.common)
implementation(libs.kotlinx.coroutines.swing)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import com.powersync.DatabaseDriverFactory
import com.powersync.PowerSyncDatabase
import com.powersync.bucket.BucketPriority
import com.powersync.connector.supabase.SupabaseConnector
import com.powersync.demos.components.EditDialog
import com.powersync.demos.powersync.ListContent
Expand All @@ -36,9 +37,15 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
)
}
val db = remember { PowerSyncDatabase(factory, schema) }
val status = db.currentStatus.asFlow().collectAsState(initial = null)
val hasSynced by remember { derivedStateOf { status.value?.hasSynced } }

val status by db.currentStatus.asFlow().collectAsState(initial = db.currentStatus)

// This assumes that the buckets for lists has a priority of 1 (but it will work fine with sync
// rules not defining any priorities at all too). When giving lists a higher priority than
// items, we can have a consistent snapshot of lists without items. In the case where many items
// exist (that might take longer to sync initially), this allows us to display lists earlier.
val hasSyncedLists by remember {
derivedStateOf { status.statusForPriority(BucketPriority(1)).hasSynced }
}

val navController = remember { NavController(Screen.Home) }
val authViewModel = remember {
Expand Down Expand Up @@ -86,14 +93,14 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
HomeScreen(
modifier = modifier.background(MaterialTheme.colors.background),
items = items,
isConnected = status.value?.connected,
isConnected = status.connected,
onSignOutSelected = { handleSignOut() },
inputText = listsInputText,
onItemClicked = handleOnItemClicked,
onItemDeleteClicked = lists.value::onItemDeleteClicked,
onAddItemClicked = lists.value::onAddItemClicked,
onInputTextChanged = lists.value::onInputTextChanged,
hasSynced = hasSynced
hasSynced = hasSyncedLists
)
}

Expand All @@ -106,7 +113,7 @@ fun App(factory: DatabaseDriverFactory, modifier: Modifier = Modifier) {
modifier = modifier.background(MaterialTheme.colors.background),
navController = navController,
items = todoItems,
isConnected = status.value?.connected,
isConnected = status.connected,
inputText = todosInputText,
onItemClicked = todos.value::onItemClicked,
onItemDoneChanged = todos.value::onItemDoneChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal fun HomeScreen(
modifier: Modifier = Modifier,
items: List<ListItem>,
inputText: String,
isConnected: Boolean?,
isConnected: Boolean,
hasSynced: Boolean?,
onSignOutSelected: () -> Unit,
onItemClicked: (item: ListItem) -> Unit,
Expand All @@ -49,7 +49,7 @@ internal fun HomeScreen(
onSignOutSelected
) },
actions = {
WifiIcon(isConnected ?: false)
WifiIcon(isConnected)
Spacer(modifier = Modifier.width(16.dp))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal fun TodosScreen(
navController: NavController,
items: List<TodoItem>,
inputText: String,
isConnected: Boolean?,
isConnected: Boolean,
onItemClicked: (item: TodoItem) -> Unit,
onItemDoneChanged: (item: TodoItem, isDone: Boolean) -> Unit,
onItemDeleteClicked: (item: TodoItem) -> Unit,
Expand All @@ -53,7 +53,7 @@ internal fun TodosScreen(
}
},
actions = {
WifiIcon(isConnected ?: false)
WifiIcon(isConnected)
Spacer(modifier = Modifier.width(16.dp))
}
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.powersync.DatabaseDriverFactory
import com.powersync.demos.App

@Composable fun MainView() = App(DatabaseDriverFactory(), Modifier.fillMaxSize())
Loading