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

97 lines
2.7 KiB
Rust
Raw Normal View History

2026-05-06 01:42:38 +08:00
use gpui::{AppContext, BorrowAppContext, ParentElement, Styled, div};
2026-04-26 16:06:49 +01:00
2026-05-06 01:42:38 +08:00
use crate::{
app,
screen::dashboard::{
issue_list::{self, IssueList},
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>,
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()),
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);
});
}
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
}
}
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().w_40().h_full().child(self.sidebar.clone()))
.child(
div()
.w_80()
.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()
.h_full()
.bg(theme.colors.surface)
.border_l_1()
.border_color(theme.colors.border),
),
2026-04-26 16:06:49 +01:00
)
}
}