chore: move new issue/pull form into a split panel
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-25 10:01:11 +07:00
parent e54364b716
commit f305c56e9e
18 changed files with 576 additions and 451 deletions
+78 -38
View File
@@ -10,20 +10,19 @@ use nostr::prelude::PublicKey;
use signed_core::GitEvent;
use signed_state::RepoStore;
use ui::button::Button;
use ui::common::v_flex;
use ui::common::{Sizable, h_flex, v_flex};
use ui::icons::{Icon, IconRole};
use ui::layout::panel::Panel;
use ui::layout::root::RootContext as _;
use ui::layout::panel::{Panel, PanelSlot};
use ui::segmented::{Segmented, SegmentedOption};
use ui::theme::ActiveTheme as _;
use utils::relative_time;
use self::detail::IssueDetailView;
use crate::app::AppRoot;
use crate::issues::new_issue::NewIssueDialog;
use crate::issues::new_issue::NewIssueView;
use crate::repo::helpers::short_id;
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
use crate::shared::{log_dropped, panels};
use crate::shared::event_list::{EventHandler, EventList, EventRow};
use crate::shared::log_dropped;
pub mod detail;
pub(crate) mod helpers;
@@ -73,9 +72,36 @@ impl IssuesView {
}
}
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
let dialog = NewIssueDialog::new(self.store.clone(), cx);
cx.open_dialog(dialog);
fn open_new_issue(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("new-issue:{addr}"));
let workspace = self.workspace.clone();
let workspace_for_build = workspace.clone();
let store = self.store.clone();
log_dropped(workspace.update(cx, |root, cx| {
root.panels().clone().update(cx, |panels, cx| {
panels.open(
PanelSlot::Split,
id.clone(),
move |_, cx| {
cx.new(|cx| {
NewIssueView::new(
workspace_for_build.clone(),
id.clone(),
store.clone(),
cx,
)
})
},
window,
cx,
)
})
}));
}
/// Total number of issues across all statuses, for the sidebar label.
@@ -127,23 +153,30 @@ impl IssuesView {
fn render_header(&self, cx: &mut Context<Self>) -> AnyElement {
let counts = self.counts;
let muted = cx.theme().colors.muted_foreground;
let colors = cx.theme().colors;
let muted = colors.muted_foreground;
let weak = cx.entity().downgrade();
filter_toolbar(
cx,
[
h_flex()
.px_2()
.h_12()
.w_full()
.gap_3()
.border_b_1()
.border_color(colors.border)
.bg(colors.muted)
.child(
Segmented::new("issue-filter", self.filter)
.options(vec![
SegmentedOption::new(IssueFilter::All, format!("All ({})", counts.total))
SegmentedOption::new(IssueFilter::All)
.label(format!("All ({})", counts.total))
.icon(Icon::named(IconRole::GitIssueDone).color(muted)),
SegmentedOption::new(IssueFilter::Open, format!("Open ({})", counts.open))
SegmentedOption::new(IssueFilter::Open)
.label(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)),
SegmentedOption::new(IssueFilter::Closed)
.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| {
@@ -152,18 +185,19 @@ impl IssuesView {
}) {
log::warn!("failed to switch issue filter: {error}");
}
})
.into_any_element(),
div().flex_1().into_any_element(),
}),
)
.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(),
],
)
.small()
.on_click(cx.listener(|this, _, window, cx| {
this.open_new_issue(window, cx);
})),
)
.into_any_element()
}
}
@@ -197,15 +231,21 @@ impl Render for IssuesView {
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,
);
log_dropped(workspace.update(cx, |root, cx| {
root.panels().clone().update(cx, |panels, cx| {
panels.open(
PanelSlot::Split,
id,
move |_, cx| {
cx.new(|cx| {
IssueDetailView::new(store.clone(), issue_id, cx)
})
},
window,
cx,
)
})
}));
})
};
+100 -55
View File
@@ -1,70 +1,132 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
Styled as _, Window, div,
AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
Render, SharedString, Styled as _, Task, WeakEntity, Window, div,
};
use signed_state::RepoStore;
use ui::common::v_flex;
use ui::dialog::{Dialog, DialogHandle};
use ui::button::Button;
use ui::common::{h_flex, v_flex};
use ui::field::Field;
use ui::input::{Input, InputState};
use ui::layout::panel::{Panel, PanelSlot};
use ui::theme::ActiveTheme as _;
use crate::shared::progress::{DialogProgress, dialog_submit_button};
use crate::app::AppRoot;
use crate::shared::log_dropped;
use crate::shared::progress::error_row;
pub struct NewIssueDialog {
handle: DialogHandle,
pub struct NewIssueView {
workspace: WeakEntity<AppRoot>,
panel_id: SharedString,
store: Entity<RepoStore>,
subject: Entity<InputState>,
content: Entity<InputState>,
state: Entity<DialogProgress>,
submitting: bool,
error: Option<SharedString>,
/// The running publish, cancelled when the view closes.
submit_task: Option<Task<()>>,
}
impl NewIssueDialog {
pub fn new(store: Entity<RepoStore>, cx: &mut App) -> Entity<Self> {
impl NewIssueView {
pub fn new(
workspace: WeakEntity<AppRoot>,
panel_id: SharedString,
store: Entity<RepoStore>,
cx: &mut Context<Self>,
) -> 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),
Self {
workspace,
panel_id,
store,
subject,
content,
state,
})
submitting: false,
error: None,
submit_task: None,
}
}
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 {
if self.submitting {
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);
});
self.submitting = true;
self.error = None;
cx.notify();
self.handle.close(cx);
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| {
root.panels().clone().update(cx, |panels, cx| {
panels.close(PanelSlot::Split, &panel_id, cx)
})
}));
}
Err(error) => {
log_dropped(this.update(cx, |this, cx| {
this.submitting = false;
this.error = Some(error.to_string().into());
cx.notify();
}));
}
}));
}
fn render_footer(&self, cx: &Context<Self>) -> AnyElement {
let weak = cx.entity().downgrade();
h_flex()
.px_4()
.py_2()
.w_full()
.justify_end()
.border_t_1()
.border_color(cx.theme().colors.border)
.child(
Button::new("create-issue")
.label("Create issue")
.loading(self.submitting)
.disabled(self.submitting)
.on_click(move |_, _, cx| {
log_dropped(weak.update(cx, |this, cx| this.submit(cx)));
}),
)
.into_any_element()
}
}
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();
let action_state = self.state.clone();
impl Panel for NewIssueView {
fn title(&self, _cx: &App) -> SharedString {
SharedString::from("New issue")
}
Dialog::new("new-issue-dialog")
.handle(self.handle.clone())
.min_width(gpui::px(520.))
.title("New issue")
.content(move |_, cx| {
fn loading(&self, _cx: &App) -> bool {
self.submitting
}
}
impl Render for NewIssueView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.id("new-issue")
.size_full()
.child(
v_flex()
.p_4()
.flex_1()
.gap_3()
.child(
div()
@@ -74,31 +136,14 @@ impl Render for NewIssueDialog {
)
.child(
Field::new("issue-title", "Title")
.child(Input::new("issue-title-input", subject.clone())),
.child(Input::new("issue-title-input", self.subject.clone())),
)
.child(
Field::new("issue-content", "Content")
.child(Input::new("issue-content-input", content.clone()).rows(6)),
.child(Input::new("issue-content-input", self.content.clone()).rows(6)),
)
.into_any_element()
})
.actions(move |_, cx| {
let this = this.clone();
let busy = action_state.read(cx).busy;
vec![
dialog_submit_button(
"create-issue",
"Create issue",
None,
busy,
&this,
|this, _window, cx| {
this.submit(cx);
Ok(())
},
)
.into_any_element() as AnyElement,
]
})
.when_some(error_row(&self.error, cx), |this, error| this.child(error)),
)
.child(self.render_footer(cx))
}
}