Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 6749490

Browse files
authored
Merge pull request #93 from bytes-zone/dont-throw-out-information
choose whether to merge/replace
2 parents c9163d6 + ee659d0 commit 6749490

8 files changed

Lines changed: 73 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## 0.5.2 (Unreleased)
3+
## 0.5.2 (2025-01-28)
4+
5+
- Logging in no longer replaces your document. Instead, it asks if you'd like to merge or replace.
6+
7+
This release is available as a container image at `ghcr.io/bytes-zone/beeps:v0.5.2`.
48

59
## 0.5.1 (2025-01-28)
610

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.

beeps-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "beeps-server"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2021"
55

66
[dependencies]

beeps/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "beeps"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2021"
55

66
[lints]

beeps/src/app.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use popover::{AuthIntent, Popover};
1616
use crate::config::Config;
1717
use beeps_core::{
1818
sync::{login, register, Client},
19-
NodeId, Replica,
19+
Document, NodeId, Replica,
2020
};
2121
use chrono::{DateTime, Local, Utc};
2222
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
@@ -42,7 +42,12 @@ pub struct App {
4242

4343
/// If we're replacing the entire replica on the next sync (for example when
4444
/// initially logging in.)
45-
replace_on_next_sync: bool,
45+
in_first_sync: bool,
46+
47+
/// The document we got on our first sync. We keep this separate to decide
48+
/// whether to replace our current document with this or merge them
49+
/// together.
50+
first_sync_document: Option<Document>,
4651

4752
/// State of the pings table
4853
table_state: TableState,
@@ -89,7 +94,8 @@ impl App {
8994
Ok(Self {
9095
status_line: Some("Loaded replica".to_string()),
9196
replica,
92-
replace_on_next_sync: false,
97+
in_first_sync: false,
98+
first_sync_document: None,
9399
client: auth,
94100
last_sync: None,
95101
table_state: TableState::new().with_selected(0),
@@ -104,7 +110,8 @@ impl App {
104110
status_line: None,
105111
replica: Replica::new(NodeId::random()),
106112
client: auth,
107-
replace_on_next_sync: false,
113+
in_first_sync: false,
114+
first_sync_document: None,
108115
last_sync: None,
109116
table_state: TableState::new().with_selected(0),
110117
popover: None,
@@ -253,7 +260,7 @@ impl App {
253260
}
254261
Action::LoggedIn(client) => {
255262
self.client = Some(client.clone());
256-
self.replace_on_next_sync = true;
263+
self.in_first_sync = true;
257264

258265
vec![
259266
Effect::SaveSyncClientAuth(client.clone()),
@@ -273,12 +280,12 @@ impl App {
273280
Action::Pulled(resp) => {
274281
self.status_line = Some("Got a new doc from the server".to_string());
275282

276-
if self.replace_on_next_sync {
277-
self.replica.replace_doc(resp.document);
278-
self.replace_on_next_sync = false;
283+
if self.in_first_sync {
284+
self.first_sync_document = Some(resp.document);
285+
self.popover = Some(Popover::ConfirmReplaceOrMerge);
279286
} else {
280287
self.replica.merge(resp.document);
281-
}
288+
};
282289

283290
vec![]
284291
}
@@ -355,6 +362,25 @@ impl App {
355362
}
356363
_ => auth.handle_event(key),
357364
},
365+
Some(Popover::ConfirmReplaceOrMerge) => match key.code {
366+
KeyCode::Char('r') => {
367+
self.dismiss_popover();
368+
self.in_first_sync = false;
369+
if let Some(document) = self.first_sync_document.take() {
370+
self.replica.replace_doc(document);
371+
effects.push(Effect::SaveReplica(self.replica.clone()));
372+
}
373+
}
374+
KeyCode::Char('m') => {
375+
self.dismiss_popover();
376+
self.in_first_sync = false;
377+
if let Some(document) = self.first_sync_document.take() {
378+
self.replica.merge(document);
379+
effects.push(Effect::SaveReplica(self.replica.clone()));
380+
}
381+
}
382+
_ => (),
383+
},
358384
}
359385

360386
effects

beeps/src/app/popover.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub enum Popover {
1919

2020
/// Register with the server
2121
Authenticating(auth_form::AuthForm, AuthIntent),
22+
23+
/// Confirm whether or not we want to replace the full sync information or merge it.
24+
ConfirmReplaceOrMerge,
2225
}
2326

2427
/// When we're working with an Authenticating popover, what do we intend to do
@@ -103,6 +106,28 @@ impl Popover {
103106
));
104107
}
105108
Popover::Authenticating(auth, _) => auth.render(body_area, frame),
109+
Popover::ConfirmReplaceOrMerge => {
110+
let popup_vert = Layout::vertical([Constraint::Percentage(50)]).flex(Flex::Center);
111+
let popup_horiz =
112+
Layout::horizontal([Constraint::Percentage(50)]).flex(Flex::Center);
113+
114+
let [popup_area] = popup_vert.areas(body_area);
115+
let [popup_area] = popup_horiz.areas(popup_area);
116+
117+
let popup = Paragraph::new(
118+
"You've successfully logged in! Do you want to replace your local data with the server's data, or merge local and remote data?\n\nPress 'r' to replace, or 'm' to merge.",
119+
)
120+
.block(
121+
Block::default()
122+
.borders(Borders::ALL)
123+
.title("Replace or Merge?")
124+
.padding(Padding::horizontal(1))
125+
.border_style(Style::new().blue()),
126+
);
127+
128+
frame.render_widget(Clear, popup_area);
129+
frame.render_widget(popup, popup_area);
130+
}
106131
}
107132
}
108133
}

beeps_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "beeps_core"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2021"
55

66
[lints]

browser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "browser"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2021"
55

66
[lib]

0 commit comments

Comments
 (0)