gui: one ActionOutcome for every control's last-action line

Documents' AsyncActionState, Ensemble's ActionState and Settings'
RunNowState and RemoteTriggerState were four spellings of Idle / Pending /
succeeded-with-a-sentence / failed-with-a-sentence (audit S3). They are
job_binding::ActionOutcome — the half of a control's state the module doc
already said a job can't carry — with from_result for the "Ok → Done, Err →
Failed" match each result handler wrote, and is_pending. Settings' two
status-line matches are one widgets::outcome_line. Each screen keeps its own
colors and rendering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Opus 5.5 committed 2026-09-28 16:12:31 -07:00
1 parent 67e3f30e8a
commit 17346b270d
9 files changed
+131 -156

No files matched your search

@@ -29,7 +29,7 @@ use synchronicity::eviction::{self, EvictionPlan};
use synchronicity::jobs::{JobKind, JobOrigin, JobSubject};
use crate::background::spawn_then;
use crate::job_binding::JobControl;
use crate::job_binding::{ActionOutcome, JobControl};
use synchronicity::node::NodePubkey;
use synchronicity::p2p::asset_sync::{
push_document_to_peer, sync_document_asset, sync_document_assets_recursive,
@@ -67,9 +67,9 @@ use super::document_detail::{
property_table_rows,
};
use super::{
AsyncActionState, DeleteLocallyState, Detail, DetailState, DetailTab, DocRow, DocumentsView,
PlacementRow, PresenceLook, PropertyEditField, PropertyEditState, PropertyEditWidget,
PurgeState, RowOverride, SYNC_TAB_MAX_WIDTH, presence_with_help, validate_property_field,
DeleteLocallyState, Detail, DetailState, DetailTab, DocRow, DocumentsView, PlacementRow,
PresenceLook, PropertyEditField, PropertyEditState, PropertyEditWidget, PurgeState,
RowOverride, SYNC_TAB_MAX_WIDTH, presence_with_help, validate_property_field,
};
impl DocumentsView {
@@ -138,7 +138,7 @@ impl DocumentsView {
let Some(row) = self.detail.as_ref().and_then(|d| d.placement_rows.get(ix)) else {
return;
};
if matches!(row.override_write, AsyncActionState::Pending) {
if row.override_write.is_pending() {
return;
}
if row.is_this_node {
@@ -168,14 +168,14 @@ impl DocumentsView {
if let Err(e) = result {
log::error!("Failed to save sync override for {doc_id}: {e}");
if let Some(row) = self.detail.as_mut().and_then(|d| d.placement_rows.get_mut(ix)) {
row.override_write = AsyncActionState::Failed(e.to_string().into());
row.override_write = ActionOutcome::Failed(e.to_string().into());
}
cx.notify();
return;
}
if let Some(row) = self.detail.as_mut().and_then(|d| d.placement_rows.get_mut(ix)) {
row.sync_override = RowOverride::Known(over);
row.override_write = AsyncActionState::Idle;
row.override_write = ActionOutcome::Idle;
}
cx.notify();
}
@@ -435,7 +435,7 @@ impl DocumentsView {
return;
};
if let Some(row) = detail.placement_rows.get_mut(ix) {
row.action = AsyncActionState::Idle;
row.action = ActionOutcome::Idle;
}
self.active_jobs.refresh(&self.job_runner);
cx.notify();
@@ -478,10 +478,7 @@ impl DocumentsView {
move |this, result, cx| {
let ok = result.is_ok();
if let Some(row) = this.detail.as_mut().and_then(|d| d.placement_rows.get_mut(ix)) {
row.action = match result {
Ok(msg) => AsyncActionState::Done(msg.into()),
Err(e) => AsyncActionState::Failed(e.into()),
};
row.action = ActionOutcome::from_result(result);
}
// On success, refresh presence badges *and* every row's
// holding — a pull is precisely the thing that moves them.
@@ -573,13 +570,7 @@ impl DocumentsView {
move |this, result, cx| {
let ok = result.is_ok();
if let Some(detail) = this.detail.as_mut() {
detail.asset_sync.insert(
asset,
match result {
Ok(msg) => AsyncActionState::Done(msg.into()),
Err(e) => AsyncActionState::Failed(e.into()),
},
);
detail.asset_sync.insert(asset, ActionOutcome::from_result(result));
}
// On success, rebuild the rows so this one's presence badges
// and "not fetched locally" summary reflect what we pulled in.
@@ -678,7 +669,7 @@ impl DocumentsView {
// Safe to re-fetch: `job_runner` and `detail` are disjoint fields, and
// `ix`/the document/peer identity haven't changed since the checks above.
if let Some(row) = self.detail.as_mut().and_then(|d| d.placement_rows.get_mut(ix)) {
row.action = AsyncActionState::Idle;
row.action = ActionOutcome::Idle;
}
self.active_jobs.refresh(&self.job_runner);
cx.notify();
@@ -714,10 +705,7 @@ impl DocumentsView {
let doc_id = detail.id.clone();
let store = Arc::clone(&this.store);
if let Some(row) = detail.placement_rows.get_mut(ix) {
row.action = match result {
Ok(msg) => AsyncActionState::Done(msg.into()),
Err(e) => AsyncActionState::Failed(e.into()),
};
row.action = ActionOutcome::from_result(result);
// Refresh this row's belief about the peer's version to
// reflect what was just pushed.
let record = store
@@ -750,7 +738,7 @@ impl DocumentsView {
};
let doc_id = detail.id.clone();
if let Some(row) = detail.placement_rows.get_mut(ix) {
row.override_write = AsyncActionState::Pending;
row.override_write = ActionOutcome::Pending;
}
cx.notify();
@@ -772,8 +760,8 @@ impl DocumentsView {
return;
};
row.override_write = match &result {
Ok(_) => AsyncActionState::Done("Updated".into()),
Err(e) => AsyncActionState::Failed(e.clone().into()),
Ok(_) => ActionOutcome::Done("Updated".into()),
Err(e) => ActionOutcome::Failed(e.clone().into()),
};
if let Ok(confirmed) = result {
row.sync_override = RowOverride::Known(confirmed);
@@ -1328,9 +1316,9 @@ impl DocumentsView {
let activity = control.activity("Syncing…");
let status: Option<(SharedString, gpui::Rgba)> = match detail.asset_sync.get(&item.asset) {
_ if busy => None,
None | Some(AsyncActionState::Idle) | Some(AsyncActionState::Pending) => None,
Some(AsyncActionState::Done(msg)) => Some((msg.clone(), theme.text_secondary)),
Some(AsyncActionState::Failed(msg)) => Some((msg.clone(), theme.color_error)),
None | Some(ActionOutcome::Idle) | Some(ActionOutcome::Pending) => None,
Some(ActionOutcome::Done(msg)) => Some((msg.clone(), theme.text_secondary)),
Some(ActionOutcome::Failed(msg)) => Some((msg.clone(), theme.color_error)),
};
let asset = item.asset.clone();
@@ -1701,9 +1689,9 @@ impl DocumentsView {
// one's.
let status: Option<(SharedString, gpui::Rgba)> = match &row.action {
_ if busy => None,
AsyncActionState::Idle | AsyncActionState::Pending => None,
AsyncActionState::Done(msg) => Some((msg.clone(), theme.text_secondary)),
AsyncActionState::Failed(msg) => Some((msg.clone(), theme.color_error)),
ActionOutcome::Idle | ActionOutcome::Pending => None,
ActionOutcome::Done(msg) => Some((msg.clone(), theme.text_secondary)),
ActionOutcome::Failed(msg) => Some((msg.clone(), theme.color_error)),
};
let content = placement_content(row.holding.map(|h| h.files), detail.placement_total.0);
let content_color = match row.holding {
@@ -1821,7 +1809,7 @@ impl DocumentsView {
ix: usize,
cx: &mut Context<Self>,
) -> impl IntoElement + use<> {
let pending = matches!(row.override_write, AsyncActionState::Pending);
let pending = row.override_write.is_pending();
let current = row.sync_override;
let view = cx.entity();
let options = [
@@ -2189,9 +2177,9 @@ pub(super) fn placement_rows(
// Meaningless for this node: the column answers "does that node have
// the version we have", and here the two are the same thing.
latest_version: NodeVersionStatus::PresentUnknownVersion,
action: AsyncActionState::Idle,
action: ActionOutcome::Idle,
sync_override: RowOverride::Known(local_override),
override_write: AsyncActionState::Idle,
override_write: ActionOutcome::Idle,
}];
let peers = store
@@ -2221,9 +2209,9 @@ pub(super) fn placement_rows(
is_this_node: false,
holding: placement.peers.get(&node_pubkey).copied(),
latest_version: node_version_status(records_by_node.get(&node_pubkey)),
action: AsyncActionState::Idle,
action: ActionOutcome::Idle,
sync_override: RowOverride::Unknown,
override_write: AsyncActionState::Idle,
override_write: ActionOutcome::Idle,
}
}));
+4 -14
View File
@@ -55,7 +55,7 @@ use crate::components::tag_input::TagInput;
use crate::components::text_input::{InputEvent, TextInput};
use crate::components::tooltip::text_tooltip;
use crate::import_job;
use crate::job_binding::ActiveJobs;
use crate::job_binding::{ActionOutcome, ActiveJobs};
use crate::network_task::{self, NodeSlot};
use crate::sizing::{font, icon, scaled, shape};
use crate::store_watch;
@@ -217,9 +217,9 @@ struct PlacementRow {
latest_version: NodeVersionStatus,
/// Pull for this node, push for a peer — one field because the row offers
/// exactly one of them, and the user reads it as "the button on this row".
action: AsyncActionState,
action: ActionOutcome,
sync_override: RowOverride,
override_write: AsyncActionState,
override_write: ActionOutcome,
}
/// A node's Pin/Exclude override for the open document, as this screen knows
@@ -275,7 +275,7 @@ struct Detail {
/// `ContentFetch` job, read through [`active_jobs`](DocumentsView::active_jobs),
/// so a pull started by the scheduler or another screen shows here too. See
/// [`crate::job_binding`] for the split.
asset_sync: HashMap<ContentKey, AsyncActionState>,
asset_sync: HashMap<ContentKey, ActionOutcome>,
}
enum DetailState {
@@ -368,16 +368,6 @@ fn validate_property_field(
}
}
/// State of a fire-and-forget async action that reports a text result:
/// "Sync to this node" on the detail screen, and each row's own "Push now" in
/// the "Sync to other node" list.
enum AsyncActionState {
Idle,
Pending,
Done(SharedString),
Failed(SharedString),
}
/// State of the "Purge" action on the detail screen.
enum PurgeState {
Idle,
+27
View File
@@ -136,6 +136,33 @@ impl ActiveJobs {
}
}
/// What a control has to say about the last action it started — the result
/// sentence no job carries (see the module docs). Shared by every screen that
/// shows one: Documents' Sync/Push rows, Settings' Run now and remote Sync now,
/// and an Ensemble member's Ping and Sync.
#[derive(Clone, Default)]
pub enum ActionOutcome {
#[default]
Idle,
Pending,
Done(SharedString),
Failed(SharedString),
}
impl ActionOutcome {
/// `Done` with the success message, or `Failed` with the error's.
pub fn from_result(result: Result<impl Into<SharedString>, impl Into<SharedString>>) -> Self {
match result {
Ok(msg) => Self::Done(msg.into()),
Err(e) => Self::Failed(e.into()),
}
}
pub fn is_pending(&self) -> bool {
matches!(self, Self::Pending)
}
}
/// What one job-bound control has to know: the job it speaks for while that job
/// runs, and whether this screen has just asked for one that hasn't appeared
/// yet.
+4 -3
View File
@@ -10,7 +10,8 @@ use synchronicity::node::do_bootstrap_retry;
use synchronicity::stores::Store;
use tokio::runtime::Handle;
use super::{ActionState, LastAction, Loaded, MemberRow};
use super::{LastAction, Loaded, MemberRow};
use crate::job_binding::ActionOutcome;
use crate::network_task::NodeSlot;
@@ -73,8 +74,8 @@ pub(super) fn load_blocking(
// running: the Sync button asks `ActiveJobs` about the job
// itself. A `Pending` seeded here would outlive that job,
// since nothing but this screen's own click resolves it.
ping: ActionState::Idle,
sync: ActionState::Idle,
ping: ActionOutcome::Idle,
sync: ActionOutcome::Idle,
last_action: LastAction::default(),
}
})
+11 -23
View File
@@ -42,7 +42,7 @@ use crate::components::screen_header::{screen_header, screen_title};
use crate::components::section::section_heading;
use crate::components::text_input::{InputEvent, TextInput};
use crate::components::truncate::TruncateMiddle;
use crate::job_binding::ActiveJobs;
use crate::job_binding::{ActionOutcome, ActiveJobs};
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::{CONTENT_MAX_WIDTH, DIALOG_NARROW_WIDTH};
use crate::sizing::{control, font, scaled};
@@ -57,15 +57,6 @@ const FACT_LABEL_WIDTH: gpui::Rems = scaled(130.);
/// Width of the revoke dialog.
const DIALOG_WIDTH: gpui::Rems = scaled(460.);
/// The result/progress state of a ping or sync action on one member.
#[derive(Clone)]
enum ActionState {
Idle,
Pending,
Ok(SharedString),
Err(SharedString),
}
/// Which of a member's two actions (ping/sync) was started most recently.
///
/// `action_status`'s one status slot shows whichever action is currently
@@ -114,8 +105,8 @@ struct MemberRow {
/// while its condition holds — and empty is what keeps a healthy roster
/// one line per node.
health: Vec<PeerHealthCopy>,
ping: ActionState,
sync: ActionState,
ping: ActionOutcome,
sync: ActionOutcome,
/// See [`LastAction`].
last_action: LastAction,
}
@@ -390,7 +381,7 @@ impl EnsembleView {
fn ping(&mut self, target: String, cx: &mut Context<Self>) {
if let Some(row) = self.member_mut(&target) {
row.ping = ActionState::Pending;
row.ping = ActionOutcome::Pending;
row.last_action = LastAction::Ping;
}
cx.notify();
@@ -408,10 +399,7 @@ impl EnsembleView {
},
move |this, result, _| {
if let Some(row) = this.member_mut(&target) {
row.ping = match result {
Ok(ms) => ActionState::Ok(ms.into()),
Err(e) => ActionState::Err(e.into()),
};
row.ping = ActionOutcome::from_result(result);
}
},
)
@@ -421,7 +409,7 @@ impl EnsembleView {
fn sync(&mut self, target: String, cx: &mut Context<Self>) {
let Ok(peer) = target.parse::<NodePubkey>() else {
if let Some(row) = self.member_mut(&target) {
row.sync = ActionState::Err("invalid peer node ID".into());
row.sync = ActionOutcome::Failed("invalid peer node ID".into());
row.last_action = LastAction::Sync;
}
cx.notify();
@@ -438,7 +426,7 @@ impl EnsembleView {
// own dedup and comes back as "already running" rather than a second
// network sync.
if let Some(row) = self.member_mut(&target) {
row.sync = ActionState::Pending;
row.sync = ActionOutcome::Pending;
row.last_action = LastAction::Sync;
}
cx.notify();
@@ -494,12 +482,12 @@ impl EnsembleView {
if let Some(row) = this.member_mut(&target) {
match result {
Ok((msg, last_synced)) => {
row.sync = ActionState::Ok(msg.into());
row.sync = ActionOutcome::Done(msg.into());
if let Some(last_synced) = last_synced {
row.last_synced = last_synced.into();
}
}
Err(e) => row.sync = ActionState::Err(e.into()),
Err(e) => row.sync = ActionOutcome::Failed(e.into()),
}
}
},
@@ -1291,7 +1279,7 @@ impl EnsembleView {
.child(div().text_size(font::SMALL).text_color(theme.color_error).child(when));
}
let (ping_target, sync_target) = (member.node_id_hex.clone(), member.node_id_hex.clone());
let ping_pending = matches!(member.ping, ActionState::Pending);
let ping_pending = member.ping.is_pending();
// The job decides, not this screen's click: a catalog sync with this
// peer may already be running because the scheduler, the embedded
// daemon, or the peer's own `TriggerSync` started it, and offering to
@@ -1304,7 +1292,7 @@ impl EnsembleView {
.control(
JobKind::CatalogSync,
&JobSubject::Peer(peer),
matches!(member.sync, ActionState::Pending),
member.sync.is_pending(),
)
.busy()
})
+28 -23
View File
@@ -6,10 +6,11 @@
use gpui::{Div, FontWeight, IntoElement, Rems, SharedString, div, prelude::*, px};
use synchronicity::stores::settings::NODE_NAME_MAX_LEN;
use super::{ActionState, LastAction, MemberRow};
use super::{LastAction, MemberRow};
use crate::components::spinner::spinner;
use crate::components::tooltip::text_tooltip;
use crate::components::truncate::TruncateMiddle;
use crate::job_binding::ActionOutcome;
use crate::sizing::{control, font, scaled, shape};
use crate::theme::Theme;
use crate::typeface;
@@ -141,12 +142,16 @@ pub(super) fn coverage_cell(theme: &Theme, held: u64, total: u64, fraction: f32)
/// `Idle` or `Pending` by then, so nothing but the fixed fallback ever fired.
/// `last_action` is what breaks that tie correctly: whichever the user
/// asked for more recently.
fn status_priority(ping: &ActionState, sync: &ActionState, last_action: LastAction) -> LastAction {
fn status_priority(
ping: &ActionOutcome,
sync: &ActionOutcome,
last_action: LastAction,
) -> LastAction {
match (ping, sync) {
(ActionState::Pending, _) => LastAction::Ping,
(_, ActionState::Pending) => LastAction::Sync,
(ActionState::Idle, _) => LastAction::Sync,
(_, ActionState::Idle) => LastAction::Ping,
(ActionOutcome::Pending, _) => LastAction::Ping,
(_, ActionOutcome::Pending) => LastAction::Sync,
(ActionOutcome::Idle, _) => LastAction::Sync,
(_, ActionOutcome::Idle) => LastAction::Ping,
// Neither is in flight and neither is idle — both finished with a
// lingering result. Whichever was started more recently wins.
_ => last_action,
@@ -232,10 +237,10 @@ fn action_status(
LastAction::Sync => &member.sync,
};
match state {
ActionState::Idle => None,
ActionState::Pending => Some(spinner(theme, spin_id).into_any_element()),
ActionState::Ok(msg) | ActionState::Err(msg) => {
let color = if matches!(state, ActionState::Ok(_)) {
ActionOutcome::Idle => None,
ActionOutcome::Pending => Some(spinner(theme, spin_id).into_any_element()),
ActionOutcome::Done(msg) | ActionOutcome::Failed(msg) => {
let color = if matches!(state, ActionOutcome::Done(_)) {
theme.color_success
} else {
theme.color_error
@@ -290,15 +295,15 @@ mod tests {
/// showed the new action's own state while it was `Pending`.
#[test]
fn a_freshly_started_action_wins_over_the_other_ones_lingering_result() {
let synced = ActionState::Ok("synced 3 doc(s)".into());
let synced = ActionOutcome::Done("synced 3 doc(s)".into());
assert_eq!(
status_priority(&ActionState::Pending, &synced, LastAction::Ping),
status_priority(&ActionOutcome::Pending, &synced, LastAction::Ping),
LastAction::Ping
);
let pinged = ActionState::Err("timed out".into());
let pinged = ActionOutcome::Failed("timed out".into());
assert_eq!(
status_priority(&pinged, &ActionState::Pending, LastAction::Sync),
status_priority(&pinged, &ActionOutcome::Pending, LastAction::Sync),
LastAction::Sync
);
}
@@ -309,31 +314,31 @@ mod tests {
/// recency, this fell right back to always showing sync.
#[test]
fn a_more_recently_finished_action_wins_the_tie_over_an_older_one() {
let old_sync = ActionState::Ok("synced 3 doc(s)".into());
let new_ping = ActionState::Ok("12ms".into());
let old_sync = ActionOutcome::Done("synced 3 doc(s)".into());
let new_ping = ActionOutcome::Done("12ms".into());
assert_eq!(status_priority(&new_ping, &old_sync, LastAction::Ping), LastAction::Ping);
let old_ping = ActionState::Err("timed out".into());
let new_sync = ActionState::Ok("synced 1 doc(s)".into());
let old_ping = ActionOutcome::Failed("timed out".into());
let new_sync = ActionOutcome::Done("synced 1 doc(s)".into());
assert_eq!(status_priority(&old_ping, &new_sync, LastAction::Sync), LastAction::Sync);
}
#[test]
fn an_idle_action_defers_to_whatever_the_other_one_is_doing() {
let synced = ActionState::Ok("synced 3 doc(s)".into());
let synced = ActionOutcome::Done("synced 3 doc(s)".into());
assert_eq!(
status_priority(&ActionState::Idle, &synced, LastAction::Ping),
status_priority(&ActionOutcome::Idle, &synced, LastAction::Ping),
LastAction::Sync
);
let pinged = ActionState::Ok("12ms".into());
let pinged = ActionOutcome::Done("12ms".into());
assert_eq!(
status_priority(&pinged, &ActionState::Idle, LastAction::Sync),
status_priority(&pinged, &ActionOutcome::Idle, LastAction::Sync),
LastAction::Ping
);
assert_eq!(
status_priority(&ActionState::Idle, &ActionState::Idle, LastAction::Sync),
status_priority(&ActionOutcome::Idle, &ActionOutcome::Idle, LastAction::Sync),
LastAction::Sync
);
}
+5 -25
View File
@@ -51,7 +51,7 @@ use crate::app::AppServices;
use crate::components::screen_header::{screen_header, screen_title};
use crate::components::tabs::{tab_bar, tab_pill};
use crate::components::text_input::{InputEvent, TextInput};
use crate::job_binding::ActiveJobs;
use crate::job_binding::{ActionOutcome, ActiveJobs};
use crate::linkages::LinkagesView;
use crate::network_task::NodeSlot;
use crate::store_watch;
@@ -99,15 +99,6 @@ enum PublicKey {
Error(SharedString),
}
/// What the Sync tab's "Run now" button has to say *after* a run — the summary
/// line no job carries. Whether one is under way is the `BackgroundSync` job
/// itself, read through [`SettingsView::active_jobs`]. Read/written by [`sync`].
enum RunNowState {
Idle,
Ok(SharedString),
Err(SharedString),
}
/// The type-scoped "Reclaim…" flow in progress, if any (`docs/sync-management.md`'s
/// "Eviction is explicit" section) — mirrors the document detail screen's
/// `DeleteLocallyState`, scoped to a [`DocumentType`] instead of a subtree.
@@ -149,17 +140,6 @@ enum RemoteConfigState {
Unreachable(SharedString),
}
/// The result/progress state of the remote Sync policy tab's "Sync now"
/// button — mirrors [`RunNowState`], the local counterpart, but for
/// `node_admin::trigger_sync` against [`SyncTarget::Remote`] instead of
/// running a pass in-process. Read/written by [`sync`].
enum RemoteTriggerState {
Idle,
Pending,
Ok(SharedString),
Err(SharedString),
}
pub struct SettingsView {
store: Arc<Store>,
settings: SettingsStore,
@@ -215,7 +195,7 @@ pub struct SettingsView {
/// Master on/off + interval for the background sync scheduler.
scheduler_settings: SchedulerSettings,
/// What the last "Run now" said. Whether one is running is the job.
run_now: RunNowState,
run_now: ActionOutcome,
/// Every job running on this node, indexed by `(kind, subject)` so this
/// screen's controls can find their own — see [`crate::job_binding`]. The
/// "Run now" button and each type's "Reclaim…" read it, which is what lets
@@ -237,7 +217,7 @@ pub struct SettingsView {
/// (`node_admin::trigger_sync`) — separate from `remote_config` since
/// triggering a pass doesn't itself return updated config, unlike every
/// other `node_admin` call this tab makes.
remote_trigger: RemoteTriggerState,
remote_trigger: ActionOutcome,
// Public key
public_key: PublicKey,
@@ -358,12 +338,12 @@ impl SettingsView {
content_ledger,
reclaim: None,
scheduler_settings,
run_now: RunNowState::Idle,
run_now: ActionOutcome::Idle,
active_jobs,
sync_target: SyncTarget::Local,
remote_peers: Vec::new(),
remote_config: None,
remote_trigger: RemoteTriggerState::Idle,
remote_trigger: ActionOutcome::Idle,
public_key: PublicKey::Loading,
allow_unverified_deletion,
};
+14 -30
View File
@@ -19,13 +19,13 @@ use synchronicity::stores::Store;
use synchronicity::stores::settings::SchedulerSettings;
use synchronicity::sync_prefs::SyncPolicy;
use super::widgets::{last_section, section, section_description, status_line};
use super::{RemoteConfigState, RemoteTriggerState, RunNowState, SettingsView, SyncTarget};
use super::widgets::{last_section, outcome_line, section, section_description, status_line};
use super::{RemoteConfigState, SettingsView, SyncTarget};
use crate::background::spawn_then;
use crate::components::button::{OnClickIf, button};
use crate::components::segmented_control::segmented_bar;
use crate::components::sync_policy::SyncPolicyControl;
use crate::job_binding::JobControl;
use crate::job_binding::{ActionOutcome, JobControl};
use crate::network_task;
use crate::sizing::layout::CONTENT_MAX_WIDTH;
use crate::theme::{ActiveTheme, Theme};
@@ -109,7 +109,7 @@ impl SettingsView {
// A "Sync now" result from whichever node was previously selected
// (or "this node") doesn't apply here — drop it rather than
// showing a stale status line under the newly-selected node.
self.remote_trigger = RemoteTriggerState::Idle;
self.remote_trigger = ActionOutcome::Idle;
match target {
SyncTarget::Local => {
self.remote_config = None;
@@ -166,7 +166,7 @@ impl SettingsView {
/// leaving the user to wait for its own periodic scheduler tick.
fn render_remote_trigger(&self, cx: &mut Context<Self>) -> impl IntoElement + use<> {
let theme = cx.theme().clone();
let pending = matches!(self.remote_trigger, RemoteTriggerState::Pending);
let pending = self.remote_trigger.is_pending();
div()
.flex()
@@ -179,16 +179,7 @@ impl SettingsView {
cx.listener(|this, _, _, cx| this.trigger_remote_sync(cx)),
),
)
.child(self.render_remote_trigger_status(&theme))
}
fn render_remote_trigger_status(&self, theme: &Theme) -> impl IntoElement + use<> {
match &self.remote_trigger {
RemoteTriggerState::Idle => div(),
RemoteTriggerState::Pending => status_line(theme.text_secondary, "Starting…"),
RemoteTriggerState::Ok(msg) => status_line(theme.color_success, msg.clone()),
RemoteTriggerState::Err(msg) => status_line(theme.color_error, msg.clone()),
}
.child(outcome_line(&theme, &self.remote_trigger, "Starting…"))
}
fn render_remote_status(&self, theme: &Theme) -> impl IntoElement + use<> {
@@ -241,7 +232,7 @@ impl SettingsView {
let SyncTarget::Remote(pubkey) = self.sync_target else {
return;
};
self.remote_trigger = RemoteTriggerState::Pending;
self.remote_trigger = ActionOutcome::Pending;
cx.notify();
network_task::on_endpoint(
@@ -259,8 +250,8 @@ impl SettingsView {
return;
}
this.remote_trigger = match result {
Ok(()) => RemoteTriggerState::Ok("Sync started on this node".into()),
Err(e) => RemoteTriggerState::Err(e.into()),
Ok(()) => ActionOutcome::Done("Sync started on this node".into()),
Err(e) => ActionOutcome::Failed(e.into()),
};
},
)
@@ -362,13 +353,9 @@ impl SettingsView {
theme: &Theme,
control: &JobControl,
) -> impl IntoElement + use<> {
if let Some(activity) = control.activity("Running…") {
return status_line(theme.text_secondary, activity);
}
match &self.run_now {
RunNowState::Idle => div(),
RunNowState::Ok(msg) => status_line(theme.color_success, msg.clone()),
RunNowState::Err(msg) => status_line(theme.color_error, msg.clone()),
match control.activity("Running…") {
Some(activity) => status_line(theme.text_secondary, activity),
None => outcome_line(theme, &self.run_now, "Running…"),
}
}
@@ -391,7 +378,7 @@ impl SettingsView {
// The previous run's summary, cleared now that a new one is starting.
// Nothing here says "running" — `run_all_passes` opens the job, and the
// button reads that.
self.run_now = RunNowState::Idle;
self.run_now = ActionOutcome::Idle;
cx.notify();
let store = Arc::clone(&self.store);
@@ -428,10 +415,7 @@ impl SettingsView {
}
},
move |this, result, _| {
this.run_now = match result {
Ok(msg) => RunNowState::Ok(msg.into()),
Err(e) => RunNowState::Err(e.into()),
};
this.run_now = ActionOutcome::from_result(result);
},
)
.detach();
+12
View File
@@ -3,6 +3,7 @@
use gpui::{Div, IntoElement, SharedString, div, prelude::*, px};
use crate::components::section::section_heading;
use crate::job_binding::ActionOutcome;
use crate::sizing::font;
use crate::sizing::layout::PROSE_MAX_WIDTH;
use crate::theme::Theme;
@@ -63,6 +64,17 @@ pub(super) fn status_line(color: gpui::Rgba, text: impl Into<SharedString>) -> D
div().text_size(font::SMALL).text_color(color).child(text.into())
}
/// The line beside a control saying how its last action went, `pending` while
/// it runs.
pub(super) fn outcome_line(theme: &Theme, outcome: &ActionOutcome, pending: &'static str) -> Div {
match outcome {
ActionOutcome::Idle => div(),
ActionOutcome::Pending => status_line(theme.text_secondary, pending),
ActionOutcome::Done(msg) => status_line(theme.color_success, msg.clone()),
ActionOutcome::Failed(msg) => status_line(theme.color_error, msg.clone()),
}
}
/// One label/value row in the About section.
pub(super) fn about_row(
theme: &Theme,