chore: improve ui consistently (#35)
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

Reviewed-on: #35
This commit was merged in pull request #35.
This commit is contained in:
2026-11-20 12:28:25 +00:00
parent 51dd5c8630
commit f850f4c4c1
90 changed files with 2859 additions and 2061 deletions
+239
View File
@@ -0,0 +1,239 @@
//! The shared issue and pull-request lists: toolbar, uniform rows, scrollbar
//! overlay, and empty state, plus the scrollable commit list.
use std::rc::Rc;
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement,
ParentElement as _, Pixels, SharedString, StatefulInteractiveElement as _, Styled as _,
UniformListScrollHandle, Window, div, px, uniform_list,
};
use nostr::prelude::PublicKey;
use signed_core::RepoStatus;
use signed_git::FileCommit;
use ui::avatar::Avatar;
use ui::common::{Sizable as _, h_flex, v_flex};
use ui::theme::ActiveTheme as _;
use crate::repo::helpers::commit_row;
use crate::shared::widgets::{empty_state, scroll_overlay, status_badge};
/// The height of one issue or pull-request row.
pub const ROW_HEIGHT: f32 = 73.;
/// A row's activation handler.
pub type EventHandler = Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
/// The toolbar above the issue and pull-request lists: a filter and its actions.
pub fn filter_toolbar(cx: &App, children: impl IntoIterator<Item = AnyElement>) -> AnyElement {
h_flex()
.px_4()
.w_full()
.gap_3()
.border_b_1()
.border_color(cx.theme().colors.border)
.bg(cx.theme().colors.muted)
.children(children)
.into_any_element()
}
/// One issue or pull-request row's display data and click handler.
pub struct EventRow {
pub id: ElementId,
pub status: RepoStatus,
pub title: SharedString,
pub author: SharedString,
pub picture: Option<SharedString>,
pub pubkey: PublicKey,
pub short_id: SharedString,
pub age: SharedString,
pub on_click: EventHandler,
}
/// The shared issue and pull-request list: toolbar, uniform rows, scrollbar
/// overlay, and empty state.
pub struct EventList {
id: ElementId,
toolbar: Option<AnyElement>,
rows: Vec<EventRow>,
scroll_handle: UniformListScrollHandle,
empty_message: SharedString,
}
impl EventList {
/// Builds a list rendering `rows` under `toolbar`.
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
toolbar: None,
rows: Vec::new(),
scroll_handle: UniformListScrollHandle::new(),
empty_message: "Nothing here".into(),
}
}
/// Replaces the list's scroll handle with the caller's.
pub fn scroll_handle(mut self, handle: UniformListScrollHandle) -> Self {
self.scroll_handle = handle;
self
}
/// Sets the toolbar above the rows.
pub fn toolbar(mut self, toolbar: AnyElement) -> Self {
self.toolbar = Some(toolbar);
self
}
/// Sets the rendered rows.
pub fn rows(mut self, rows: Vec<EventRow>) -> Self {
self.rows = rows;
self
}
/// Sets the empty-state message shown when no rows match.
pub fn empty_message(mut self, message: impl Into<SharedString>) -> Self {
self.empty_message = message.into();
self
}
/// Renders the list.
pub fn render(self, _cx: &App) -> AnyElement {
let count = self.rows.len();
let rows = self.rows;
let row_height = px(ROW_HEIGHT);
v_flex()
.relative()
.flex_1()
.min_h_0()
.w_full()
.children(self.toolbar)
.when(count > 0, |this| {
this.child(
uniform_list((self.id.clone(), "rows"), count, move |range, _, cx| {
range
.map(|ix| {
let Some(row) = rows.get(ix) else {
return div().into_any_element();
};
event_row(row, row_height, cx)
})
.collect()
})
.track_scroll(&self.scroll_handle)
.size_full(),
)
.child(scroll_overlay(
(self.id.clone(), "scroll"),
self.scroll_handle.clone(),
))
})
.when(count == 0, |this| {
this.child(empty_state(self.empty_message))
})
.into_any_element()
}
}
/// Renders one issue or pull-request row.
pub fn event_row(row: &EventRow, row_height: Pixels, cx: &App) -> AnyElement {
h_flex()
.id(row.id.clone())
.w_full()
.h(row_height)
.gap_4()
.px_4()
.border_b_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.on_click({
let on_click = row.on_click.clone();
move |event, window, cx| on_click(event, window, cx)
})
.child(status_badge(row.status))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.child(
div()
.text_base()
.text_ellipsis()
.whitespace_nowrap()
.child(row.title.clone()),
)
.child(event_meta_row(row, cx)),
)
.into_any_element()
}
/// The author, age, and id line under a row's title.
pub fn event_meta_row(row: &EventRow, cx: &App) -> AnyElement {
h_flex()
.gap_2()
.text_xs()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(row.pubkey)
.name(row.author.clone())
.picture(row.picture.clone())
.small(),
)
.child(div().child(row.author.clone())),
)
.child(SharedString::from("opened"))
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child(row.short_id.clone()),
)
.child(row.age.clone())
.into_any_element()
}
/// A scrollable commit list: uniform `commit_row`s under a scrollbar overlay.
#[allow(clippy::too_many_arguments)]
pub fn commit_list(
id: &'static str,
scroll_id: &'static str,
commits: Arc<Vec<FileCommit>>,
scroll_handle: UniformListScrollHandle,
action: impl Fn(usize, &FileCommit, &App) -> Option<AnyElement> + 'static,
on_click: impl Fn(&FileCommit, &mut Window, &mut App) + Clone + 'static,
_cx: &App,
) -> AnyElement {
let count = commits.len();
v_flex()
.relative()
.flex_1()
.min_h_0()
.child(
uniform_list(id, count, move |range, _, cx| {
range
.map(|ix| {
let commit = commits[ix].clone();
let action = action(ix, &commit, cx);
let on_click = on_click.clone();
let row_commit = commit.clone();
commit_row(
ix,
&commit,
action,
move |window, cx| on_click(&row_commit, window, cx),
cx,
)
})
.collect()
})
.track_scroll(&scroll_handle)
.size_full(),
)
.child(scroll_overlay(scroll_id, scroll_handle))
.into_any_element()
}
+20
View File
@@ -1,3 +1,8 @@
use gpui::{App, Entity};
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
pub mod event_list;
pub mod panels;
pub mod progress;
pub mod tree;
@@ -15,3 +20,18 @@ pub fn log_dropped<T>(result: Result<T, anyhow::Error>) {
);
}
}
/// Tracks a detail view's author, commenters, and repository owner for
/// profile prefetch.
pub fn track_event_participants(
author: Option<PublicKey>,
owner: Option<PublicKey>,
comments: impl Iterator<Item = PublicKey>,
directory: &Entity<ProfileDirectory>,
cx: &mut App,
) {
let mut keys: Vec<PublicKey> = author.into_iter().collect();
keys.extend(comments);
keys.extend(owner);
directory.update(cx, |directory, cx| directory.track(keys, cx));
}
+40 -2
View File
@@ -1,10 +1,11 @@
use gpui::{
AnyElement, App, Context, IntoElement as _, ParentElement as _, SharedString, Styled as _,
Subscription, div,
AnyElement, App, AsyncApp, Context, Entity, IntoElement as _, ParentElement as _, SharedString,
Styled as _, Subscription, Task, div,
};
use signed_core::RepoAddr;
use signed_state::{Backend, BackendEvent, PushStepStatus};
use ui::common::{h_flex, v_flex};
use ui::dialog::DialogHandle;
use ui::icons::{Icon, IconRole};
use ui::spinner::Spinner;
use ui::theme::ActiveTheme as _;
@@ -126,3 +127,40 @@ pub fn push_steps_row(steps: &[PushStepStatus], cx: &App) -> Option<AnyElement>
Some(v_flex().gap_1().children(rows).into_any_element())
}
/// Runs a dialog task to completion.
pub fn run_dialog_task<T: 'static>(
task: Task<Result<T, anyhow::Error>>,
state: &Entity<DialogProgress>,
handle: &DialogHandle,
cx: &mut App,
) {
let state = state.clone();
let handle = handle.clone();
run_dialog_task_with(
task,
cx,
move |_, cx| cx.update(|cx| handle.close(cx)),
move |error, cx| {
state.update(cx, |state, cx| {
state.fail(error.to_string());
cx.notify();
});
},
);
}
/// Runs a dialog task to completion, with explicit success and failure sinks.
pub fn run_dialog_task_with<T: 'static>(
task: Task<Result<T, anyhow::Error>>,
cx: &mut App,
on_success: impl FnOnce(T, &mut AsyncApp) + 'static,
on_error: impl FnOnce(anyhow::Error, &mut AsyncApp) + 'static,
) {
cx.spawn(async move |cx| match task.await {
Ok(value) => on_success(value, cx),
Err(error) => on_error(error, cx),
})
.detach();
}
+59 -3
View File
@@ -1,9 +1,14 @@
use gpui::{AnyElement, App, IntoElement, ParentElement as _, SharedString, Styled as _, div};
use gpui::{
AnyElement, App, ElementId, IntoElement, ParentElement as _, SharedString, Styled as _, div,
};
use signed_core::RepoStatus;
use ui::badge::{Badge, BadgeVariant};
use ui::common::StyledExt as _;
use ui::clipboard::ClipboardButton;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole};
use ui::scrollbar::{Scrollbar, ScrollbarHandle};
use ui::spinner::Spinner;
use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip;
@@ -25,7 +30,7 @@ pub fn status_badge(status: RepoStatus) -> Badge {
/// A centered empty-state message filling the available space.
pub fn empty_state(message: impl Into<SharedString>) -> AnyElement {
let message = message.into();
ui::common::v_flex()
v_flex()
.size_full()
.items_center()
.justify_center()
@@ -33,6 +38,57 @@ pub fn empty_state(message: impl Into<SharedString>) -> AnyElement {
.into_any_element()
}
/// A centered spinner filling the available space.
pub fn centered_spinner(id: impl Into<ElementId>) -> AnyElement {
v_flex()
.size_full()
.items_center()
.justify_center()
.child(Spinner::new(id))
.into_any_element()
}
/// The vertical scrollbar pinned over a uniform list's full extent.
pub fn scroll_overlay<I, H>(id: I, handle: H) -> AnyElement
where
I: Into<ElementId>,
H: ScrollbarHandle,
{
div()
.absolute()
.top_0()
.left_0()
.right_0()
.bottom_0()
.child(Scrollbar::vertical(id, handle))
.into_any_element()
}
/// One copyable clone command with its text visible next to the copy icon.
pub fn clone_row(id: SharedString, command: SharedString, cx: &App) -> AnyElement {
h_flex()
.h_8()
.px_2()
.gap_2()
.min_w_0()
.bg(cx.theme().colors.secondary)
.rounded(cx.theme().radius.control)
.text_color(cx.theme().colors.secondary_foreground)
.child(
div()
.flex_1()
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.font_family(cx.theme().mono_font)
.text_xs()
.child(command.clone()),
)
.child(ClipboardButton::new(id, command).xsmall())
.into_any_element()
}
/// A one-line muted label used by section headers.
pub fn section_label(text: impl Into<SharedString>, cx: &App) -> AnyElement {
div()