Skip to content

Commit ae1795a

Browse files
authored
fix(rust-tui): Makes rust-tui actually stop syncing (#130)
1 parent e43d9cc commit ae1795a

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

.github/workflows/pr-checks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
- name: Install Rust
4545
uses: actions-rs/toolchain@v1
4646
with:
47-
toolchain: stable
4847
override: true
4948
components: rustfmt, clippy
5049

rust-toolchain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.85

rust-tui/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-tui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ path = "src/bin/main.rs"
1414

1515
[dependencies]
1616
# Ditto dependenceis
17-
dittolive-ditto = "4.11.1"
17+
dittolive-ditto = "4.11.2"
1818

1919
# External dependencies
2020
anyhow = "1"

rust-tui/src/tui/todolist.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Todolist {
3535
/// Ditto subscriptions must also be held to keep them alive
3636
///
3737
/// Subscriptions cause Ditto to sync selected data from other peers
38-
pub tasks_subscription: Option<Arc<SyncSubscription>>,
38+
pub tasks_subscription: Arc<SyncSubscription>,
3939

4040
// TUI state below
4141
pub mode: TodoMode,
@@ -90,7 +90,6 @@ impl Todolist {
9090
let tasks_subscription = ditto
9191
.sync()
9292
.register_subscription_v2("SELECT * FROM tasks")?;
93-
let tasks_subscription = Some(tasks_subscription);
9493

9594
// register observer for live query
9695
// Register observer, which runs against the local database on this peer
@@ -147,7 +146,7 @@ impl Todolist {
147146
})
148147
.collect::<Vec<_>>();
149148

150-
let sync_state = if self.tasks_subscription.is_some() {
149+
let sync_state = if self.ditto.is_sync_active() {
151150
" 🟢 Sync Active ".green()
152151
} else {
153152
" 🔴 Sync Inactive ".red()
@@ -286,19 +285,11 @@ impl Todolist {
286285
}
287286

288287
fn toggle_sync(&mut self) -> Result<()> {
289-
self.tasks_subscription = match &self.tasks_subscription {
290-
Some(subscription) => {
291-
subscription.cancel();
292-
None
293-
}
294-
None => {
295-
let sub = self
296-
.ditto
297-
.sync()
298-
.register_subscription_v2("SELECT * FROM tasks")?;
299-
Some(sub)
300-
}
301-
};
288+
if self.ditto.is_sync_active() {
289+
self.ditto.stop_sync();
290+
} else {
291+
self.ditto.start_sync()?;
292+
}
302293
Ok(())
303294
}
304295

@@ -349,8 +340,8 @@ impl Todolist {
349340
"UPDATE tasks SET deleted=true WHERE _id=:id",
350341
serde_json::json!({
351342
"id": id
352-
})),
353-
)
343+
}),
344+
))
354345
.await?;
355346

356347
Ok(())
@@ -365,8 +356,8 @@ impl Todolist {
365356
"INSERT INTO tasks DOCUMENTS (:task)",
366357
serde_json::json!({
367358
"task": task
368-
})),
369-
)
359+
}),
360+
))
370361
.await?;
371362
Ok(())
372363
}
@@ -377,11 +368,11 @@ impl Todolist {
377368
.store()
378369
.execute_v2((
379370
"UPDATE tasks SET title=:title WHERE _id=:id",
380-
serde_json::json!({
381-
"title": title,
382-
"id": id
383-
})),
384-
)
371+
serde_json::json!({
372+
"title": title,
373+
"id": id
374+
}),
375+
))
385376
.await?;
386377

387378
Ok(())

0 commit comments

Comments
 (0)