wip: pr file diffing
This commit is contained in:
@@ -148,8 +148,8 @@ impl gpui::RenderOnce for IssueListItem {
|
||||
}
|
||||
|
||||
let repo_name_text = match self.repo_name {
|
||||
| Some(name) => text(name),
|
||||
| None => text("Unknown repo"),
|
||||
| Some(name) => text(name),
|
||||
| None => text("Unknown repo"),
|
||||
}
|
||||
.text_xs()
|
||||
.opacity(0.5);
|
||||
@@ -162,21 +162,21 @@ impl gpui::RenderOnce for IssueListItem {
|
||||
.bg(theme.colors.surface)
|
||||
} else {
|
||||
match self.status {
|
||||
| api::issues::PullRequestState::Closed => pill(
|
||||
text("Closed").text_color(theme.colors.danger_on_solid),
|
||||
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.danger_on_solid),
|
||||
)
|
||||
.bg(theme.colors.danger_solid),
|
||||
| api::issues::PullRequestState::Merged => pill(
|
||||
text("Merged").text_color(theme.colors.accent_on_solid),
|
||||
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.accent_on_solid),
|
||||
)
|
||||
.bg(theme.colors.accent_solid),
|
||||
| _ => pill(
|
||||
text("Open").text_color(theme.colors.success_on_solid),
|
||||
font_icon(FontIcon::PullRequestArrow).text_color(theme.colors.success_on_solid),
|
||||
)
|
||||
.bg(theme.colors.success_solid),
|
||||
| api::issues::PullRequestState::Closed => pill(
|
||||
text("Closed").text_color(theme.colors.danger_on_solid),
|
||||
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.danger_on_solid),
|
||||
)
|
||||
.bg(theme.colors.danger_solid),
|
||||
| api::issues::PullRequestState::Merged => pill(
|
||||
text("Merged").text_color(theme.colors.accent_on_solid),
|
||||
font_icon(FontIcon::PullRequestClosed).text_color(theme.colors.accent_on_solid),
|
||||
)
|
||||
.bg(theme.colors.accent_solid),
|
||||
| _ => pill(
|
||||
text("Open").text_color(theme.colors.success_on_solid),
|
||||
font_icon(FontIcon::PullRequestArrow).text_color(theme.colors.success_on_solid),
|
||||
)
|
||||
.bg(theme.colors.success_solid),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
mod issue_list;
|
||||
mod pull_request_diff_view;
|
||||
mod pull_request_view;
|
||||
mod screen;
|
||||
mod sidebar;
|
||||
|
||||
79
src/screen/dashboard/pull_request_diff_view.rs
Normal file
79
src/screen/dashboard/pull_request_diff_view.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
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!()
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,12 @@ use crate::{
|
||||
text::text,
|
||||
},
|
||||
query::{self, QueryStatus, read_query, use_query},
|
||||
screen::dashboard::pull_request_diff_view::PullRequestDiffView,
|
||||
};
|
||||
|
||||
pub(crate) struct PullRequestView {
|
||||
markdown_viewer: Option<gpui::Entity<MarkdownText>>,
|
||||
diff_view: Option<gpui::Entity<PullRequestDiffView>>,
|
||||
|
||||
pull_request_query: Option<query::Entity<api::issues::FetchPullRequest>>,
|
||||
}
|
||||
@@ -27,6 +29,7 @@ struct Toolbar {}
|
||||
pub fn new(_cx: &mut gpui::Context<PullRequestView>) -> PullRequestView {
|
||||
PullRequestView {
|
||||
markdown_viewer: None,
|
||||
diff_view: None,
|
||||
pull_request_query: None,
|
||||
}
|
||||
}
|
||||
@@ -126,12 +129,9 @@ impl PullRequestView {
|
||||
}
|
||||
}
|
||||
|
||||
let merge_text = match (
|
||||
pr.author.as_ref(),
|
||||
pr.base_branch_name.as_ref(),
|
||||
pr.head_branch_name.as_ref(),
|
||||
) {
|
||||
| (Some(author), Some(base_branch), Some(head_branch)) => {
|
||||
let merge_text = pr.author.as_ref().map(|author| {
|
||||
let base_branch = pr.base_branch_name.as_str();
|
||||
let head_branch = pr.head_branch_name.as_str();
|
||||
let str = format!(
|
||||
"{} requested to merge {} into {}",
|
||||
author.login, head_branch, base_branch
|
||||
@@ -166,14 +166,11 @@ impl PullRequestView {
|
||||
),
|
||||
];
|
||||
|
||||
Some((
|
||||
(
|
||||
author,
|
||||
gpui::StyledText::new(str).with_highlights(highlights),
|
||||
))
|
||||
}
|
||||
|
||||
| _ => None,
|
||||
};
|
||||
)
|
||||
});
|
||||
|
||||
let metadata_line =
|
||||
div()
|
||||
|
||||
@@ -33,9 +33,9 @@ impl Screen {
|
||||
fn on_create(&mut self, cx: &mut gpui::Context<Self>) {
|
||||
_ = cx
|
||||
.subscribe(&self.issue_list, |this, _, event, cx| match event {
|
||||
| issue_list::Event::ItemSelected(pr_id) => {
|
||||
this.handle_issue_list_item_selected(pr_id, cx);
|
||||
}
|
||||
| issue_list::Event::ItemSelected(pr_id) => {
|
||||
this.handle_issue_list_item_selected(pr_id, cx);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user