chore: refactor issue detail into a split panel
This commit is contained in:
@@ -1,24 +1,34 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
||||
ScrollHandle, SharedString, Styled as _, Subscription, Window, div,
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Pixels, Render, ScrollHandle, SharedString, Styled as _, Subscription,
|
||||
WeakEntity, Window, div, px,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::EventId;
|
||||
use signed_core::GitEvent;
|
||||
use signed_state::RepoStore;
|
||||
use ui::avatar::Avatar;
|
||||
use ui::badge::{Badge, BadgeVariant};
|
||||
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::layout::panel::{Panel, PanelSlot, SplitSide};
|
||||
use ui::scroll_area::ScrollArea;
|
||||
use ui::spinner::Spinner;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
||||
use crate::shared::log_dropped;
|
||||
use crate::app::AppRoot;
|
||||
use crate::issues::helpers::{comment_form, comments_section};
|
||||
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";
|
||||
const SIDEBAR_WIDTH: Pixels = px(240.);
|
||||
|
||||
pub struct IssueDetailView {
|
||||
store: Entity<RepoStore>,
|
||||
@@ -31,6 +41,48 @@ pub struct IssueDetailView {
|
||||
}
|
||||
|
||||
impl IssueDetailView {
|
||||
/// Opens the issue's detail as the main panel and its sidebar in the split pane.
|
||||
pub fn open(
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
store: Entity<RepoStore>,
|
||||
issue_id: EventId,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
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,
|
||||
);
|
||||
|
||||
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,
|
||||
);
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -60,31 +112,54 @@ 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 owner = store.announcement.as_ref().map(|a| a.owner);
|
||||
|
||||
let author = store
|
||||
.issues
|
||||
.iter()
|
||||
.find(|issue| issue.id == self.issue_id)
|
||||
.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();
|
||||
crate::shared::track_event_participants(
|
||||
author,
|
||||
owner,
|
||||
comments.into_iter(),
|
||||
&self.directory,
|
||||
cx,
|
||||
);
|
||||
|
||||
track_event_participants(author, owner, comments.into_iter(), &self.directory, 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 title(&self, cx: &App) -> SharedString {
|
||||
let subject = self
|
||||
.store
|
||||
.read(cx)
|
||||
.issues
|
||||
.iter()
|
||||
.find(|issue| issue.id == self.issue_id)
|
||||
.map(|issue| issue.activity_subject());
|
||||
|
||||
match subject {
|
||||
Some(subject) => SharedString::from(format!("issue: {subject}")),
|
||||
None => {
|
||||
let hex = self.issue_id.to_hex();
|
||||
let short = hex.get(..8).unwrap_or(&hex);
|
||||
SharedString::from(format!("issue: {short}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
let owner = self.store.read(cx).announcement.as_ref().map(|a| a.owner)?;
|
||||
let profile = self.directory.read(cx).profile(&owner, cx);
|
||||
|
||||
Some(
|
||||
Avatar::new(owner)
|
||||
.name(profile.name())
|
||||
.picture(profile.picture())
|
||||
.small()
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
@@ -112,7 +187,6 @@ impl Render for IssueDetailView {
|
||||
} else {
|
||||
SharedString::from(&issue.content)
|
||||
};
|
||||
|
||||
(
|
||||
issue.activity_subject(),
|
||||
profile.name(),
|
||||
@@ -125,27 +199,22 @@ impl Render for IssueDetailView {
|
||||
};
|
||||
let picture = self.directory.read(cx).profile(&pubkey, cx).picture();
|
||||
|
||||
h_flex()
|
||||
div()
|
||||
.id("issue-detail")
|
||||
.size_full()
|
||||
.child(
|
||||
ScrollArea::new("issue-detail-scroll")
|
||||
.handle(self.scroll_handle.clone())
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.size_full()
|
||||
.child(
|
||||
v_flex()
|
||||
.p_4()
|
||||
.gap_6()
|
||||
.child(
|
||||
h_flex().gap_2().child(status_badge(status)).child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.text_sm()
|
||||
.font_semibold()
|
||||
.child(title),
|
||||
),
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(status_badge(status))
|
||||
.child(div().flex_1().min_w_0().font_semibold().child(title)),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
@@ -156,7 +225,7 @@ impl Render for IssueDetailView {
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.text_base()
|
||||
.text_sm()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
@@ -183,7 +252,7 @@ impl Render for IssueDetailView {
|
||||
.child(SharedString::from(age)),
|
||||
),
|
||||
)
|
||||
.child(div().text_base().child(content)),
|
||||
.child(content),
|
||||
)
|
||||
.child(comments_section(
|
||||
&self.store,
|
||||
@@ -202,14 +271,116 @@ impl Render for IssueDetailView {
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(sidebar_section(
|
||||
&self.store,
|
||||
issue_id,
|
||||
&store.issues,
|
||||
true,
|
||||
&self.directory,
|
||||
cx,
|
||||
))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
/// The issue's participant and label sidebar, shown in the split pane.
|
||||
struct IssueSidebarView {
|
||||
store: Entity<RepoStore>,
|
||||
issue_id: EventId,
|
||||
directory: Entity<ProfileDirectory>,
|
||||
scroll_handle: ScrollHandle,
|
||||
}
|
||||
|
||||
impl Panel for IssueSidebarView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from(SIDEBAR_ID)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for IssueSidebarView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let store = self.store.read(cx);
|
||||
|
||||
let details = store
|
||||
.issues
|
||||
.iter()
|
||||
.find(|issue| issue.id == self.issue_id)
|
||||
.map(|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.dedup();
|
||||
|
||||
let labels: Vec<String> = root.tags.hashtags().map(|tag| tag.to_string()).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();
|
||||
|
||||
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() {
|
||||
this.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child("None yet."),
|
||||
)
|
||||
} else {
|
||||
this.child(v_flex().gap_1().items_start().children(
|
||||
labels.iter().map(|label| {
|
||||
Badge::new(
|
||||
SharedString::from(format!("label:{label}")),
|
||||
label.clone(),
|
||||
)
|
||||
.variant(BadgeVariant::Outline)
|
||||
.small()
|
||||
.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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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 nostr::prelude::{Event, EventId};
|
||||
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 _, StyledExt as _, h_flex, v_flex};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
@@ -76,98 +74,6 @@ pub(crate) fn filter_by_status<'a>(
|
||||
(visible, counts)
|
||||
}
|
||||
|
||||
pub(crate) fn sidebar_section(
|
||||
store: &Entity<RepoStore>,
|
||||
id: EventId,
|
||||
roots: &[Event],
|
||||
top_gap: bool,
|
||||
directory: &Entity<ProfileDirectory>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let store = store.read(cx);
|
||||
let Some(root) = roots.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(
|
||||
div()
|
||||
.text_xs()
|
||||
.font_medium()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child("Participants"),
|
||||
)
|
||||
.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()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.text_base()
|
||||
.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() {
|
||||
this.child(
|
||||
div()
|
||||
.text_base()
|
||||
.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,
|
||||
@@ -180,7 +86,7 @@ pub(crate) fn comments_section(
|
||||
|
||||
v_flex()
|
||||
.gap_4()
|
||||
.child(div().text_xs().font_medium().child(title))
|
||||
.child(div().text_xs().font_semibold().child(title))
|
||||
.children(comments.iter().map(|comment| {
|
||||
let profile = directory.read(cx).profile(&comment.pubkey, cx);
|
||||
let author = profile.name();
|
||||
@@ -196,7 +102,7 @@ pub(crate) fn comments_section(
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.text_base()
|
||||
.text_sm()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
@@ -219,7 +125,7 @@ pub(crate) fn comments_section(
|
||||
.child(SharedString::from(age)),
|
||||
),
|
||||
)
|
||||
.child(div().text_base().child(content))
|
||||
.child(div().text_sm().child(content))
|
||||
}))
|
||||
.into_any_element()
|
||||
}
|
||||
@@ -242,8 +148,8 @@ pub(crate) fn comment_form(
|
||||
.gap_2()
|
||||
.child(
|
||||
Input::new("comment-input", comment_input.clone())
|
||||
.rows(4)
|
||||
.placeholder("Leave a comment..."),
|
||||
.placeholder("Leave a comment...")
|
||||
.rows(4),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
|
||||
@@ -264,38 +264,20 @@ impl Render for IssuesView {
|
||||
.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();
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(
|
||||
cx,
|
||||
|panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
id,
|
||||
move |_, cx| {
|
||||
cx.new(|cx| {
|
||||
IssueDetailView::new(
|
||||
store.clone(),
|
||||
issue_id,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
},
|
||||
)
|
||||
}));
|
||||
IssueDetailView::open(
|
||||
&workspace,
|
||||
store.clone(),
|
||||
issue_id,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.items_start()
|
||||
.gap_2()
|
||||
.child(h_flex().w_24().child(status_badge(status)))
|
||||
.child(h_flex().w_20().child(status_badge(status)))
|
||||
.child(
|
||||
v_flex()
|
||||
.flex_1()
|
||||
|
||||
@@ -135,7 +135,7 @@ impl Render for NewIssueView {
|
||||
.child(
|
||||
div()
|
||||
.pr_16()
|
||||
.text_base()
|
||||
.text_sm()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child("Report a bug, ask a question, or propose a change."),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user