Files
novem/src/screen/dashboard/screen.rs
2026-05-14 00:05:31 +08:00

102 lines
2.9 KiB
Rust

use gpui::{AppContext, ParentElement, Styled, div};
use crate::{
api, app,
screen::dashboard::{
issue_list::{self, IssueList},
pull_request_view::{self, PullRequestView},
titlebar::{self, TitleBar},
},
};
pub(crate) struct Screen {
titlebar: gpui::Entity<TitleBar>,
issue_list: gpui::Entity<IssueList>,
pull_request_view: gpui::Entity<PullRequestView>,
issue_filter: Option<&'static str>,
}
pub(crate) fn new(cx: &mut gpui::Context<Screen>) -> Screen {
let mut screen = Screen {
titlebar: cx.new(titlebar::new),
issue_list: cx.new(issue_list::new),
pull_request_view: cx.new(pull_request_view::new),
issue_filter: None,
};
screen.on_create(cx);
screen
}
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);
}
})
.detach();
}
fn handle_issue_list_item_selected(
&mut self,
id: &api::issues::Id,
cx: &mut gpui::Context<Self>,
) {
println!("handle issue list item selected: {:?}", id);
self.pull_request_view.update(cx, |view, cx| {
view.change_displayed_pull_request(id.clone(), cx);
println!("change displayed pull request: {:?}", id);
cx.notify();
})
}
}
impl gpui::Render for Screen {
fn render(
&mut self,
_window: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
let theme = app::current_theme(cx);
div()
.flex()
.flex_col()
.size_full()
.bg(theme.colors.surface_chrome)
.child(self.titlebar.clone())
.child(
div()
.flex()
.flex_row()
.flex_1()
.min_h_0()
.w_full()
.child(
div()
.w_64()
.flex_shrink_0()
.h_full()
.ml_2()
.overflow_hidden()
.child(self.issue_list.clone()),
)
.child(
div()
.flex_1()
.min_w_0()
.min_h_0()
.m_2()
.mt_0()
.rounded_lg()
.overflow_hidden()
.border_1()
.border_color(theme.colors.border_muted)
.child(self.pull_request_view.clone()),
),
)
}
}