80 lines
2.5 KiB
Rust
80 lines
2.5 KiB
Rust
|
|
use crate::{
|
||
|
|
api,
|
||
|
|
query::{self, QueryStatus, read_query, use_query},
|
||
|
|
};
|
||
|
|
|
||
|
|
pub(crate) struct PullRequestDiffView {
|
||
|
|
selected_file_path: Option<String>,
|
||
|
|
|
||
|
|
pr_query: query::Entity<api::issues::FetchPullRequest>,
|
||
|
|
old_content_query: Option<query::Entity<api::repo::FetchFileContent>>,
|
||
|
|
new_content_query: Option<query::Entity<api::repo::FetchFileContent>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
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),
|
||
|
|
old_content_query: None,
|
||
|
|
new_content_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_content_query, new_content_query)) = ({
|
||
|
|
if let QueryStatus::Loaded(pr) = read_query(&self.pr_query, cx) {
|
||
|
|
Some((
|
||
|
|
api::repo::FetchFileContent {
|
||
|
|
repo_slug: pr.base_repo_slug.clone(),
|
||
|
|
path: pr.base_branch_name.clone(),
|
||
|
|
reff: Some(pr.base_ref.clone()),
|
||
|
|
},
|
||
|
|
api::repo::FetchFileContent {
|
||
|
|
repo_slug: pr.head_repo_slug.clone(),
|
||
|
|
path: pr.head_branch_name.clone(),
|
||
|
|
reff: Some(pr.head_ref.clone()),
|
||
|
|
},
|
||
|
|
))
|
||
|
|
} else {
|
||
|
|
None
|
||
|
|
}
|
||
|
|
}) else {
|
||
|
|
return;
|
||
|
|
};
|
||
|
|
|
||
|
|
let old_content_query = use_query(old_content_query, cx);
|
||
|
|
let new_content_query = use_query(new_content_query, cx);
|
||
|
|
|
||
|
|
_ = cx.observe(&old_content_query, |this, _, cx| {}).detach();
|
||
|
|
|
||
|
|
_ = cx.observe(&new_content_query, |this, _, cx| {}).detach();
|
||
|
|
|
||
|
|
self.old_content_query = Some(old_content_query);
|
||
|
|
self.new_content_query = Some(new_content_query);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl gpui::Render for PullRequestDiffView {
|
||
|
|
fn render(
|
||
|
|
&mut self,
|
||
|
|
window: &mut gpui::Window,
|
||
|
|
cx: &mut gpui::Context<Self>,
|
||
|
|
) -> impl gpui::IntoElement {
|
||
|
|
todo!()
|
||
|
|
}
|
||
|
|
}
|