BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / calendar_picker.rs

calendar_picker.rs

calendar_picker.rs 4.0 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5use store::CalendarAccounts;
6
7use crate::app_state::AppState;
8use crate::theme;
9use crate::views::widgets::icon;
10
11pub const PICKER_WIDTH: f32 = 220.;
12const ROW_HEIGHT: f32 = 28.;
13
14/// Teams-like calendar list: Outlook + each connected Google calendar with show toggles.
15pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
16 let accounts = app.read(cx).calendar_accounts();
17 let mut column = v_flex()
18 .debug_selector(|| "shell/islands/calendar/picker".into())
19 .w(px(PICKER_WIDTH))
20 .flex_none()
21 .h_full()
22 .border_r_1()
23 .border_color(theme::border())
24 .bg(theme::surface())
25 .px(px(12.))
26 .py(px(12.))
27 .gap(px(4.))
28 .child(
29 div()
30 .text_size(px(11.))
31 .font_weight(FontWeight::SEMIBOLD)
32 .text_color(theme::text_muted())
33 .mb(px(6.))
34 .child("CALENDARS"),
35 )
36 .child(outlook_row(app, &accounts));
37 for account in &accounts.google_accounts {
38 column = column.child(
39 div()
40 .mt(px(8.))
41 .mb(px(2.))
42 .text_size(px(11.))
43 .font_weight(FontWeight::SEMIBOLD)
44 .text_color(theme::text_muted())
45 .truncate()
46 .child(account.email.clone()),
47 );
48 for calendar in &account.calendars {
49 let toggle_app = app.clone();
50 let account_id = account.id.clone();
51 let calendar_id = calendar.id.clone();
52 let color = if calendar.primary {
53 theme::accent()
54 } else {
55 theme::text_soft()
56 };
57 column = column.child(toggle_row(
58 format!("calendar-picker-{}", calendar.id),
59 calendar.summary.clone(),
60 calendar.selected,
61 color,
62 move |cx| {
63 toggle_app.update(cx, |state, cx| {
64 state.toggle_google_calendar_selected(&account_id, &calendar_id, cx)
65 });
66 },
67 ));
68 }
69 }
70 if !accounts.has_google() {
71 column = column.child(
72 div()
73 .mt(px(8.))
74 .text_size(px(12.))
75 .text_color(theme::text_muted())
76 .child("Connect Google in Settings › Calendar"),
77 );
78 }
79 column
80}
81
82fn outlook_row(app: &Entity<AppState>, accounts: &CalendarAccounts) -> Stateful<Div> {
83 let app = app.clone();
84 toggle_row(
85 "calendar-picker-outlook",
86 "Outlook",
87 accounts.outlook_selected,
88 theme::accent(),
89 move |cx| {
90 app.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx));
91 },
92 )
93}
94
95fn toggle_row(
96 id: impl Into<ElementId>,
97 label: impl Into<SharedString>,
98 on: bool,
99 swatch: Hsla,
100 on_click: impl Fn(&mut App) + 'static,
101) -> Stateful<Div> {
102 h_flex()
103 .id(id)
104 .h(px(ROW_HEIGHT))
105 .flex_none()
106 .w_full()
107 .items_center()
108 .gap(px(8.))
109 .rounded(px(6.))
110 .px(px(4.))
111 .cursor_pointer()
112 .hover(|row| row.bg(theme::popup_hover()))
113 .on_click(move |_, _, cx| on_click(cx))
114 .child(
115 div()
116 .size(px(14.))
117 .flex_none()
118 .rounded(px(3.))
119 .bg(if on { swatch } else { theme::border() })
120 .when(on, |box_| {
121 box_.flex().items_center().justify_center().child(icon(
122 IconName::Check,
123 10.,
124 theme::text(),
125 ))
126 }),
127 )
128 .child(
129 div()
130 .flex_1()
131 .min_w_0()
132 .truncate()
133 .text_size(px(13.))
134 .text_color(theme::text())
135 .child(label.into()),
136 )
137}