chore: improve ui consistently (#35)
Reviewed-on: #35
This commit was merged in pull request #35.
This commit is contained in:
@@ -3,12 +3,11 @@ use gpui::{
|
||||
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{EventId, PublicKey};
|
||||
use nostr::prelude::EventId;
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
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;
|
||||
use ui::scroll_area::ScrollArea;
|
||||
@@ -56,27 +55,23 @@ impl IssueDetailView {
|
||||
/// Track the issue author, everyone who commented and the repository owner.
|
||||
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
||||
let store = self.store.read(cx);
|
||||
let mut keys: Vec<PublicKey> = store
|
||||
let author = store
|
||||
.issues
|
||||
.iter()
|
||||
.find(|issue| issue.id == self.issue_id)
|
||||
.map(|issue| issue.pubkey)
|
||||
.into_iter()
|
||||
.map(|issue| issue.pubkey);
|
||||
let owner = store.announcement.as_ref().map(|a| a.owner);
|
||||
let comments: Vec<_> = store
|
||||
.comments_of(&self.issue_id)
|
||||
.map(|comment| comment.pubkey)
|
||||
.collect();
|
||||
|
||||
keys.extend(
|
||||
store
|
||||
.comments_of(&self.issue_id)
|
||||
.map(|comment| comment.pubkey),
|
||||
crate::shared::track_event_participants(
|
||||
author,
|
||||
owner,
|
||||
comments.into_iter(),
|
||||
&self.directory,
|
||||
cx,
|
||||
);
|
||||
|
||||
if let Some(owner) = store.announcement.as_ref().map(|a| a.owner) {
|
||||
keys.push(owner);
|
||||
}
|
||||
|
||||
self.directory.update(cx, |directory, cx| {
|
||||
directory.track(keys, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,17 +92,12 @@ impl Render for IssueDetailView {
|
||||
let store = self.store.read(cx);
|
||||
|
||||
let Some(issue) = store.issues.iter().find(|issue| issue.id == self.issue_id) else {
|
||||
let message = if store.loaded {
|
||||
"Issue not found"
|
||||
// A not-yet-loaded store is not the same as a missing issue.
|
||||
return if store.loaded {
|
||||
crate::shared::widgets::empty_state("Issue not found")
|
||||
} else {
|
||||
"Loading issue..."
|
||||
crate::shared::widgets::centered_spinner("issue-loading")
|
||||
};
|
||||
return v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new(message))
|
||||
.into_any_element();
|
||||
};
|
||||
|
||||
let (title, author, status, age, issue_id, content, pubkey) = {
|
||||
|
||||
@@ -1,36 +1,33 @@
|
||||
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, px, uniform_list,
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
|
||||
};
|
||||
use helpers::{IssueFilter, StatusCounts, filter_by_status};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::PublicKey;
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::button::Button;
|
||||
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::common::v_flex;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use self::detail::IssueDetailView;
|
||||
use crate::repo::helpers::short_id;
|
||||
use crate::shared::event_list::{EventList, EventRow};
|
||||
use crate::shared::panels;
|
||||
use crate::shared::widgets::status_badge;
|
||||
use crate::workspace::Workspace;
|
||||
|
||||
pub mod detail;
|
||||
pub(crate) mod helpers;
|
||||
pub mod new_issue;
|
||||
|
||||
const ISSUE_ROW_HEIGHT: f32 = 73.;
|
||||
|
||||
pub struct IssuesView {
|
||||
workspace: WeakEntity<Workspace>,
|
||||
store: Entity<RepoStore>,
|
||||
@@ -131,14 +128,9 @@ impl IssuesView {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
let weak = cx.entity().downgrade();
|
||||
|
||||
h_flex()
|
||||
.px_4()
|
||||
.w_full()
|
||||
.gap_3()
|
||||
.border_b_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.bg(cx.theme().colors.muted)
|
||||
.child(
|
||||
crate::shared::event_list::filter_toolbar(
|
||||
cx,
|
||||
[
|
||||
Segmented::new("issue-filter", self.filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(IssueFilter::All, format!("All ({})", counts.total))
|
||||
@@ -158,18 +150,18 @@ impl IssuesView {
|
||||
}) {
|
||||
log::warn!("failed to switch issue filter: {error}");
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(div().flex_1())
|
||||
.child(
|
||||
})
|
||||
.into_any_element(),
|
||||
div().flex_1().into_any_element(),
|
||||
Button::new("new-issue")
|
||||
.label("New issue")
|
||||
.icon(Icon::named(IconRole::CirclePlus))
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.open_new_issue(cx);
|
||||
})),
|
||||
)
|
||||
.into_any_element()
|
||||
}))
|
||||
.into_any_element(),
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,147 +174,70 @@ 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 count = self.visible_issues.len();
|
||||
let visible_issues = self.visible_issues.clone();
|
||||
let directory = self.directory.clone();
|
||||
let store = self.store.clone();
|
||||
let workspace = self.workspace.clone();
|
||||
|
||||
let rows = visible_issues
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(ix, &issue_ix)| {
|
||||
// The store re-read per frame can shrink below a captured index.
|
||||
let issue = store.read(cx).issues.get(issue_ix)?;
|
||||
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 on_click: crate::shared::event_list::EventHandler = {
|
||||
let workspace = workspace.clone();
|
||||
let store = store.clone();
|
||||
Rc::new(move |_, window, cx| {
|
||||
let id = SharedString::from(format!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| IssueDetailView::new(store.clone(), issue_id, cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
};
|
||||
|
||||
Some(EventRow {
|
||||
id: ix.into(),
|
||||
status,
|
||||
title: issue.activity_subject().into(),
|
||||
author: profile.name(),
|
||||
picture: profile.picture(),
|
||||
pubkey: issue.pubkey,
|
||||
short_id: short_id(&id_hex),
|
||||
age: SharedString::from(relative_time(issue.created_at)),
|
||||
on_click,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
let empty_message = match filter {
|
||||
IssueFilter::All => "No issues",
|
||||
IssueFilter::Open => "No open issues",
|
||||
IssueFilter::Closed => "No closed issues",
|
||||
};
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.child(self.render_header(cx))
|
||||
.when_some(self.new_issue.clone(), |el, view| el.child(view))
|
||||
.child(
|
||||
v_flex()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.w_full()
|
||||
.when(count > 0, |this| {
|
||||
this.child(
|
||||
uniform_list("issues", count, move |range, _, cx| {
|
||||
range
|
||||
.map(|ix| {
|
||||
let issue_ix = visible_issues[ix];
|
||||
let issue = &store.read(cx).issues[issue_ix];
|
||||
let title = issue.activity_subject();
|
||||
let id_hex = issue.id.to_hex();
|
||||
let profile = directory.read(cx).profile(&issue.pubkey, cx);
|
||||
let author = profile.name();
|
||||
let age = relative_time(issue.created_at);
|
||||
let status = store.read(cx).status_of(issue);
|
||||
let issue_id = issue.id;
|
||||
let workspace = workspace.clone();
|
||||
let store = store.clone();
|
||||
|
||||
h_flex()
|
||||
.id(ix)
|
||||
.w_full()
|
||||
.h(px(ISSUE_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(move |_, window, cx| {
|
||||
let id =
|
||||
SharedString::from(format!("issue:{issue_id}"));
|
||||
let store = store.clone();
|
||||
panels::open_detail(
|
||||
&workspace,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(
|
||||
store.clone(),
|
||||
issue_id,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.child(status_badge(status))
|
||||
.child(
|
||||
v_flex()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.gap_1()
|
||||
.child(
|
||||
div()
|
||||
.text_base()
|
||||
.text_ellipsis()
|
||||
.whitespace_nowrap()
|
||||
.child(title),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.text_xs()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Avatar::new(issue.pubkey)
|
||||
.name(author.clone())
|
||||
.picture(
|
||||
profile.picture(),
|
||||
)
|
||||
.small(),
|
||||
)
|
||||
.child(div().child(author)),
|
||||
)
|
||||
.child(SharedString::from("opened"))
|
||||
.child(
|
||||
div()
|
||||
.text_color(
|
||||
cx.theme()
|
||||
.colors
|
||||
.muted_foreground,
|
||||
)
|
||||
.child(SharedString::from(
|
||||
&id_hex[..8],
|
||||
)),
|
||||
)
|
||||
.child(SharedString::from(age)),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&self.scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
.top_0()
|
||||
.left_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.child(Scrollbar::vertical(
|
||||
"issues-scroll",
|
||||
self.scroll_handle.clone(),
|
||||
)),
|
||||
)
|
||||
})
|
||||
.when(count == 0, |this| {
|
||||
let message = match filter {
|
||||
IssueFilter::All => "No issues",
|
||||
IssueFilter::Open => "No open issues",
|
||||
IssueFilter::Closed => "No closed issues",
|
||||
};
|
||||
this.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new(message)),
|
||||
)
|
||||
}),
|
||||
EventList::new("issues")
|
||||
.toolbar(self.render_header(cx))
|
||||
.scroll_handle(self.scroll_handle.clone())
|
||||
.rows(rows)
|
||||
.empty_message(empty_message)
|
||||
.render(cx),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
@@ -10,31 +10,41 @@ use ui::field::Field;
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::shared::progress::DialogProgress;
|
||||
|
||||
pub struct NewIssueDialog {
|
||||
handle: DialogHandle,
|
||||
store: Entity<RepoStore>,
|
||||
subject: Entity<InputState>,
|
||||
content: Entity<InputState>,
|
||||
state: Entity<DialogProgress>,
|
||||
}
|
||||
|
||||
impl NewIssueDialog {
|
||||
pub fn new(store: Entity<RepoStore>, cx: &mut App) -> Entity<Self> {
|
||||
let subject = InputState::new(cx);
|
||||
let content = InputState::builder().multiline().build(cx);
|
||||
let state = cx.new(|_| DialogProgress::default());
|
||||
|
||||
cx.new(|_| Self {
|
||||
handle: DialogHandle::new(true),
|
||||
store,
|
||||
subject,
|
||||
content,
|
||||
state,
|
||||
})
|
||||
}
|
||||
|
||||
fn submit(&mut self, cx: &mut Context<Self>) {
|
||||
// The publish runs detached in the store; one submission per dialog.
|
||||
if self.state.read(cx).busy {
|
||||
return;
|
||||
}
|
||||
let subject = self.subject.read(cx).value().to_string();
|
||||
let content = self.content.read(cx).value().to_string();
|
||||
let subject = (!subject.trim().is_empty()).then_some(subject);
|
||||
|
||||
self.state.update(cx, |state, _| state.begin());
|
||||
self.store.update(cx, |store, cx| {
|
||||
store.open_issue(subject, content, cx);
|
||||
});
|
||||
@@ -48,6 +58,7 @@ impl Render for NewIssueDialog {
|
||||
let subject = self.subject.clone();
|
||||
let content = self.content.clone();
|
||||
let this = cx.entity().downgrade();
|
||||
let action_state = self.state.clone();
|
||||
|
||||
Dialog::new("new-issue-dialog")
|
||||
.handle(self.handle.clone())
|
||||
@@ -72,11 +83,14 @@ impl Render for NewIssueDialog {
|
||||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
.actions(move |_, cx| {
|
||||
let this = this.clone();
|
||||
let busy = action_state.read(cx).busy;
|
||||
vec![
|
||||
Button::new("create-issue")
|
||||
.label("Create issue")
|
||||
.loading(busy)
|
||||
.disabled(busy)
|
||||
.on_click(move |_, _, cx| {
|
||||
crate::shared::log_dropped(this.update(cx, |this, cx| this.submit(cx)));
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user