feat: impl pull request file tree
This commit is contained in:
@@ -7,7 +7,8 @@ use crate::{
|
||||
text::text,
|
||||
},
|
||||
query::{self, QueryStatus, read_query, use_query, watch_query},
|
||||
util,
|
||||
screen::dashboard::pull_request_file_tree::{self, PullRequestFileTree},
|
||||
util::{self},
|
||||
};
|
||||
use gpui::{AppContext, ParentElement, Styled, div};
|
||||
|
||||
@@ -20,6 +21,8 @@ pub(crate) struct PullRequestDiffView {
|
||||
|
||||
diff_view_state: DiffViewState,
|
||||
diff_view_content: Option<DiffViewContent>,
|
||||
|
||||
file_tree: gpui::Entity<PullRequestFileTree>,
|
||||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
@@ -31,7 +34,7 @@ pub(crate) fn new(
|
||||
pr_query: use_query(api::issues::FetchPullRequest { id: pr_id.clone() }, cx),
|
||||
file_tree_query: use_query(
|
||||
api::issues::FetchPullRequestFileTree {
|
||||
id: pr_id,
|
||||
id: pr_id.clone(),
|
||||
first: 100,
|
||||
},
|
||||
cx,
|
||||
@@ -39,6 +42,8 @@ pub(crate) fn new(
|
||||
content_diff_query: None,
|
||||
diff_view_state: DiffViewState::new(),
|
||||
diff_view_content: None,
|
||||
|
||||
file_tree: cx.new(|cx| pull_request_file_tree::new(pr_id, cx)),
|
||||
};
|
||||
view.on_create(cx);
|
||||
view
|
||||
@@ -117,8 +122,8 @@ impl PullRequestDiffView {
|
||||
) {
|
||||
if let Some(diff) = {
|
||||
match read_query(query, cx) {
|
||||
| QueryStatus::Loaded(diff) => Some(Arc::clone(diff)),
|
||||
| _ => None,
|
||||
| QueryStatus::Loaded(diff) => Some(Arc::clone(diff)),
|
||||
| _ => None,
|
||||
}
|
||||
} {
|
||||
self.load_diff_view(diff, cx);
|
||||
@@ -153,16 +158,16 @@ impl PullRequestDiffView {
|
||||
|
||||
_ = cx
|
||||
.spawn(async move |weak, cx| match tokio::join!(t1, t2) {
|
||||
| (Some(old_side_highlights), Some(new_side_highlights)) => {
|
||||
_ = weak.update(cx, |this, cx| {
|
||||
this.diff_view_state
|
||||
.set_old_side_highlights(old_side_highlights);
|
||||
this.diff_view_state
|
||||
.set_new_side_highlights(new_side_highlights);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
| _ => {}
|
||||
| (Some(old_side_highlights), Some(new_side_highlights)) => {
|
||||
_ = weak.update(cx, |this, cx| {
|
||||
this.diff_view_state
|
||||
.set_old_side_highlights(old_side_highlights);
|
||||
this.diff_view_state
|
||||
.set_new_side_highlights(new_side_highlights);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
| _ => {}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
@@ -184,18 +189,30 @@ impl gpui::Render for PullRequestDiffView {
|
||||
.unwrap_or(QueryStatus::Loading);
|
||||
|
||||
match content_diff {
|
||||
| QueryStatus::Err(_) | QueryStatus::Loading => div()
|
||||
.size_full()
|
||||
.bg(theme.colors.surface)
|
||||
.p_4()
|
||||
.child(text("asd")),
|
||||
| QueryStatus::Err(_) | QueryStatus::Loading => div()
|
||||
.size_full()
|
||||
.bg(theme.colors.surface)
|
||||
.p_4()
|
||||
.child(text("asd")),
|
||||
|
||||
| QueryStatus::Loaded(_) => match &self.diff_view_content {
|
||||
| Some(content) => div()
|
||||
.size_full()
|
||||
.child(diff_view(self.diff_view_state.clone(), content.clone())),
|
||||
| None => div(),
|
||||
},
|
||||
| QueryStatus::Loaded(_) => match &self.diff_view_content {
|
||||
| Some(content) => div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.w_80()
|
||||
.h_full()
|
||||
.border_r_1()
|
||||
.border_color(theme.colors.border_muted)
|
||||
.p_1()
|
||||
.child(self.file_tree.clone()),
|
||||
)
|
||||
.child(diff_view(self.diff_view_state.clone(), content.clone())),
|
||||
| None => div(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user