2. Review another copy before applying it
A real sync completion would call offer_remote from its completion reducer. The documentation harness supplies a separate preview control so you can try that transition without a server. The control is not part of the production component and does not stand in for a successful network request.
While a conflict is visible, keep the two copies stable. Keeping the local draft creates a new change based on the reviewed server revision; choosing the incoming copy clears the obsolete queued change. A later incoming copy at or below the accepted server revision is ignored.
This model deliberately keeps one pending replacement per note, not an append-only history. That is appropriate here because a note is a replaceable document. A payment, stock movement or audit event cannot generally be collapsed this way; those operations need their own durable identities and acceptance rules.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/state.rs","value":"src-state-rs"},{"index":1,"label":"src/app.rs","value":"src-app-rs"},{"index":2,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/state.rs","value":"src-state-rs"}
use fission::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LocalChange {
pub sequence: u64,
pub base_revision: u64,
pub text: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ServerCopy {
pub revision: u64,
pub text: String,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct OfflineState {
pub draft: String,
pub remote: Option<ServerCopy>,
pub queued: Option<LocalChange>,
pub base_revision: u64,
pub local_sequence: u64,
pub status: &'static str,
}
impl GlobalState for OfflineState {}
impl OfflineState {
pub fn queue_note(&mut self) {
if self.remote.is_some() { return; }
if self.draft.trim().is_empty() {
self.status = "note.required";
return;
}
if self.queued.as_ref().is_some_and(|change| change.text == self.draft) {
self.status = "note.unchanged";
return;
}
self.local_sequence += 1;
self.queued = Some(LocalChange {
sequence: self.local_sequence,
base_revision: self.base_revision,
text: self.draft.clone(),
});
self.status = "note.queued";
}
}
impl OfflineState {
pub fn offer_remote(&mut self, copy: ServerCopy) {
if copy.revision <= self.base_revision
|| self.remote.as_ref().is_some_and(|current| current.revision >= copy.revision)
{
return;
}
self.remote = Some(copy);
self.status = "note.review";
}
pub fn keep_local(&mut self) {
if self.draft.trim().is_empty() {
self.status = "note.required";
return;
}
let Some(remote) = self.remote.take() else { return };
self.base_revision = remote.revision;
self.local_sequence += 1;
self.queued = Some(LocalChange {
sequence: self.local_sequence,
base_revision: self.base_revision,
text: self.draft.clone(),
});
self.status = "note.kept";
}
pub fn use_server(&mut self) {
let Some(remote) = self.remote.take() else { return };
self.draft = remote.text;
self.base_revision = remote.revision;
self.queued = None;
self.status = "note.selected";
}
}
{"id":"fission-tabs-1","index":1,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::state::OfflineState;
fission_component! {
pub OfflineNotes<OfflineState> {}
view(_notes, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let status = if state.status.is_empty() { "note.ready" } else { state.status };
} =>
Container(Scroll(child: Container(
Column(gap: tokens.spacing.m, children: [
Text(cx.tr("note.title")).size(tokens.typography.heading2_size),
Text(cx.tr("note.summary")).color(tokens.colors.text_secondary),
TextInput(
label: Some(cx.tr("note.draft").into()),
bind: state.draft,
read_only: state.remote.is_some(),
multiline: true,
min_lines: Some(3),
max_lines: Some(7),
semantics_identifier: Some("inspection-note.draft".into()),
),
Button(
child: Text(cx.tr("note.queue")),
key: "queue-note",
disabled: state.remote.is_some(),
on_press: reduce { state.queue_note(); },
),
Text(cx.tr(status)),
if let Some(change) = &state.queued {
Container(Column(gap: tokens.spacing.s, children: [
Text(cx.tr("note.snapshot")).weight(tokens.typography.font_weight_semibold),
Text(change.text.clone()),
Text(cx.tr("note.sequence").replace("{sequence}", &change.sequence.to_string())),
Text(cx.tr("note.base").replace("{revision}", &change.base_revision.to_string())),
])).padding_all(tokens.spacing.m).bg(tokens.colors.surface),
},
if let Some(remote) = &state.remote {
Container(Column(gap: tokens.spacing.s, children: [
Text(cx.tr("note.server").replace("{revision}", &remote.revision.to_string()))
.weight(tokens.typography.font_weight_semibold),
Text(remote.text.clone()),
Text(cx.tr("note.choice")),
Wrap(spacing: tokens.spacing.s, children: [
Button(
child: Text(cx.tr("note.keep")),
key: "keep-local",
on_press: reduce { state.keep_local(); },
),
Button(
child: Text(cx.tr("note.use_server")),
key: "use-server",
variant: ButtonVariant::Outline,
on_press: reduce { state.use_server(); },
),
]),
])).padding_all(tokens.spacing.m).bg(tokens.colors.surface),
},
Text(cx.tr("note.scope")).color(tokens.colors.text_secondary),
])
).padding_all(tokens.spacing.l)
.width_length(Length::percent(100.0))
.max_width(720.0)))
.height_length(Length::vh(100.0))
}
{"id":"fission-tabs-1","index":2,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod state;
mod app;
mod translations;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<state::OfflineState, _>::new(ConflictPreview)
.with_env(translations::create_env())
.with_title("Inspection note model")
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
// This control belongs to the documentation harness, not the app or sync service.
fission_component! {
pub ConflictPreview<state::OfflineState> {}
view(_preview, state, cx) =>
Column(children: [
Button(
child: Text(cx.tr("preview.receive")),
key: "preview-server-copy",
on_press: reduce {
state.offer_remote(state::ServerCopy {
revision: state.base_revision + 1,
text: "Pressure rose after another inspection; check the relief valve.".into(),
});
},
),
app::OfflineNotes,
])
}
{"id":"fission-tabs-1"}
Queue your draft, receive the example incoming copy, and read both before choosing. Keeping yours must preserve its text; choosing the incoming copy must remove the obsolete queued snapshot.
Show the app previewHide the app preview
Show the app preview
Hide the app preview