update ui

This commit is contained in:
2026-09-02 13:51:45 +07:00
parent 15224277bc
commit c03ce50c82
@@ -15,7 +15,7 @@ use gpui::{
Pixels, Render, SharedString, Size, Subscription, Task, WeakEntity, Window, div, px, relative, Pixels, Render, SharedString, Size, Subscription, Task, WeakEntity, Window, div, px, relative,
size, size,
}; };
use gpui_base::Button as BaseButton; use gpui_base::{Button as BaseButton, StyledExt};
use gpui_component::button::{Button, ButtonVariants}; use gpui_component::button::{Button, ButtonVariants};
use gpui_component::combobox::{ use gpui_component::combobox::{
Caret, Combobox, ComboboxEvent, ComboboxState, ComboboxTriggerContext, Caret, Combobox, ComboboxEvent, ComboboxState, ComboboxTriggerContext,
@@ -97,10 +97,9 @@ impl NewPullRequestView {
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
let subject = cx.new(|cx| InputState::new(window, cx).placeholder("Pull request title"));
let description = cx
.new(|cx| TextareaState::new(window, cx).placeholder("Describe the change (optional)"));
let pane = cx.new(DiffPane::new); let pane = cx.new(DiffPane::new);
let subject = cx.new(|cx| InputState::new(window, cx).placeholder("Title"));
let description = cx.new(|cx| TextareaState::new(window, cx).placeholder("Describe..."));
let base_select: Entity<ComboboxState<SearchableVec<SharedString>>> = cx.new(|cx| { let base_select: Entity<ComboboxState<SearchableVec<SharedString>>> = cx.new(|cx| {
ComboboxState::new( ComboboxState::new(
@@ -111,6 +110,7 @@ impl NewPullRequestView {
) )
.searchable(true) .searchable(true)
}); });
let compare_select: Entity<ComboboxState<SearchableVec<SharedString>>> = cx.new(|cx| { let compare_select: Entity<ComboboxState<SearchableVec<SharedString>>> = cx.new(|cx| {
ComboboxState::new( ComboboxState::new(
SearchableVec::new(Vec::<SharedString>::new()), SearchableVec::new(Vec::<SharedString>::new()),
@@ -181,8 +181,6 @@ impl NewPullRequestView {
/// (defaults: the announced HEAD branch for the base, the checkout's /// (defaults: the announced HEAD branch for the base, the checkout's
/// current branch for the compare) and load the compare. /// current branch for the compare) and load the compare.
fn choose_checkout(&mut self, window: &mut Window, cx: &mut Context<Self>) { fn choose_checkout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let handle = window.window_handle();
let prompt = cx.prompt_for_paths(PathPromptOptions { let prompt = cx.prompt_for_paths(PathPromptOptions {
files: false, files: false,
directories: true, directories: true,
@@ -190,15 +188,21 @@ impl NewPullRequestView {
prompt: Some("Choose local checkout".into()), prompt: Some("Choose local checkout".into()),
}); });
let task = cx.spawn(async move |this, cx| { let task = cx.spawn_in(window, async move |this, cx| {
if let Ok(Ok(Some(mut paths))) = prompt.await // `Ok(Ok(Some(paths)))` means the user picked a folder; a
&& let Some(path) = paths.pop() // cancel (or a picker failure) resolves to anything else.
{ let picked = match prompt.await {
Ok(Ok(Some(mut paths))) => paths.pop(),
_ => None,
};
let Some(path) = picked else {
return Ok(());
};
let path = path.to_string_lossy().to_string(); let path = path.to_string_lossy().to_string();
// Branches and the current branch are read off the UI thread. // Branches and the current branch are read off the UI thread.
let info = cx let info = cx
.background_executor() .background_spawn({
.spawn({
let path = path.clone(); let path = path.clone();
async move { async move {
let repo = gix::open(Path::new(&path)).ok()?; let repo = gix::open(Path::new(&path)).ok()?;
@@ -210,12 +214,10 @@ impl NewPullRequestView {
}) })
.await; .await;
let _ = handle.update(cx, |_, window, cx| { this.update_in(cx, |this, window, cx| {
let _ = this.update(cx, |this, cx| {
this.apply_checkout(path, info, window, cx); this.apply_checkout(path, info, window, cx);
}); })?;
});
}
Ok(()) Ok(())
}); });
self.tasks.push(task); self.tasks.push(task);
@@ -496,15 +498,19 @@ impl NewPullRequestView {
h_flex() h_flex()
.px_4() .px_4()
.h_12() .h_16()
.w_full() .w_full()
.gap_2() .gap_2()
.items_center() .items_end()
.child(
v_flex()
.gap_1()
.child( .child(
div() div()
.text_xs() .text_xs()
.font_semibold()
.text_color(cx.theme().muted_foreground) .text_color(cx.theme().muted_foreground)
.child("base"), .child("Merge Into"),
) )
.child( .child(
div().w(px(140.)).child( div().w(px(140.)).child(
@@ -519,17 +525,17 @@ impl NewPullRequestView {
render_ref_trigger(ctx, CustomIconName::GitBranch, cx) render_ref_trigger(ctx, CustomIconName::GitBranch, cx)
}), }),
), ),
),
) )
.child( .child(
Icon::new(IconName::ArrowRight) v_flex()
.small() .gap_1()
.text_color(cx.theme().muted_foreground),
)
.child( .child(
div() div()
.text_xs() .text_xs()
.font_semibold()
.text_color(cx.theme().muted_foreground) .text_color(cx.theme().muted_foreground)
.child("compare"), .child("Pull From"),
) )
.child( .child(
div().w(px(140.)).child( div().w(px(140.)).child(
@@ -544,6 +550,7 @@ impl NewPullRequestView {
render_ref_trigger(ctx, CustomIconName::GitBranch, cx) render_ref_trigger(ctx, CustomIconName::GitBranch, cx)
}), }),
), ),
),
) )
.child( .child(
Button::new("choose-checkout") Button::new("choose-checkout")
@@ -561,7 +568,7 @@ impl NewPullRequestView {
.child( .child(
Button::new("create-pr") Button::new("create-pr")
.primary() .primary()
.label("Create pull request") .icon(IconName::Plus)
.loading(self.submitting) .loading(self.submitting)
.disabled(!can_submit) .disabled(!can_submit)
.on_click(cx.listener(|this, _event, window, cx| { .on_click(cx.listener(|this, _event, window, cx| {
@@ -575,11 +582,10 @@ impl NewPullRequestView {
fn render_inputs(&self, _cx: &mut Context<Self>) -> AnyElement { fn render_inputs(&self, _cx: &mut Context<Self>) -> AnyElement {
v_flex() v_flex()
.px_4() .px_4()
.py_2()
.w_full() .w_full()
.gap_2() .gap_2()
.child(Input::new(&self.subject)) .child(Input::new(&self.subject))
.child(Textarea::new(&self.description).h_32()) .child(Textarea::new(&self.description).h_24())
.into_any_element() .into_any_element()
} }
@@ -590,7 +596,7 @@ impl NewPullRequestView {
h_flex() h_flex()
.px_4() .px_4()
.h_9() .pb_4()
.w_full() .w_full()
.gap_2() .gap_2()
.items_center() .items_center()
@@ -834,6 +840,9 @@ impl Render for NewPullRequestView {
v_flex() v_flex()
.id("new-pr") .id("new-pr")
.size_full() .size_full()
.child(
v_flex()
.gap_4()
.child(self.render_compare_bar(cx)) .child(self.render_compare_bar(cx))
.child(self.render_inputs(cx)) .child(self.render_inputs(cx))
.when_some(self.error.clone(), |this, error| { .when_some(self.error.clone(), |this, error| {
@@ -847,7 +856,8 @@ impl Render for NewPullRequestView {
.child(error), .child(error),
) )
}) })
.child(self.render_tabs(cx)) .child(self.render_tabs(cx)),
)
.child( .child(
v_flex() v_flex()
.flex_1() .flex_1()