chore: restructure ui components
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

This commit is contained in:
2026-11-27 21:05:37 +07:00
parent db3d53f2aa
commit 44c2dc6345
114 changed files with 9117 additions and 7675 deletions
+283 -163
View File
@@ -2,9 +2,9 @@ use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, Pixels, Render, ScrollHandle, SharedString, Styled as _, Subscription,
WeakEntity, Window, div, px,
AnyElement, App, AppContext as _, Context, ElementId, Entity, IntoElement, ListAlignment,
ListSizingBehavior, ListState, ParentElement as _, Pixels, Render, ScrollHandle, SharedString,
Styled as _, Subscription, Window, div, list, px, rems,
};
use metadata::ProfileDirectory;
use nostr::prelude::EventId;
@@ -12,19 +12,21 @@ use signed_core::GitEvent;
use signed_state::RepoStore;
use ui::avatar::Avatar;
use ui::badge::{Badge, BadgeVariant};
use ui::button::Button;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::empty_state::EmptyState;
use ui::input::InputState;
use ui::layout::panel::{Panel, PanelSlot, SplitSide};
use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState};
use ui::layout::panel::{Panel, PanelSlot, PanelStack, SplitSide};
use ui::scroll_area::ScrollArea;
use ui::spinner::Spinner;
use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip;
use utils::relative_time;
use crate::app::AppRoot;
use crate::issues::helpers::{comment_form, comments_section};
use crate::shared::labels::ProfileDirectoryExt as _;
use crate::shared::log_dropped;
use crate::shared::widgets::status_badge;
use crate::shared::{log_dropped, track_event_participants};
/// The split pane showing the issue's participants and labels.
const SIDEBAR_ID: &str = "Issue details";
@@ -37,6 +39,7 @@ pub struct IssueDetailView {
/// Profiles for the author, commenters and the repository owner.
directory: Entity<ProfileDirectory>,
scroll_handle: ScrollHandle,
comments_scroll: ListState,
_subscription: Subscription,
}
@@ -44,7 +47,7 @@ impl IssueDetailView {
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
let comment_input = InputState::builder().multiline().build(cx);
let directory = ProfileDirectory::new(cx);
let weak = cx.entity().downgrade();
let weak = cx.weak_entity();
let subscription = cx.observe(&store, |this, _store, cx| {
this.track_participants(cx);
@@ -63,13 +66,14 @@ impl IssueDetailView {
comment_input,
directory,
scroll_handle: ScrollHandle::new(),
comments_scroll: ListState::new(0, ListAlignment::Top, px(48.)),
_subscription: subscription,
}
}
/// Opens the issue's detail as the main panel and its sidebar in the split pane.
pub fn open(
workspace: &WeakEntity<AppRoot>,
panels: &Entity<PanelStack>,
store: Entity<RepoStore>,
issue_id: EventId,
window: &mut Window,
@@ -78,35 +82,33 @@ impl IssueDetailView {
let id = SharedString::from(format!("issue:{issue_id}"));
let sidebar_store = store.clone();
log_dropped(workspace.update(cx, |root, cx| {
root.panels().update(cx, |panels, cx| {
panels.open(
PanelSlot::Main,
id,
{
let store = store.clone();
move |_, cx| cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx))
},
window,
cx,
);
panels.update(cx, |panels, cx| {
panels.open(
PanelSlot::Main,
id,
{
let store = store.clone();
move |_, cx| cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx))
},
window,
cx,
);
let sidebar = cx.new(|cx| IssueSidebarView {
store: sidebar_store.clone(),
issue_id,
directory: ProfileDirectory::new(cx),
scroll_handle: ScrollHandle::new(),
});
let sidebar = cx.new(|cx| IssueSidebarView {
store: sidebar_store.clone(),
issue_id,
directory: ProfileDirectory::new(cx),
scroll_handle: ScrollHandle::new(),
});
panels.insert_split_at(
SIDEBAR_ID,
SIDEBAR_WIDTH,
SplitSide::Trailing,
Arc::new(sidebar),
cx,
);
})
}));
panels.insert_split_at(
SIDEBAR_ID,
SIDEBAR_WIDTH,
SplitSide::Trailing,
Arc::new(sidebar),
cx,
);
});
}
/// Track the issue author, everyone who commented and the repository owner.
@@ -125,7 +127,81 @@ impl IssueDetailView {
.map(|comment| comment.pubkey)
.collect();
track_event_participants(author, owner, comments.into_iter(), &self.directory, cx);
self.directory
.track_participants(author, owner, comments.into_iter(), cx);
}
/// One comment card of the issue's discussion.
fn render_comment(&self, ix: usize, cx: &App) -> AnyElement {
let Some(comment) = self.store.read(cx).comments_of(&self.issue_id).nth(ix) else {
return div().into_any_element();
};
let profile = self.directory.read(cx).profile(&comment.pubkey, cx);
let author = profile.name();
let age = relative_time(comment.created_at);
let content = SharedString::from(comment.content.as_str());
v_flex()
.gap_1()
.p_3()
.border_1()
.border_color(cx.theme().colors.border)
.rounded(cx.theme().radius.control)
.child(
h_flex()
.gap_2()
.text_sm()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(comment.pubkey)
.name(author.clone())
.picture(profile.picture())
.small(),
)
.child(author),
)
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child("commented"),
)
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(age)),
),
)
.child(div().text_sm().child(content))
.into_any_element()
}
/// Posts the composer's text as a comment on this issue.
fn submit_comment(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let content = self.comment_input.read(cx).value().trim().to_string();
if content.is_empty() {
return;
}
let event = self
.store
.read(cx)
.issues
.iter()
.find(|event| event.id == self.issue_id)
.cloned();
if let Some(event) = event {
self.store.update(cx, |store, cx| {
store.comment(&event, content, cx);
});
}
self.comment_input.update(cx, |input, cx| {
input.set_value("", window, cx);
});
}
}
@@ -174,9 +250,9 @@ impl Render for IssueDetailView {
let Some(issue) = store.issues.iter().find(|issue| issue.id == self.issue_id) else {
// A not-yet-loaded store is not the same as a missing issue.
return if store.loaded {
EmptyState::centered("Issue not found")
EmptyState::centered("Issue not found").into_any_element()
} else {
Spinner::centered("issue-loading")
Spinner::centered("issue-loading").into_any_element()
};
};
@@ -199,75 +275,125 @@ impl Render for IssueDetailView {
};
let picture = self.directory.read(cx).profile(&pubkey, cx).picture();
div()
.id("issue-detail")
ScrollArea::new("issue-detail-scroll")
.handle(self.scroll_handle.clone())
.size_full()
.child(
ScrollArea::new("issue-detail-scroll")
.handle(self.scroll_handle.clone())
.size_full()
v_flex()
.p_4()
.gap_6()
.child(
h_flex()
.gap_2()
.child(status_badge(status))
.child(div().flex_1().min_w_0().font_semibold().child(title)),
)
.child(
v_flex()
.p_4()
.gap_6()
.child(
h_flex()
.gap_2()
.child(status_badge(status))
.child(div().flex_1().min_w_0().font_semibold().child(title)),
)
.gap_8()
.child(
v_flex()
.gap_8()
.gap_4()
.child(
v_flex()
.gap_4()
h_flex()
.gap_2()
.text_sm()
.child(
h_flex()
.gap_2()
.text_sm()
.gap_1()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(pubkey)
.name(author.clone())
.picture(picture)
.small(),
)
.child(author),
Avatar::new(pubkey)
.name(author.clone())
.picture(picture)
.small(),
)
.child(
div()
.text_color(
cx.theme().colors.muted_foreground,
)
.child("opened"),
)
.child(
div()
.text_color(
cx.theme().colors.muted_foreground,
)
.child(SharedString::from(age)),
),
.child(author),
)
.child(content),
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child("opened"),
)
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(age)),
),
)
.child(comments_section(
&self.store,
issue_id,
&self.directory,
cx,
))
.child(comment_form(
&self.store,
issue_id,
&store.issues,
&self.comment_input,
"comment",
cx,
)),
.child(content),
)
.child({
let comments = self.store.read(cx).comments_of(&issue_id).count();
if self.comments_scroll.item_count() != comments {
self.comments_scroll.reset(comments);
}
v_flex()
.gap_4()
.child(
h_flex()
.gap_2()
.child(Icon::named(IconRole::Message))
.child(
div()
.text_sm()
.font_semibold()
.child("Discussions"),
)
.child(Badge::new(
format!("discussion-count:{issue_id}"),
comments.to_string(),
)),
)
.child(
v_flex().max_h(rems(24.)).min_h_0().child(
list(
self.comments_scroll.clone(),
cx.processor(|this, ix, _, cx| {
this.render_comment(ix, cx)
}),
)
.with_sizing_behavior(ListSizingBehavior::Infer),
),
)
})
.child(
v_flex()
.gap_2()
.child(
Input::new("comment-input", self.comment_input.clone())
.placeholder("Leave a comment...")
.rows(4),
)
.child(
h_flex()
.justify_between()
.child(
h_flex()
.gap_1()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(
Icon::named(IconRole::Markdown)
.size(px(12.))
.color(
cx.theme().colors.muted_foreground,
),
)
.child("Markdown is supported"),
)
.child(
Button::new("comment")
.label("Comment")
.tooltip(Tooltip::text("Post comment"))
.on_click(cx.listener(
|this, _, window, cx| {
this.submit_comment(window, cx)
},
)),
),
),
),
),
)
@@ -292,78 +418,79 @@ impl Panel for IssueSidebarView {
impl Render for IssueSidebarView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let store = self.store.read(cx);
let root = store.issues.iter().find(|issue| issue.id == self.issue_id);
let details = store
.issues
.iter()
.find(|issue| issue.id == self.issue_id)
.map(|root| {
ScrollArea::new("issue-sidebar-scroll")
.handle(self.scroll_handle.clone())
.size_full()
.child(v_flex().w_full().p_4().when_some(root, |this, root| {
let mut participants = vec![root.pubkey];
participants.extend(store.comments_of(&root.id).map(|comment| comment.pubkey));
participants.sort_by_key(|key| key.to_hex());
participants.sort_by_key(|key| key.to_bytes());
participants.dedup();
let labels: Vec<String> = root.tags.hashtags().map(|tag| tag.to_string()).collect();
let labels: Vec<SharedString> =
root.tags.hashtags().map(SharedString::from).collect();
v_flex()
.gap_4()
.child(
v_flex()
.gap_2()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child("Participants"),
)
.children(participants.iter().map(|pubkey| {
let profile = self.directory.read(cx).profile(pubkey, cx);
let name = profile.name();
this.child(
v_flex()
.gap_4()
.child(
v_flex()
.gap_2()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child("Participants"),
)
.children(participants.iter().map(|pubkey| {
let profile = self.directory.read(cx).profile(pubkey, cx);
let name = profile.name();
h_flex()
.gap_1()
.child(
Avatar::new(*pubkey)
.name(name.clone())
.picture(profile.picture())
.small(),
)
.child(
div()
.flex_1()
.min_w_0()
.whitespace_nowrap()
.text_sm()
.text_ellipsis()
.child(name),
)
.into_any_element()
})),
)
.child(
v_flex()
.gap_2()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child("Labels"),
)
.map(|this| {
if labels.is_empty() {
h_flex()
.gap_1()
.child(
Avatar::new(*pubkey)
.name(name.clone())
.picture(profile.picture())
.small(),
)
.child(
div()
.flex_1()
.min_w_0()
.whitespace_nowrap()
.text_sm()
.text_ellipsis()
.child(name),
)
})),
)
.child(
v_flex()
.gap_2()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child("Labels"),
)
.when(labels.is_empty(), |this| {
this.child(
div()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child("None yet."),
)
} else {
})
.when(!labels.is_empty(), |this| {
this.child(v_flex().gap_1().items_start().children(
labels.iter().map(|label| {
Badge::new(
SharedString::from(format!("label:{label}")),
(ElementId::from("label"), label.clone()),
label.clone(),
)
.variant(BadgeVariant::Outline)
@@ -371,16 +498,9 @@ impl Render for IssueSidebarView {
.flex_none()
}),
))
}
}),
)
.into_any_element()
})
.unwrap_or_else(|| div().into_any_element());
ScrollArea::new("issue-sidebar-scroll")
.handle(self.scroll_handle.clone())
.size_full()
.child(v_flex().w_full().p_4().child(details))
}),
),
)
}))
}
}
-180
View File
@@ -1,19 +1,4 @@
use gpui::{
AnyElement, App, Entity, IntoElement, ParentElement as _, SharedString, Styled as _, div, px,
};
use metadata::ProfileDirectory;
use nostr::prelude::{Event, EventId};
use signed_core::RepoStatus;
use signed_state::RepoStore;
use ui::avatar::Avatar;
use ui::badge::Badge;
use ui::button::Button;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState};
use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip;
use utils::relative_time;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum IssueFilter {
@@ -31,168 +16,3 @@ impl IssueFilter {
}
}
}
/// Root events counted by their resolved status.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct StatusCounts {
pub(crate) total: usize,
pub(crate) open: usize,
pub(crate) closed: usize,
pub(crate) draft: usize,
pub(crate) applied: usize,
}
impl StatusCounts {
fn record(&mut self, status: RepoStatus) {
self.total += 1;
match status {
RepoStatus::Open => self.open += 1,
RepoStatus::Closed => self.closed += 1,
RepoStatus::Draft => self.draft += 1,
RepoStatus::Applied => self.applied += 1,
}
}
}
/// Indices of `roots` whose status `keep` accepts, counting every root's status.
pub(crate) fn filter_by_status<'a>(
roots: impl IntoIterator<Item = &'a Event>,
status_of: impl Fn(&Event) -> RepoStatus,
keep: impl Fn(RepoStatus) -> bool,
) -> (Vec<usize>, StatusCounts) {
let mut counts = StatusCounts::default();
let visible = roots
.into_iter()
.enumerate()
.filter_map(|(index, root)| {
let status = status_of(root);
counts.record(status);
keep(status).then_some(index)
})
.collect();
(visible, counts)
}
pub(crate) fn comments_section(
store: &Entity<RepoStore>,
root: EventId,
directory: &Entity<ProfileDirectory>,
cx: &App,
) -> AnyElement {
let store = store.read(cx);
let comments: Vec<&Event> = store.comments_of(&root).collect();
let count = comments.len();
v_flex()
.gap_4()
.child(
h_flex()
.gap_2()
.child(Icon::named(IconRole::Message))
.child(div().text_sm().font_semibold().child("Discussions"))
.child(Badge::new(
format!("discussion-count:{root}"),
count.to_string(),
)),
)
.children(comments.iter().map(|comment| {
let profile = directory.read(cx).profile(&comment.pubkey, cx);
let author = profile.name();
let age = relative_time(comment.created_at);
let content = SharedString::from(comment.content.as_str());
v_flex()
.gap_1()
.p_3()
.border_1()
.border_color(cx.theme().colors.border)
.rounded(cx.theme().radius.control)
.child(
h_flex()
.gap_2()
.text_sm()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(comment.pubkey)
.name(author.clone())
.picture(profile.picture())
.small(),
)
.child(author),
)
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child("commented"),
)
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(age)),
),
)
.child(div().text_sm().child(content))
}))
.into_any_element()
}
pub(crate) fn comment_form(
store: &Entity<RepoStore>,
root: EventId,
roots: &[Event],
comment_input: &Entity<InputState>,
button_id: &'static str,
cx: &App,
) -> AnyElement {
let Some(root) = roots.iter().find(|event| event.id == root).cloned() else {
return div().into_any_element();
};
let comment_input = comment_input.clone();
let store = store.clone();
v_flex()
.gap_2()
.child(
Input::new("comment-input", comment_input.clone())
.placeholder("Leave a comment...")
.rows(4),
)
.child(
h_flex()
.justify_between()
.child(
h_flex()
.gap_1()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(
Icon::named(IconRole::Markdown)
.size(px(12.))
.color(cx.theme().colors.muted_foreground),
)
.child("Markdown is supported"),
)
.child(
Button::new(button_id)
.label("Comment")
.tooltip(Tooltip::text("Post comment"))
.on_click(move |_, window, cx| {
let content = comment_input.read(cx).value().trim().to_string();
if content.is_empty() {
return;
}
store.update(cx, |store, cx| {
store.comment(&root, content, cx);
});
comment_input.update(cx, |input, cx| {
input.set_value("", window, cx);
});
}),
),
)
.into_any_element()
}
+153 -129
View File
@@ -1,13 +1,16 @@
use std::ops::Range;
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled as _,
Subscription, UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
};
use helpers::{IssueFilter, StatusCounts, filter_by_status};
use helpers::IssueFilter;
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
use signed_core::GitEvent;
use nostr::prelude::{EventId, PublicKey};
use signed_core::{GitEvent, RepoStatus};
use signed_state::RepoStore;
use ui::avatar::Avatar;
use ui::button::Button;
@@ -23,19 +26,31 @@ use utils::relative_time;
use self::detail::IssueDetailView;
use crate::app::AppRoot;
use crate::issues::new_issue::NewIssueView;
use crate::repo::helpers::short_id;
use crate::shared::labels::ShortIdExt as _;
use crate::shared::log_dropped;
use crate::shared::widgets::status_badge;
use crate::shared::widgets::{StatusCounts, status_badge};
pub mod detail;
pub(crate) mod helpers;
pub mod new_issue;
/// One issue row, with its display strings built on rebuild.
struct IssueRow {
id: EventId,
/// The row's element id.
element_id: SharedString,
status: RepoStatus,
subject: SharedString,
author: PublicKey,
age: SharedString,
short: SharedString,
}
pub struct IssuesView {
workspace: WeakEntity<AppRoot>,
store: Entity<RepoStore>,
filter: IssueFilter,
visible_issues: Vec<usize>,
rows: Arc<Vec<IssueRow>>,
counts: StatusCounts,
// A filter change notifies even when the visible rows are unchanged.
synced_filter: IssueFilter,
@@ -51,7 +66,7 @@ impl IssuesView {
store: Entity<RepoStore>,
cx: &mut Context<Self>,
) -> Self {
let weak = cx.entity().downgrade();
let weak = cx.weak_entity();
let subscription = cx.observe(&store, |this, _store, cx| {
this.rebuild(cx);
});
@@ -66,7 +81,7 @@ impl IssuesView {
workspace,
store: store.clone(),
filter: IssueFilter::Open,
visible_issues: Vec::new(),
rows: Arc::new(Vec::new()),
counts: StatusCounts::default(),
synced_filter: IssueFilter::Open,
scroll_handle: UniformListScrollHandle::new(),
@@ -117,48 +132,150 @@ impl IssuesView {
let (visible_issues, counts) = {
let store = self.store.read(cx);
filter_by_status(
StatusCounts::filter(
&store.issues,
|issue| store.status_of(issue),
|status| filter.matches(status),
)
};
let store = self.store.read(cx);
let mut keys: Vec<PublicKey> = store.issues.iter().map(|issue| issue.pubkey).collect();
let (keys, rows) = {
let store = self.store.read(cx);
let mut keys: Vec<PublicKey> = store.issues.iter().map(|issue| issue.pubkey).collect();
if let Some(owner) = store
.announcement
.as_ref()
.map(|announcement| announcement.owner)
{
keys.push(owner);
}
if let Some(owner) = store
.announcement
.as_ref()
.map(|announcement| announcement.owner)
{
keys.push(owner);
}
let rows: Vec<IssueRow> = visible_issues
.iter()
.filter_map(|index| {
let issue = store.issues.get(*index)?;
Some(IssueRow {
id: issue.id,
element_id: SharedString::from(format!("issue:{}", issue.id.to_hex())),
status: store.status_of(issue),
subject: SharedString::from(issue.activity_subject()),
author: issue.pubkey,
age: SharedString::from(relative_time(issue.created_at)),
short: issue.id.to_hex().short_id(),
})
})
.collect();
(keys, rows)
};
self.directory.update(cx, |directory, cx| {
directory.track(keys, cx);
});
let filter_changed = self.synced_filter != filter;
let visible_issues_changed = self.visible_issues != visible_issues;
let counts_changed = self.counts != counts;
let rows_changed = self.rows.len() != rows.len();
if !filter_changed && !visible_issues_changed && !counts_changed {
if !filter_changed && !counts_changed && !rows_changed {
return;
}
self.synced_filter = filter;
self.visible_issues = visible_issues;
self.rows = Arc::new(rows);
self.counts = counts;
cx.notify();
}
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
/// One issue row of the list.
fn render_issue(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
let Some(row) = self.rows.get(ix) else {
return div().into_any_element();
};
let profile = self.directory.read(cx).profile(&row.author, cx);
let issue_id = row.id;
let status = row.status;
h_flex()
.id(row.element_id.clone())
.w_full()
.h_16()
.px_2()
.border_b_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.on_click(cx.listener(move |this, _, window, cx| {
this.open_issue(issue_id, window, cx);
}))
.child(
h_flex()
.w_full()
.items_start()
.gap_2()
.child(h_flex().w_20().child(status_badge(status)))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.child(
div()
.text_sm()
.text_ellipsis()
.whitespace_nowrap()
.child(row.subject.clone()),
)
.child(
h_flex()
.gap_2()
.text_xs()
.child(
h_flex()
.min_w_0()
.gap_1()
.child(
Avatar::new(row.author)
.name(profile.name())
.picture(profile.picture())
.small(),
)
.child(
div().min_w_0().truncate().child(profile.name()),
),
)
.child("opened")
.child(
div()
.text_color(cx.theme().colors.muted_foreground)
.child(row.short.clone()),
)
.child(row.age.clone()),
),
),
)
.into_any_element()
}
/// Opens this issue's detail panel in the split stack.
fn open_issue(&mut self, issue_id: EventId, window: &mut Window, cx: &mut Context<Self>) {
let panels = self
.workspace
.read_with(cx, |root, _| root.panels().clone());
let Ok(panels) = panels else {
log::warn!("issue list outlived the app shell");
return;
};
IssueDetailView::open(&panels, self.store.clone(), issue_id, window, cx);
}
fn render_header(&self, cx: &mut Context<Self>) -> impl IntoElement {
let counts = self.counts;
let colors = cx.theme().colors;
let muted = colors.muted_foreground;
let weak = cx.entity().downgrade();
h_flex()
.px_2()
@@ -181,14 +298,10 @@ impl IssuesView {
.label(format!("Closed ({})", counts.closed))
.icon(Icon::named(IconRole::GitIssueClosed).color(muted)),
])
.on_change(move |filter, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.filter = filter;
this.rebuild(cx);
}) {
log::warn!("failed to switch issue filter: {error}");
}
}),
.on_change(cx.processor(|this, filter: IssueFilter, _, cx| {
this.filter = filter;
this.rebuild(cx);
})),
)
.child(div().flex_1())
.child(
@@ -200,7 +313,6 @@ impl IssuesView {
this.open_new_issue(window, cx);
})),
)
.into_any_element()
}
}
@@ -213,12 +325,8 @@ impl Panel for IssuesView {
impl Render for IssuesView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let filter = self.filter;
let visible_issues = self.visible_issues.clone();
let directory = self.directory.clone();
let store = self.store.clone();
let workspace = self.workspace.clone();
let scroll_handle = self.scroll_handle.clone();
let count = visible_issues.len();
let count = self.rows.len();
let empty_message = match filter {
IssueFilter::All => "No issues",
@@ -237,96 +345,13 @@ impl Render for IssuesView {
.child(self.render_header(cx))
.when(count > 0, |this| {
this.child(
uniform_list("issues", count, move |range, _, cx| {
range
.map(|ix| {
// The store re-read per frame can shrink below a captured index.
let Some(issue) =
visible_issues.get(ix).and_then(|issue_ix| {
store.read(cx).issues.get(*issue_ix)
})
else {
return div().into_any_element();
};
let profile = directory.read(cx).profile(&issue.pubkey, cx);
let issue_id = issue.id;
let id_hex = issue.id.to_hex();
let status = store.read(cx).status_of(issue);
let store = store.clone();
let workspace = workspace.clone();
h_flex()
.id(SharedString::from(format!("issue:{id_hex}")))
.w_full()
.h_16()
.px_2()
.border_b_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.on_click(move |_, window, cx| {
IssueDetailView::open(
&workspace,
store.clone(),
issue_id,
window,
cx,
);
})
.child(
h_flex()
.w_full()
.items_start()
.gap_2()
.child(h_flex().w_20().child(status_badge(status)))
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.child(
div()
.text_sm()
.text_ellipsis()
.whitespace_nowrap()
.child(issue.activity_subject()),
)
.child(
h_flex()
.gap_2()
.text_xs()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(issue.pubkey)
.name(profile.name())
.picture(
profile.picture(),
)
.small(),
)
.child(
div().child(profile.name()),
),
)
.child("opened")
.child(
div()
.text_color(
cx.theme()
.colors
.muted_foreground,
)
.child(short_id(&id_hex)),
)
.child(relative_time(issue.created_at)),
),
),
)
.into_any_element()
})
.collect()
})
uniform_list(
"issues",
count,
cx.processor(|this, range: Range<usize>, _, cx| {
range.map(|ix| this.render_issue(ix, cx)).collect()
}),
)
.track_scroll(&scroll_handle)
.size_full(),
)
@@ -334,8 +359,7 @@ impl Render for IssuesView {
})
.when(count == 0, |this| {
this.child(EmptyState::centered(empty_message))
})
.into_any_element(),
}),
)
.into_any_element()
}
+14 -8
View File
@@ -13,7 +13,6 @@ use ui::theme::ActiveTheme as _;
use crate::app::AppRoot;
use crate::shared::log_dropped;
use crate::shared::progress::error_row;
pub struct NewIssueView {
workspace: WeakEntity<AppRoot>,
@@ -64,9 +63,11 @@ impl NewIssueView {
let workspace = self.workspace.clone();
let panel_id = self.panel_id.clone();
let task = self
.store
.update(cx, |store, cx| store.open_issue(subject, content, cx));
self.submit_task = Some(cx.spawn(async move |this, cx| match task.await {
Ok(()) => {
log_dropped(workspace.update(cx, |root, cx| {
@@ -86,8 +87,6 @@ impl NewIssueView {
}
fn render_footer(&self, cx: &Context<Self>) -> AnyElement {
let weak = cx.entity().downgrade();
h_flex()
.px_4()
.py_2()
@@ -100,9 +99,7 @@ impl NewIssueView {
.label("Create issue")
.loading(self.submitting)
.disabled(self.submitting)
.on_click(move |_, _, cx| {
log_dropped(weak.update(cx, |this, cx| this.submit(cx)));
}),
.on_click(cx.listener(|this, _, _, cx| this.submit(cx))),
)
.into_any_element()
}
@@ -124,6 +121,8 @@ impl Panel for NewIssueView {
impl Render for NewIssueView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
const HINT: &str = "Report a bug, ask a question, or propose a change.";
v_flex()
.id("new-issue")
.size_full()
@@ -137,7 +136,7 @@ impl Render for NewIssueView {
.pr_16()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child("Report a bug, ask a question, or propose a change."),
.child(HINT),
)
.child(
Field::new("issue-title", "Title")
@@ -147,7 +146,14 @@ impl Render for NewIssueView {
Field::new("issue-content", "Content")
.child(Input::new("issue-content-input", self.content.clone()).rows(6)),
)
.when_some(error_row(&self.error, cx), |this, error| this.child(error)),
.when_some(self.error.clone(), |this, error| {
this.child(
div()
.text_sm()
.text_color(cx.theme().ramps.destructive.base)
.child(error),
)
}),
)
.child(self.render_footer(cx))
}