Files
novem/src/screen/dashboard/screen.rs

131 lines
3.9 KiB
Rust
Raw Normal View History

2026-05-11 00:32:12 +08:00
use gpui::{AppContext, ParentElement, Styled, div};
2026-04-26 16:06:49 +01:00
2026-05-06 01:42:38 +08:00
use crate::{
2026-05-11 00:32:12 +08:00
api, app,
2026-05-06 01:42:38 +08:00
screen::dashboard::{
issue_list::{self, IssueList},
2026-05-11 00:32:12 +08:00
pull_request_view::{self, PullRequestView},
2026-05-06 01:42:38 +08:00
sidebar::{self, Sidebar, SidebarItemValue},
titlebar::{self, TitleBar},
},
};
2026-04-26 16:06:49 +01:00
pub(crate) struct Screen {
2026-05-06 01:42:38 +08:00
titlebar: gpui::Entity<TitleBar>,
issue_list: gpui::Entity<IssueList>,
sidebar: gpui::Entity<Sidebar>,
2026-05-11 00:32:12 +08:00
pull_request_view: gpui::Entity<PullRequestView>,
2026-05-06 01:42:38 +08:00
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),
sidebar: cx.new(|_| sidebar::new()),
2026-05-11 00:32:12 +08:00
pull_request_view: cx.new(pull_request_view::new),
2026-05-06 01:42:38 +08:00
issue_filter: None,
};
screen.on_create(cx);
screen
2026-04-26 16:06:49 +01:00
}
2026-05-06 01:42:38 +08:00
impl Screen {
fn on_create(&mut self, cx: &mut gpui::Context<Self>) {
let on_item_change = cx.listener(|this, value, _, cx| {
this.handle_sidebar_item_change(value, cx);
});
self.sidebar.update(cx, |sidebar, _| {
sidebar.on_item_change(on_item_change);
});
2026-05-11 00:32:12 +08:00
_ = 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();
2026-05-06 01:42:38 +08:00
}
fn handle_sidebar_item_change(
&mut self,
value: &SidebarItemValue,
cx: &mut gpui::Context<Self>,
) {
match value {
SidebarItemValue::PullRequest { filter } => {
self.issue_filter = Some(*filter);
cx.notify();
}
}
2026-04-26 16:06:49 +01:00
}
2026-05-11 00:32:12 +08:00
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();
})
}
2026-04-26 16:06:49 +01:00
}
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()
.bg(theme.colors.background)
.size_full()
.child(self.titlebar.clone())
.child(
div()
.flex()
.flex_row()
.flex_1()
.w_full()
2026-05-06 01:42:38 +08:00
.child(
div()
2026-05-11 00:32:12 +08:00
.w_40()
.flex_shrink_0()
.h_full()
.child(self.sidebar.clone()),
)
.child(
div()
.w_64()
.flex_shrink_0()
2026-05-06 01:42:38 +08:00
.h_full()
.bg(theme.colors.surface)
.border_x_1()
.border_color(theme.colors.border)
.mr_2()
.overflow_hidden()
.child(self.issue_list.clone()),
)
.child(
div()
.flex_1()
2026-05-11 00:32:12 +08:00
.min_w_0()
2026-05-06 01:42:38 +08:00
.h_full()
.bg(theme.colors.surface)
.border_l_1()
2026-05-11 00:32:12 +08:00
.border_color(theme.colors.border)
.child(self.pull_request_view.clone()),
2026-05-06 01:42:38 +08:00
),
2026-04-26 16:06:49 +01:00
)
}
}