new layout (wip) (#34)
Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
use gpui::{
|
||||
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
||||
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{EventId, PublicKey};
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::input::InputState;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::scroll_area::ScrollArea;
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use utils::relative_time;
|
||||
|
||||
use crate::issues::helpers::{comment_form, comments_section, issue_roots, sidebar_section};
|
||||
use crate::shared::widgets::status_badge;
|
||||
|
||||
pub struct IssueDetailView {
|
||||
store: Entity<RepoStore>,
|
||||
issue_id: EventId,
|
||||
comment_input: Entity<InputState>,
|
||||
/// Profiles for the author, commenters and the repository owner.
|
||||
directory: Entity<ProfileDirectory>,
|
||||
scroll_handle: ScrollHandle,
|
||||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
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 subscription = cx.observe(&store, |this, _store, cx| {
|
||||
this.track_participants(cx);
|
||||
cx.notify();
|
||||
});
|
||||
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
let weak = cx.entity().downgrade();
|
||||
cx.defer(move |cx| {
|
||||
crate::shared::log_dropped(weak.update(cx, |this, cx| this.track_participants(cx)));
|
||||
});
|
||||
|
||||
Self {
|
||||
store,
|
||||
issue_id,
|
||||
comment_input,
|
||||
directory,
|
||||
scroll_handle: ScrollHandle::new(),
|
||||
_subscription: subscription,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
.issues
|
||||
.iter()
|
||||
.find(|issue| issue.id == self.issue_id)
|
||||
.map(|issue| issue.pubkey)
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
keys.extend(
|
||||
store
|
||||
.comments_of(&self.issue_id)
|
||||
.map(|comment| comment.pubkey),
|
||||
);
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for IssueDetailView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
let hex = self.issue_id.to_hex();
|
||||
let short = hex.get(..8).unwrap_or(&hex);
|
||||
SharedString::from(format!("Issue {short}"))
|
||||
}
|
||||
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
!self.store.read(cx).loaded
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for IssueDetailView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
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"
|
||||
} else {
|
||||
"Loading issue..."
|
||||
};
|
||||
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) = {
|
||||
let profile = self.directory.read(cx).profile(&issue.pubkey, cx);
|
||||
let content = if issue.content.is_empty() {
|
||||
SharedString::from("No description provided.")
|
||||
} else {
|
||||
SharedString::from(&issue.content)
|
||||
};
|
||||
|
||||
(
|
||||
issue.activity_subject(),
|
||||
profile.name(),
|
||||
store.status_of(issue),
|
||||
relative_time(issue.created_at),
|
||||
issue.id,
|
||||
content,
|
||||
issue.pubkey,
|
||||
)
|
||||
};
|
||||
let picture = self.directory.read(cx).profile(&pubkey, cx).picture();
|
||||
|
||||
h_flex()
|
||||
.id("issue-detail")
|
||||
.size_full()
|
||||
.child(
|
||||
ScrollArea::new("issue-detail-scroll")
|
||||
.handle(self.scroll_handle.clone())
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.child(
|
||||
v_flex()
|
||||
.p_4()
|
||||
.gap_6()
|
||||
.child(
|
||||
h_flex().gap_2().child(status_badge(status)).child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.typeset(TextRole::Headline, cx)
|
||||
.child(title),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_8()
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Avatar::new(pubkey)
|
||||
.name(author.clone())
|
||||
.picture(picture)
|
||||
.small(),
|
||||
)
|
||||
.child(author),
|
||||
)
|
||||
.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(
|
||||
div().typeset(TextRole::Body, cx).child(content),
|
||||
),
|
||||
)
|
||||
.child(comments_section(
|
||||
&self.store,
|
||||
issue_id,
|
||||
&self.directory,
|
||||
cx,
|
||||
))
|
||||
.child(comment_form(
|
||||
&self.store,
|
||||
issue_id,
|
||||
issue_roots,
|
||||
&self.comment_input,
|
||||
"comment",
|
||||
cx,
|
||||
)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(sidebar_section(
|
||||
&self.store,
|
||||
issue_id,
|
||||
issue_roots,
|
||||
true,
|
||||
&self.directory,
|
||||
cx,
|
||||
))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, Entity, IntoElement, ParentElement as _, SharedString, Styled as _, div, px,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::{Event, EventId, PublicKey};
|
||||
use signed_core::RepoStatus;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::badge::{Badge, BadgeVariant};
|
||||
use ui::button::Button;
|
||||
use ui::common::{Sizable as _, h_flex, v_flex};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use ui::tooltip::Tooltip;
|
||||
use utils::relative_time;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum IssueFilter {
|
||||
All,
|
||||
Open,
|
||||
Closed,
|
||||
}
|
||||
|
||||
impl IssueFilter {
|
||||
pub(crate) fn matches(self, status: RepoStatus) -> bool {
|
||||
match self {
|
||||
Self::All => true,
|
||||
Self::Open => status == RepoStatus::Open,
|
||||
Self::Closed => matches!(status, RepoStatus::Closed | RepoStatus::Applied),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 issue_roots(store: &RepoStore) -> &[Event] {
|
||||
&store.issues
|
||||
}
|
||||
|
||||
pub(crate) fn pr_roots(store: &RepoStore) -> &[Event] {
|
||||
&store.pull_requests
|
||||
}
|
||||
|
||||
pub(crate) fn sidebar_section(
|
||||
store: &Entity<RepoStore>,
|
||||
id: EventId,
|
||||
roots: fn(&RepoStore) -> &[Event],
|
||||
top_gap: bool,
|
||||
directory: &Entity<ProfileDirectory>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let store = store.read(cx);
|
||||
let Some(root) = roots(store).iter().find(|event| event.id == id) else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
|
||||
let mut participants: Vec<PublicKey> = vec![root.pubkey];
|
||||
participants.extend(store.comments_of(&root.id).map(|comment| comment.pubkey));
|
||||
participants.sort_by_key(PublicKey::to_hex);
|
||||
participants.dedup();
|
||||
|
||||
let labels: Vec<String> = root.tags.hashtags().map(|tag| tag.to_string()).collect();
|
||||
|
||||
v_flex()
|
||||
.w(px(240.))
|
||||
.h_full()
|
||||
.flex_none()
|
||||
.px_4()
|
||||
.gap_4()
|
||||
.border_l_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.child(
|
||||
v_flex()
|
||||
.when(top_gap, |this| this.mt_4())
|
||||
.gap_2()
|
||||
.child(crate::shared::widgets::section_label("Participants", cx))
|
||||
.children(participants.iter().map(|pubkey| {
|
||||
let profile = 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()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.text_ellipsis()
|
||||
.child(name),
|
||||
)
|
||||
.into_any_element()
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.child(crate::shared::widgets::section_label("Labels", cx))
|
||||
.map(|this| {
|
||||
if labels.is_empty() {
|
||||
this.child(
|
||||
div()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child("None yet."),
|
||||
)
|
||||
} else {
|
||||
this.child(v_flex().gap_1().children(labels.iter().map(|label| {
|
||||
Badge::new(SharedString::from(format!("label:{label}")), label.clone())
|
||||
.variant(BadgeVariant::Outline)
|
||||
})))
|
||||
}
|
||||
}),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
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 title = SharedString::from(format!("Discussions {}", comments.len()));
|
||||
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(div().typeset(TextRole::Caption2, cx).child(title))
|
||||
.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()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.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().typeset(TextRole::Body, cx).child(content))
|
||||
}))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
pub(crate) fn comment_form(
|
||||
store: &Entity<RepoStore>,
|
||||
root: EventId,
|
||||
roots: fn(&RepoStore) -> &[Event],
|
||||
comment_input: &Entity<InputState>,
|
||||
button_id: &'static str,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let comment_input = comment_input.clone();
|
||||
let store = store.clone();
|
||||
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.child(
|
||||
Input::new("comment-input", comment_input.clone())
|
||||
.rows(4)
|
||||
.placeholder("Leave a comment..."),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.justify_between()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.typeset(TextRole::Caption, cx)
|
||||
.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;
|
||||
}
|
||||
let Some(root) = roots(store.read(cx))
|
||||
.iter()
|
||||
.find(|event| event.id == root)
|
||||
.cloned()
|
||||
else {
|
||||
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()
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
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,
|
||||
};
|
||||
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::icons::{Icon, IconRole};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use utils::relative_time;
|
||||
|
||||
use self::detail::IssueDetailView;
|
||||
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>,
|
||||
new_issue: Option<Entity<new_issue::NewIssueDialog>>,
|
||||
filter: IssueFilter,
|
||||
visible_issues: Vec<usize>,
|
||||
counts: StatusCounts,
|
||||
// A filter change notifies even when the visible rows are unchanged.
|
||||
synced_filter: IssueFilter,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
/// Profiles for issue authors and the repository owner.
|
||||
directory: Entity<ProfileDirectory>,
|
||||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
impl IssuesView {
|
||||
pub fn new(
|
||||
workspace: WeakEntity<Workspace>,
|
||||
store: Entity<RepoStore>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||
this.rebuild(cx);
|
||||
});
|
||||
let weak = cx.entity().downgrade();
|
||||
cx.defer(move |cx| {
|
||||
crate::shared::log_dropped(weak.update(cx, |this, cx| this.rebuild(cx)));
|
||||
});
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
store: store.clone(),
|
||||
new_issue: None,
|
||||
filter: IssueFilter::Open,
|
||||
visible_issues: Vec::new(),
|
||||
counts: StatusCounts::default(),
|
||||
synced_filter: IssueFilter::Open,
|
||||
scroll_handle: UniformListScrollHandle::new(),
|
||||
directory: ProfileDirectory::new(cx),
|
||||
_subscription: subscription,
|
||||
}
|
||||
}
|
||||
|
||||
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
|
||||
self.new_issue = Some(new_issue::NewIssueDialog::new(self.store.clone(), cx));
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Total number of issues across all statuses, for the sidebar label.
|
||||
pub fn total_count(&self) -> usize {
|
||||
self.counts.total
|
||||
}
|
||||
|
||||
fn rebuild(&mut self, cx: &mut Context<Self>) {
|
||||
let filter = self.filter;
|
||||
|
||||
let (visible_issues, counts) = {
|
||||
let store = self.store.read(cx);
|
||||
filter_by_status(
|
||||
&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();
|
||||
|
||||
if let Some(owner) = store
|
||||
.announcement
|
||||
.as_ref()
|
||||
.map(|announcement| announcement.owner)
|
||||
{
|
||||
keys.push(owner);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if !filter_changed && !visible_issues_changed && !counts_changed {
|
||||
return;
|
||||
}
|
||||
|
||||
self.synced_filter = filter;
|
||||
self.visible_issues = visible_issues;
|
||||
self.counts = counts;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
let counts = self.counts;
|
||||
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(
|
||||
Segmented::new("issue-filter", self.filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(IssueFilter::All, format!("All ({})", counts.total))
|
||||
.icon(Icon::named(IconRole::GitIssueDone).color(muted)),
|
||||
SegmentedOption::new(IssueFilter::Open, format!("Open ({})", counts.open))
|
||||
.icon(Icon::named(IconRole::GitIssueOngoing).color(muted)),
|
||||
SegmentedOption::new(
|
||||
IssueFilter::Closed,
|
||||
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}");
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(div().flex_1())
|
||||
.child(
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for IssuesView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Issues")
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.text_ellipsis()
|
||||
.whitespace_nowrap()
|
||||
.child(title),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.typeset(TextRole::Caption, cx)
|
||||
.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)),
|
||||
)
|
||||
}),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
Styled as _, Window, div,
|
||||
};
|
||||
use signed_state::RepoStore;
|
||||
use ui::button::Button;
|
||||
use ui::common::v_flex;
|
||||
use ui::dialog::{Dialog, DialogHandle};
|
||||
use ui::field::Field;
|
||||
use ui::input::{Input, InputState};
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
|
||||
pub struct NewIssueDialog {
|
||||
handle: DialogHandle,
|
||||
store: Entity<RepoStore>,
|
||||
subject: Entity<InputState>,
|
||||
content: Entity<InputState>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
cx.new(|_| Self {
|
||||
handle: DialogHandle::new(true),
|
||||
store,
|
||||
subject,
|
||||
content,
|
||||
})
|
||||
}
|
||||
|
||||
fn submit(&mut self, cx: &mut Context<Self>) {
|
||||
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.store.update(cx, |store, cx| {
|
||||
store.open_issue(subject, content, cx);
|
||||
});
|
||||
|
||||
self.handle.close(cx);
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for NewIssueDialog {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let subject = self.subject.clone();
|
||||
let content = self.content.clone();
|
||||
let this = cx.entity().downgrade();
|
||||
|
||||
Dialog::new("new-issue-dialog")
|
||||
.handle(self.handle.clone())
|
||||
.min_width(gpui::px(520.))
|
||||
.title("New issue")
|
||||
.content(move |_, cx| {
|
||||
v_flex()
|
||||
.gap_3()
|
||||
.child(
|
||||
div()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child("Report a bug, ask a question, or propose a change."),
|
||||
)
|
||||
.child(
|
||||
Field::new("issue-title", "Title")
|
||||
.child(Input::new("issue-title-input", subject.clone())),
|
||||
)
|
||||
.child(
|
||||
Field::new("issue-content", "Content")
|
||||
.child(Input::new("issue-content-input", content.clone()).rows(6)),
|
||||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.actions(move |_, _| {
|
||||
let this = this.clone();
|
||||
vec![
|
||||
Button::new("create-issue")
|
||||
.label("Create issue")
|
||||
.on_click(move |_, _, cx| {
|
||||
crate::shared::log_dropped(this.update(cx, |this, cx| this.submit(cx)));
|
||||
})
|
||||
.into_any_element() as AnyElement,
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user