93 lines
2.7 KiB
Rust
93 lines
2.7 KiB
Rust
use crate::{
|
|
api, app,
|
|
component::text::text,
|
|
query::{self, QueryStatus, read_query, use_query},
|
|
};
|
|
|
|
pub(crate) struct PullRequestDiffView {
|
|
selected_file_path: Option<String>,
|
|
|
|
pr_query: query::Entity<api::issues::FetchPullRequest>,
|
|
content_diff_query: Option<query::Entity<api::repo::FetchFileDiff>>,
|
|
}
|
|
|
|
fn new(pr_id: api::issues::Id, cx: &mut gpui::Context<PullRequestDiffView>) -> PullRequestDiffView {
|
|
let mut view = PullRequestDiffView {
|
|
selected_file_path: None,
|
|
pr_query: use_query(api::issues::FetchPullRequest { id: pr_id }, cx),
|
|
content_diff_query: None,
|
|
};
|
|
view.on_create(cx);
|
|
view
|
|
}
|
|
|
|
impl PullRequestDiffView {
|
|
fn on_create(&mut self, cx: &mut gpui::Context<Self>) {
|
|
_ = cx
|
|
.observe(&self.pr_query, |this, _, cx| {
|
|
this.start_content_queries(cx);
|
|
})
|
|
.detach();
|
|
|
|
// if pr is already loaded, start content queries
|
|
self.start_content_queries(cx);
|
|
}
|
|
|
|
fn start_content_queries(&mut self, cx: &mut gpui::Context<Self>) {
|
|
let Some((old_file_ref, new_file_ref)) = ({
|
|
if let QueryStatus::Loaded(pr) = read_query(&self.pr_query, cx) {
|
|
Some((
|
|
api::repo::FileRef {
|
|
repo_slug: pr.base_repo_slug.clone(),
|
|
path: pr.base_branch_name.clone(),
|
|
reff: Some(pr.base_ref.clone()),
|
|
},
|
|
api::repo::FileRef {
|
|
repo_slug: pr.head_repo_slug.clone(),
|
|
path: pr.head_branch_name.clone(),
|
|
reff: Some(pr.head_ref.clone()),
|
|
},
|
|
))
|
|
} else {
|
|
None
|
|
}
|
|
}) else {
|
|
return;
|
|
};
|
|
|
|
let content_diff_query = use_query(
|
|
api::repo::FetchFileDiff {
|
|
base: old_file_ref,
|
|
head: new_file_ref,
|
|
},
|
|
cx,
|
|
);
|
|
|
|
self.content_diff_query = Some(content_diff_query);
|
|
}
|
|
}
|
|
|
|
impl gpui::Render for PullRequestDiffView {
|
|
fn render(
|
|
&mut self,
|
|
_window: &mut gpui::Window,
|
|
cx: &mut gpui::Context<Self>,
|
|
) -> impl gpui::IntoElement {
|
|
use gpui::{ParentElement, Styled, div};
|
|
|
|
let theme = app::current_theme(cx);
|
|
|
|
div()
|
|
.size_full()
|
|
.bg(theme.colors.surface)
|
|
.p_4()
|
|
.child(
|
|
text(
|
|
"Pull request diff rendering is still under construction. Launch the DiffOps playground with NOVEM_DIFFOPS_PLAYGROUND=1 cargo run.",
|
|
)
|
|
.text_sm()
|
|
.text_color(theme.colors.text_muted),
|
|
)
|
|
}
|
|
}
|