refactor: Improve error handling and remove code duplication

Extract duplicate UI update logic from reload_tasks and handle_sync into a shared update_ui_from_tasks method.
Add error notifications to StatusBar so users can see when task loading fails instead of silently showing an empty list.
Fix sidebar to only show pending tasks, filtering out deleted and completed ones.

Move magic numbers to constants in ui.rs (sidebar width, table column widths, date format) to make layout adjustments easier.
Standardize all date formatting to ISO 8601 (YYYY-MM-DD) for consistency across the app.
This commit is contained in:
Ignacio Perez
2025-12-28 12:06:49 -03:00
parent ae5309c716
commit 02b88f4326
5 changed files with 162 additions and 50 deletions
+73 -3
View File
@@ -1,7 +1,7 @@
use gpui::{Context, IntoElement, MouseButton, Render, Window, div, prelude::*, rems};
use crate::components::label::Label;
use crate::theme::ActiveTheme;
use crate::theme::{ActiveTheme, Theme};
use crate::ui::divider_v;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -21,6 +21,7 @@ impl Default for SyncState {
pub struct StatusBar {
sync_state: SyncState,
last_sync_message: String,
error_message: Option<String>,
}
impl StatusBar {
@@ -28,6 +29,7 @@ impl StatusBar {
Self {
sync_state: SyncState::default(),
last_sync_message: String::new(),
error_message: None,
}
}
@@ -47,6 +49,16 @@ impl StatusBar {
cx.notify();
}
pub fn set_error(&mut self, message: String, cx: &mut Context<Self>) {
self.error_message = Some(message);
cx.notify();
}
pub fn clear_error(&mut self, cx: &mut Context<Self>) {
self.error_message = None;
cx.notify();
}
fn sync_icon(&self) -> &'static str {
match self.sync_state {
SyncState::Idle => "",
@@ -98,7 +110,52 @@ impl Render for StatusBar {
Label::new("")
};
div()
let error_banner = if let Some(ref error) = self.error_message {
Some(
div()
.flex()
.items_center()
.justify_between()
.w_full()
.px_3()
.py_2()
.bg(Theme::alpha(theme.error, 0.12))
.border_1()
.border_color(theme.error)
.rounded_md()
.child(
div()
.flex()
.items_center()
.gap_2()
.child(Label::new("").text_color(theme.error).text_sm())
.child(
Label::new(error.clone())
.text_color(theme.error)
.text_sm(),
),
)
.child(
div()
.px_2()
.py_1()
.rounded_sm()
.cursor_pointer()
.hover(|s| s.bg(Theme::alpha(theme.error, 0.2)))
.on_mouse_down(
MouseButton::Left,
cx.listener(|this, _event, _window, cx| {
this.clear_error(cx);
}),
)
.child(Label::new("").text_color(theme.error).text_sm()),
),
)
} else {
None
};
let status_bar_content = div()
.flex()
.items_center()
.justify_between()
@@ -124,7 +181,20 @@ impl Render for StatusBar {
.gap_2()
.child(divider_v(&theme).h(rems(1.0)))
.child(sync_button),
)
);
if let Some(error) = error_banner {
div()
.flex()
.flex_col()
.w_full()
.gap_2()
.p_2()
.child(error)
.child(status_bar_content)
} else {
status_bar_content
}
}
}