use gpui::{AppContext, BorrowAppContext, ParentElement, Styled, div}; use crate::{ app, screen::dashboard::{ issue_list::{self, IssueList}, sidebar::{self, Sidebar, SidebarItemValue}, titlebar::{self, TitleBar}, }, }; pub(crate) struct Screen { titlebar: gpui::Entity, issue_list: gpui::Entity, sidebar: gpui::Entity, issue_filter: Option<&'static str>, } pub(crate) fn new(cx: &mut gpui::Context) -> 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 } impl Screen { fn on_create(&mut self, cx: &mut gpui::Context) { 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, ) { match value { SidebarItemValue::PullRequest { filter } => { self.issue_filter = Some(*filter); cx.notify(); } } } } impl gpui::Render for Screen { fn render( &mut self, _window: &mut gpui::Window, cx: &mut gpui::Context, ) -> 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() .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), ), ) } }