BlueGit

ict rusty-teams

feat(calendar): Teams-like calendar list pane with mini month

- pane: Calendar heading, mini month (shared with the date picker) that
  marks the visible range, follows navigation until moved and opens the
  span around a picked day, Add calendar opening Settings › Calendar
- groups: My calendars for Outlook and one per Google account, chevron
  collapse (remembered), group check box (all / some / none), check
  boxes in the calendar colour, Show all above five calendars
- turning off every calendar of a Google account now hides the account
  instead of falling back to its primary calendar
- pane toggle hides the pane; layout guard checks pane and mini month
- German range labels read 16.–20. November 2026 like Intl in Teams

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Joachim Mild · pushed by metis

Authored 2026-11-15 · 2 weeks ago

Hash
94caebb43ef47accc14f85fee3bbd19656568481
Parent
064c4288
14 files changed +746 −173
crates/app-base/src/format.rs +37 −1
@@ -175,6 +175,19 @@ pub fn calendar_range_label(start: NaiveDate, end: NaiveDate) -> String {
175 175 format!("{start_month} {}-{}, {}", day(start), day(end), end.year())
176 176 };
177 177 }
178 if style.is_some_and(|style| style.day_month.ends_with('.')) {
179 // German and other dotted styles: "16.–20. November 2026".
180 let to = format!("{}. {end_month} {}", day(end), end.year());
181 return if start == end {
182 to
183 } else if start.year() != end.year() {
184 format!("{}. {start_month} {} – {to}", day(start), start.year())
185 } else if start.month() != end.month() {
186 format!("{}. {start_month} – {to}", day(start))
187 } else {
188 format!("{}.–{to}", day(start))
189 };
190 }
178 191 let to = format!("{} {end_month}, {}", day(end), end.year());
179 192 if start == end {
180 193 to
@@ -435,6 +448,28 @@ mod tests {
435 448 assert_eq!(weekday_name(Weekday::Thu, WeekdayWidth::Letter), "T");
436 449 }
437 450
451 #[test]
452 fn calendar_range_reads_german_with_dots() {
453 let _guard = crate::ui_locale::locale_test_lock();
454 let date = |month, day| NaiveDate::from_ymd_opt(2026, month, day).unwrap();
455 rust_i18n::set_locale("de");
456 set_date_locale(Some("de-CH"));
457 assert_eq!(
458 calendar_range_label(date(11, 16), date(11, 20)),
459 "16.–20. November 2026"
460 );
461 assert_eq!(
462 calendar_range_label(date(11, 30), date(12, 4)),
463 "30. November – 4. Dezember 2026"
464 );
465 assert_eq!(
466 calendar_range_label(date(11, 16), date(11, 16)),
467 "16. November 2026"
468 );
469 rust_i18n::set_locale("en");
470 set_date_locale(None);
471 }
472
438 473 #[test]
439 474 fn calendar_range_follows_the_account_locale() {
440 475 let _guard = crate::ui_locale::locale_test_lock();
@@ -456,10 +491,11 @@ mod tests {
456 491 "November 9-13, 2026"
457 492 );
458 493 assert_eq!(calendar_day_number(date(11, 9)), "9");
494 // Intl.DateTimeFormat in de-DE writes the day with a dot and no comma.
459 495 set_date_locale(Some("de-DE"));
460 496 assert_eq!(
461 497 calendar_range_label(date(11, 9), date(11, 9)),
462 "9 November, 2026"
498 "9. November 2026"
463 499 );
464 500 set_date_locale(None);
465 501 }
@@ -175,6 +175,19 @@ pub fn calendar_range_label(start: NaiveDate, end: NaiveDate) -> String {
175 format!("{start_month} {}-{}, {}", day(start), day(end), end.year())
175 format!("{start_month} {}-{}, {}", day(start), day(end), end.year())
176 };
176 };
177 }
177 }
178 if style.is_some_and(|style| style.day_month.ends_with('.')) {
179 // German and other dotted styles: "16.–20. November 2026".
180 let to = format!("{}. {end_month} {}", day(end), end.year());
181 return if start == end {
182 to
183 } else if start.year() != end.year() {
184 format!("{}. {start_month} {} – {to}", day(start), start.year())
185 } else if start.month() != end.month() {
186 format!("{}. {start_month} – {to}", day(start))
187 } else {
188 format!("{}.–{to}", day(start))
189 };
190 }
178 let to = format!("{} {end_month}, {}", day(end), end.year());
191 let to = format!("{} {end_month}, {}", day(end), end.year());
179 if start == end {
192 if start == end {
180 to
193 to
@@ -435,6 +448,28 @@ mod tests {
435 assert_eq!(weekday_name(Weekday::Thu, WeekdayWidth::Letter), "T");
448 assert_eq!(weekday_name(Weekday::Thu, WeekdayWidth::Letter), "T");
436 }
449 }
437
450
451 #[test]
452 fn calendar_range_reads_german_with_dots() {
453 let _guard = crate::ui_locale::locale_test_lock();
454 let date = |month, day| NaiveDate::from_ymd_opt(2026, month, day).unwrap();
455 rust_i18n::set_locale("de");
456 set_date_locale(Some("de-CH"));
457 assert_eq!(
458 calendar_range_label(date(11, 16), date(11, 20)),
459 "16.–20. November 2026"
460 );
461 assert_eq!(
462 calendar_range_label(date(11, 30), date(12, 4)),
463 "30. November – 4. Dezember 2026"
464 );
465 assert_eq!(
466 calendar_range_label(date(11, 16), date(11, 16)),
467 "16. November 2026"
468 );
469 rust_i18n::set_locale("en");
470 set_date_locale(None);
471 }
472
438 #[test]
473 #[test]
439 fn calendar_range_follows_the_account_locale() {
474 fn calendar_range_follows_the_account_locale() {
440 let _guard = crate::ui_locale::locale_test_lock();
475 let _guard = crate::ui_locale::locale_test_lock();
@@ -456,10 +491,11 @@ mod tests {
456 "November 9-13, 2026"
491 "November 9-13, 2026"
457 );
492 );
458 assert_eq!(calendar_day_number(date(11, 9)), "9");
493 assert_eq!(calendar_day_number(date(11, 9)), "9");
494 // Intl.DateTimeFormat in de-DE writes the day with a dot and no comma.
459 set_date_locale(Some("de-DE"));
495 set_date_locale(Some("de-DE"));
460 assert_eq!(
496 assert_eq!(
461 calendar_range_label(date(11, 9), date(11, 9)),
497 calendar_range_label(date(11, 9), date(11, 9)),
462 "9 November, 2026"
498 "9. November 2026"
463 );
499 );
464 set_date_locale(None);
500 set_date_locale(None);
465 }
501 }
crates/app-call-model/src/calendar_list.rs added +103 −0
@@ -0,0 +1,103 @@
1 //! Calendar list pane logic: group check state, Show all, mini month cells.
2
3 use chrono::{Datelike, NaiveDate};
4
5 /// Groups with more calendars than this hide the ones that are off until Show all.
6 pub const SHOW_ALL_AFTER: usize = 5;
7
8 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9 pub enum GroupCheck {
10 All,
11 Some,
12 None,
13 }
14
15 pub fn group_check(selected: &[bool]) -> GroupCheck {
16 match selected.iter().filter(|on| **on).count() {
17 0 => GroupCheck::None,
18 count if count == selected.len() => GroupCheck::All,
19 _ => GroupCheck::Some,
20 }
21 }
22
23 /// Indexes of the calendars a group lists: all of them when short or expanded,
24 /// otherwise the ones turned on plus the primary one.
25 pub fn listed_calendars(selected: &[bool], primary: &[bool], expanded: bool) -> Vec<usize> {
26 let all = 0..selected.len();
27 if expanded || selected.len() <= SHOW_ALL_AFTER {
28 return all.collect();
29 }
30 all.filter(|&index| selected[index] || primary.get(index).copied().unwrap_or(false))
31 .collect()
32 }
33
34 /// Whether a group offers Show all / Show fewer.
35 pub fn offers_show_all(count: usize) -> bool {
36 count > SHOW_ALL_AFTER
37 }
38
39 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
40 pub struct MiniMonthCell {
41 pub date: NaiveDate,
42 pub in_month: bool,
43 /// Inside the range the grid shows.
44 pub shown: bool,
45 pub today: bool,
46 }
47
48 pub fn mini_month_cell(
49 date: NaiveDate,
50 month: NaiveDate,
51 shown: &[NaiveDate],
52 today: NaiveDate,
53 ) -> MiniMonthCell {
54 MiniMonthCell {
55 date,
56 in_month: date.month() == month.month() && date.year() == month.year(),
57 shown: shown.contains(&date),
58 today: date == today,
59 }
60 }
61
62 #[cfg(test)]
63 mod tests {
64 use super::*;
65
66 #[test]
67 fn the_group_box_reads_all_some_or_none() {
68 assert_eq!(group_check(&[true, true]), GroupCheck::All);
69 assert_eq!(group_check(&[true, false]), GroupCheck::Some);
70 assert_eq!(group_check(&[false, false]), GroupCheck::None);
71 }
72
73 #[test]
74 fn a_long_group_lists_the_primary_and_the_ones_on_until_show_all() {
75 let mut selected = [false; 8];
76 selected[3] = true;
77 selected[6] = true;
78 let mut primary = [false; 8];
79 primary[0] = true;
80 assert_eq!(listed_calendars(&selected, &primary, false), [0, 3, 6]);
81 assert_eq!(listed_calendars(&selected, &primary, true).len(), 8);
82 assert!(offers_show_all(8));
83 assert!(!offers_show_all(5));
84 assert_eq!(listed_calendars(&[false; 4], &[false; 4], false).len(), 4);
85 }
86
87 #[test]
88 fn mini_month_marks_the_shown_range_and_today() {
89 let day = |d| NaiveDate::from_ymd_opt(2026, 11, d).unwrap();
90 let shown: Vec<_> = (16..=20).map(day).collect();
91 let cell = mini_month_cell(day(18), day(1), &shown, day(15));
92 assert!(cell.in_month && cell.shown && !cell.today);
93 let today = mini_month_cell(day(15), day(1), &shown, day(15));
94 assert!(today.today && !today.shown);
95 let outside = mini_month_cell(
96 NaiveDate::from_ymd_opt(2026, 12, 1).unwrap(),
97 day(1),
98 &shown,
99 day(15),
100 );
101 assert!(!outside.in_month);
102 }
103 }
@@ -0,0 +1,103 @@
1//! Calendar list pane logic: group check state, Show all, mini month cells.
2
3use chrono::{Datelike, NaiveDate};
4
5/// Groups with more calendars than this hide the ones that are off until Show all.
6pub const SHOW_ALL_AFTER: usize = 5;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum GroupCheck {
10 All,
11 Some,
12 None,
13}
14
15pub fn group_check(selected: &[bool]) -> GroupCheck {
16 match selected.iter().filter(|on| **on).count() {
17 0 => GroupCheck::None,
18 count if count == selected.len() => GroupCheck::All,
19 _ => GroupCheck::Some,
20 }
21}
22
23/// Indexes of the calendars a group lists: all of them when short or expanded,
24/// otherwise the ones turned on plus the primary one.
25pub fn listed_calendars(selected: &[bool], primary: &[bool], expanded: bool) -> Vec<usize> {
26 let all = 0..selected.len();
27 if expanded || selected.len() <= SHOW_ALL_AFTER {
28 return all.collect();
29 }
30 all.filter(|&index| selected[index] || primary.get(index).copied().unwrap_or(false))
31 .collect()
32}
33
34/// Whether a group offers Show all / Show fewer.
35pub fn offers_show_all(count: usize) -> bool {
36 count > SHOW_ALL_AFTER
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub struct MiniMonthCell {
41 pub date: NaiveDate,
42 pub in_month: bool,
43 /// Inside the range the grid shows.
44 pub shown: bool,
45 pub today: bool,
46}
47
48pub fn mini_month_cell(
49 date: NaiveDate,
50 month: NaiveDate,
51 shown: &[NaiveDate],
52 today: NaiveDate,
53) -> MiniMonthCell {
54 MiniMonthCell {
55 date,
56 in_month: date.month() == month.month() && date.year() == month.year(),
57 shown: shown.contains(&date),
58 today: date == today,
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn the_group_box_reads_all_some_or_none() {
68 assert_eq!(group_check(&[true, true]), GroupCheck::All);
69 assert_eq!(group_check(&[true, false]), GroupCheck::Some);
70 assert_eq!(group_check(&[false, false]), GroupCheck::None);
71 }
72
73 #[test]
74 fn a_long_group_lists_the_primary_and_the_ones_on_until_show_all() {
75 let mut selected = [false; 8];
76 selected[3] = true;
77 selected[6] = true;
78 let mut primary = [false; 8];
79 primary[0] = true;
80 assert_eq!(listed_calendars(&selected, &primary, false), [0, 3, 6]);
81 assert_eq!(listed_calendars(&selected, &primary, true).len(), 8);
82 assert!(offers_show_all(8));
83 assert!(!offers_show_all(5));
84 assert_eq!(listed_calendars(&[false; 4], &[false; 4], false).len(), 4);
85 }
86
87 #[test]
88 fn mini_month_marks_the_shown_range_and_today() {
89 let day = |d| NaiveDate::from_ymd_opt(2026, 11, d).unwrap();
90 let shown: Vec<_> = (16..=20).map(day).collect();
91 let cell = mini_month_cell(day(18), day(1), &shown, day(15));
92 assert!(cell.in_month && cell.shown && !cell.today);
93 let today = mini_month_cell(day(15), day(1), &shown, day(15));
94 assert!(today.today && !today.shown);
95 let outside = mini_month_cell(
96 NaiveDate::from_ymd_opt(2026, 12, 1).unwrap(),
97 day(1),
98 &shown,
99 day(15),
100 );
101 assert!(!outside.in_month);
102 }
103}
crates/app-call-model/src/lib.rs +1 −0
@@ -1,6 +1,7 @@
1 1 pub mod agenda;
2 2 pub mod background;
3 3 pub mod bubbles;
4 pub mod calendar_list;
4 5 pub mod calendar_now;
5 6 pub mod calendar_prefs;
6 7 pub mod caption_style;
@@ -1,6 +1,7 @@
1pub mod agenda;
1pub mod agenda;
2pub mod background;
2pub mod background;
3pub mod bubbles;
3pub mod bubbles;
4pub mod calendar_list;
4pub mod calendar_now;
5pub mod calendar_now;
5pub mod calendar_prefs;
6pub mod calendar_prefs;
6pub mod caption_style;
7pub mod caption_style;
crates/app-state/src/app_state.rs +12 −0
@@ -160,6 +160,10 @@ pub struct AppState {
160 160 pub call_history: Vec<teams_core::CallLogEntry>,
161 161 pub calendar_events: Vec<chatsvc::CalendarEvent>,
162 162 pub calendar_event_peek_request: Option<chatsvc::CalendarEvent>,
163 /// Authorize URL while Google OAuth waits on the loopback redirect.
164 pub google_connect_pending: Option<String>,
165 /// Bumped on cancel so a late loopback result is discarded.
166 pub google_connect_generation: u64,
163 167 pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,
164 168 pub calls_list: crate::call::CallsList,
165 169 pub speed_dial: Vec<crate::call::SpeedDialEntry>,
@@ -212,6 +216,10 @@ pub struct AppState {
212 216 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
213 217 pub calendar_week: crate::call::week::CalendarWeek,
214 218 pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,
219 /// Month the mini month shows after the user moved it; `None` follows the grid.
220 pub calendar_mini_month: Option<chrono::NaiveDate>,
221 /// Calendar list groups expanded with Show all (this session only).
222 pub calendar_expanded_groups: Vec<String>,
215 223 /// Mailbox time zone name, written back unchanged with the work hours.
216 224 pub mailbox_time_zone: Option<String>,
217 225 /// Bumped when the hour grid should align to local «now» (open / Today / day-week span).
@@ -329,6 +337,8 @@ impl AppState {
329 337 call_history: Vec::new(),
330 338 calendar_events: Vec::new(),
331 339 calendar_event_peek_request: None,
340 google_connect_pending: None,
341 google_connect_generation: 0,
332 342 calendar_nudge: None,
333 343 calls_list: crate::call::CallsList::default(),
334 344 speed_dial,
@@ -383,6 +393,8 @@ impl AppState {
383 393 calendar_prefs.initial_span(),
384 394 ),
385 395 calendar_prefs,
396 calendar_mini_month: None,
397 calendar_expanded_groups: Vec::new(),
386 398 mailbox_time_zone: None,
387 399 calendar_scroll_to_now: 0,
388 400 call_backgrounds: if mode.demo {
@@ -160,6 +160,10 @@ pub struct AppState {
160 pub call_history: Vec<teams_core::CallLogEntry>,
160 pub call_history: Vec<teams_core::CallLogEntry>,
161 pub calendar_events: Vec<chatsvc::CalendarEvent>,
161 pub calendar_events: Vec<chatsvc::CalendarEvent>,
162 pub calendar_event_peek_request: Option<chatsvc::CalendarEvent>,
162 pub calendar_event_peek_request: Option<chatsvc::CalendarEvent>,
163 /// Authorize URL while Google OAuth waits on the loopback redirect.
164 pub google_connect_pending: Option<String>,
165 /// Bumped on cancel so a late loopback result is discarded.
166 pub google_connect_generation: u64,
163 pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,
167 pub calendar_nudge: Option<tokio::sync::mpsc::UnboundedSender<()>>,
164 pub calls_list: crate::call::CallsList,
168 pub calls_list: crate::call::CallsList,
165 pub speed_dial: Vec<crate::call::SpeedDialEntry>,
169 pub speed_dial: Vec<crate::call::SpeedDialEntry>,
@@ -212,6 +216,10 @@ pub struct AppState {
212 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
216 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
213 pub calendar_week: crate::call::week::CalendarWeek,
217 pub calendar_week: crate::call::week::CalendarWeek,
214 pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,
218 pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,
219 /// Month the mini month shows after the user moved it; `None` follows the grid.
220 pub calendar_mini_month: Option<chrono::NaiveDate>,
221 /// Calendar list groups expanded with Show all (this session only).
222 pub calendar_expanded_groups: Vec<String>,
215 /// Mailbox time zone name, written back unchanged with the work hours.
223 /// Mailbox time zone name, written back unchanged with the work hours.
216 pub mailbox_time_zone: Option<String>,
224 pub mailbox_time_zone: Option<String>,
217 /// Bumped when the hour grid should align to local «now» (open / Today / day-week span).
225 /// Bumped when the hour grid should align to local «now» (open / Today / day-week span).
@@ -329,6 +337,8 @@ impl AppState {
329 call_history: Vec::new(),
337 call_history: Vec::new(),
330 calendar_events: Vec::new(),
338 calendar_events: Vec::new(),
331 calendar_event_peek_request: None,
339 calendar_event_peek_request: None,
340 google_connect_pending: None,
341 google_connect_generation: 0,
332 calendar_nudge: None,
342 calendar_nudge: None,
333 calls_list: crate::call::CallsList::default(),
343 calls_list: crate::call::CallsList::default(),
334 speed_dial,
344 speed_dial,
@@ -383,6 +393,8 @@ impl AppState {
383 calendar_prefs.initial_span(),
393 calendar_prefs.initial_span(),
384 ),
394 ),
385 calendar_prefs,
395 calendar_prefs,
396 calendar_mini_month: None,
397 calendar_expanded_groups: Vec::new(),
386 mailbox_time_zone: None,
398 mailbox_time_zone: None,
387 calendar_scroll_to_now: 0,
399 calendar_scroll_to_now: 0,
388 call_backgrounds: if mode.demo {
400 call_backgrounds: if mode.demo {
crates/app-state/src/calendar_accounts_actions.rs +92 −21
@@ -1,3 +1,4 @@
1 use app_base::ui_locale::{tr, tr_args};
1 2 use chrono::Utc;
2 3 use gpui_kit::Context;
3 4 use store::{
@@ -19,6 +20,10 @@ impl AppState {
19 20 load_calendar_accounts(&self.store)
20 21 }
21 22
23 pub fn google_connect_pending(&self) -> Option<&str> {
24 self.google_connect_pending.as_deref()
25 }
26
22 27 pub fn disconnect_google_account(&mut self, account_id: &str, cx: &mut Context<Self>) {
23 28 let mut accounts = load_calendar_accounts(&self.store);
24 29 accounts.disconnect_google(account_id);
@@ -71,6 +76,24 @@ impl AppState {
71 76 cx.notify();
72 77 }
73 78
79 /// Group check box: turn every calendar of one Google account on or off.
80 pub fn set_google_account_selected(
81 &mut self,
82 account_id: &str,
83 on: bool,
84 cx: &mut Context<Self>,
85 ) {
86 let mut accounts = load_calendar_accounts(&self.store);
87 if let Some(account) = accounts.google_account_mut(account_id) {
88 for calendar in &mut account.calendars {
89 calendar.selected = on;
90 }
91 }
92 let _ = save_calendar_accounts(&self.store, &accounts);
93 self.refresh_calendar(cx);
94 cx.notify();
95 }
96
74 97 pub fn toggle_outlook_calendar_selected(&mut self, cx: &mut Context<Self>) {
75 98 let mut accounts = load_calendar_accounts(&self.store);
76 99 accounts.outlook_selected = !accounts.outlook_selected;
@@ -80,17 +103,31 @@ impl AppState {
80 103 cx.notify();
81 104 }
82 105
106 pub fn reopen_google_connect(&mut self, cx: &mut Context<Self>) {
107 if let Some(url) = self.google_connect_pending.clone() {
108 crate::external_browser::open_url(cx, &self.store, &url);
109 }
110 }
111
112 pub fn cancel_google_connect(&mut self, cx: &mut Context<Self>) {
113 self.google_connect_generation = self.google_connect_generation.wrapping_add(1);
114 self.google_connect_pending = None;
115 self.raise_notice(tr("settings.calendar.sign_in_cancelled"), None, cx);
116 cx.notify();
117 }
118
83 119 pub fn connect_google_calendar(&mut self, cx: &mut Context<Self>) {
120 if self.google_connect_pending.is_some() {
121 self.reopen_google_connect(cx);
122 return;
123 }
84 124 let Some(oauth) = client_id_from_env() else {
85 self.raise_notice(
86 "Set TEAMS_GOOGLE_CLIENT_ID (and optional TEAMS_GOOGLE_CLIENT_SECRET) to connect Google Calendar."
87 .to_owned(),
88 None,
89 cx,
90 );
125 self.raise_notice(tr("settings.calendar.not_in_build"), None, cx);
91 126 return;
92 127 };
93 128 let store = self.store.clone();
129 self.google_connect_generation = self.google_connect_generation.wrapping_add(1);
130 let generation = self.google_connect_generation;
94 131 cx.spawn(async move |this, cx| {
95 132 let prepared = runtime::spawn({
96 133 let oauth = oauth.clone();
@@ -106,45 +143,73 @@ impl AppState {
106 143 let (authorize_url, pending, listener, oauth) = match prepared.await {
107 144 Ok(Ok(value)) => value,
108 145 Ok(Err(error)) => {
109 this.update(cx, |state, cx| state.raise_notice(error, None, cx))
110 .ok();
146 this.update(cx, |state, cx| {
147 clear_google_connect_if(state, generation);
148 state.raise_notice(error, None, cx);
149 })
150 .ok();
111 151 return;
112 152 }
113 153 Err(_) => {
114 154 this.update(cx, |state, cx| {
115 state.raise_notice("Could not start Google sign-in.".to_owned(), None, cx)
155 clear_google_connect_if(state, generation);
156 state.raise_notice(tr("settings.calendar.sign_in_start_failed"), None, cx);
116 157 })
117 158 .ok();
118 159 return;
119 160 }
120 161 };
121 this.update(cx, |state, cx| {
122 crate::external_browser::open_url(cx, &state.store, &authorize_url);
123 })
124 .ok();
162 let still_current = this
163 .update(cx, |state, cx| {
164 if state.google_connect_generation != generation {
165 return false;
166 }
167 state.google_connect_pending = Some(authorize_url.clone());
168 crate::external_browser::open_url(cx, &state.store, &authorize_url);
169 cx.notify();
170 true
171 })
172 .unwrap_or(false);
173 if !still_current {
174 return;
175 }
125 176 let finished = runtime::spawn(async move {
126 177 finish_google_connect(oauth, pending, listener, store).await
127 178 });
128 179 match finished.await {
129 180 Ok(Ok(email)) => {
130 181 this.update(cx, |state, cx| {
131 state.raise_notice(
132 format!("Google Calendar connected ({email})."),
133 None,
134 cx,
135 );
182 if state.google_connect_generation != generation {
183 return;
184 }
185 state.google_connect_pending = None;
186 let mut args = std::collections::HashMap::new();
187 args.insert("email".to_owned(), email);
188 state.raise_notice(tr_args("settings.calendar.connected", &args), None, cx);
136 189 state.refresh_calendar(cx);
137 190 cx.notify();
138 191 })
139 192 .ok();
140 193 }
141 194 Ok(Err(error)) => {
142 this.update(cx, |state, cx| state.raise_notice(error, None, cx))
143 .ok();
195 this.update(cx, |state, cx| {
196 if state.google_connect_generation != generation {
197 return;
198 }
199 state.google_connect_pending = None;
200 state.raise_notice(error, None, cx);
201 cx.notify();
202 })
203 .ok();
144 204 }
145 205 Err(_) => {
146 206 this.update(cx, |state, cx| {
147 state.raise_notice("Google sign-in was cancelled.".to_owned(), None, cx)
207 if state.google_connect_generation != generation {
208 return;
209 }
210 state.google_connect_pending = None;
211 state.raise_notice(tr("settings.calendar.sign_in_cancelled"), None, cx);
212 cx.notify();
148 213 })
149 214 .ok();
150 215 }
@@ -154,6 +219,12 @@ impl AppState {
154 219 }
155 220 }
156 221
222 fn clear_google_connect_if(state: &mut AppState, generation: u64) {
223 if state.google_connect_generation == generation {
224 state.google_connect_pending = None;
225 }
226 }
227
157 228 async fn finish_google_connect(
158 229 oauth: GoogleOAuth,
159 230 pending: chatsvc::AuthPending,
@@ -1,3 +1,4 @@
1use app_base::ui_locale::{tr, tr_args};
1use chrono::Utc;
2use chrono::Utc;
2use gpui_kit::Context;
3use gpui_kit::Context;
3use store::{
4use store::{
@@ -19,6 +20,10 @@ impl AppState {
19 load_calendar_accounts(&self.store)
20 load_calendar_accounts(&self.store)
20 }
21 }
21
22
23 pub fn google_connect_pending(&self) -> Option<&str> {
24 self.google_connect_pending.as_deref()
25 }
26
22 pub fn disconnect_google_account(&mut self, account_id: &str, cx: &mut Context<Self>) {
27 pub fn disconnect_google_account(&mut self, account_id: &str, cx: &mut Context<Self>) {
23 let mut accounts = load_calendar_accounts(&self.store);
28 let mut accounts = load_calendar_accounts(&self.store);
24 accounts.disconnect_google(account_id);
29 accounts.disconnect_google(account_id);
@@ -71,6 +76,24 @@ impl AppState {
71 cx.notify();
76 cx.notify();
72 }
77 }
73
78
79 /// Group check box: turn every calendar of one Google account on or off.
80 pub fn set_google_account_selected(
81 &mut self,
82 account_id: &str,
83 on: bool,
84 cx: &mut Context<Self>,
85 ) {
86 let mut accounts = load_calendar_accounts(&self.store);
87 if let Some(account) = accounts.google_account_mut(account_id) {
88 for calendar in &mut account.calendars {
89 calendar.selected = on;
90 }
91 }
92 let _ = save_calendar_accounts(&self.store, &accounts);
93 self.refresh_calendar(cx);
94 cx.notify();
95 }
96
74 pub fn toggle_outlook_calendar_selected(&mut self, cx: &mut Context<Self>) {
97 pub fn toggle_outlook_calendar_selected(&mut self, cx: &mut Context<Self>) {
75 let mut accounts = load_calendar_accounts(&self.store);
98 let mut accounts = load_calendar_accounts(&self.store);
76 accounts.outlook_selected = !accounts.outlook_selected;
99 accounts.outlook_selected = !accounts.outlook_selected;
@@ -80,17 +103,31 @@ impl AppState {
80 cx.notify();
103 cx.notify();
81 }
104 }
82
105
106 pub fn reopen_google_connect(&mut self, cx: &mut Context<Self>) {
107 if let Some(url) = self.google_connect_pending.clone() {
108 crate::external_browser::open_url(cx, &self.store, &url);
109 }
110 }
111
112 pub fn cancel_google_connect(&mut self, cx: &mut Context<Self>) {
113 self.google_connect_generation = self.google_connect_generation.wrapping_add(1);
114 self.google_connect_pending = None;
115 self.raise_notice(tr("settings.calendar.sign_in_cancelled"), None, cx);
116 cx.notify();
117 }
118
83 pub fn connect_google_calendar(&mut self, cx: &mut Context<Self>) {
119 pub fn connect_google_calendar(&mut self, cx: &mut Context<Self>) {
120 if self.google_connect_pending.is_some() {
121 self.reopen_google_connect(cx);
122 return;
123 }
84 let Some(oauth) = client_id_from_env() else {
124 let Some(oauth) = client_id_from_env() else {
85 self.raise_notice(
125 self.raise_notice(tr("settings.calendar.not_in_build"), None, cx);
86 "Set TEAMS_GOOGLE_CLIENT_ID (and optional TEAMS_GOOGLE_CLIENT_SECRET) to connect Google Calendar."
87 .to_owned(),
88 None,
89 cx,
90 );
91 return;
126 return;
92 };
127 };
93 let store = self.store.clone();
128 let store = self.store.clone();
129 self.google_connect_generation = self.google_connect_generation.wrapping_add(1);
130 let generation = self.google_connect_generation;
94 cx.spawn(async move |this, cx| {
131 cx.spawn(async move |this, cx| {
95 let prepared = runtime::spawn({
132 let prepared = runtime::spawn({
96 let oauth = oauth.clone();
133 let oauth = oauth.clone();
@@ -106,45 +143,73 @@ impl AppState {
106 let (authorize_url, pending, listener, oauth) = match prepared.await {
143 let (authorize_url, pending, listener, oauth) = match prepared.await {
107 Ok(Ok(value)) => value,
144 Ok(Ok(value)) => value,
108 Ok(Err(error)) => {
145 Ok(Err(error)) => {
109 this.update(cx, |state, cx| state.raise_notice(error, None, cx))
146 this.update(cx, |state, cx| {
110 .ok();
147 clear_google_connect_if(state, generation);
148 state.raise_notice(error, None, cx);
149 })
150 .ok();
111 return;
151 return;
112 }
152 }
113 Err(_) => {
153 Err(_) => {
114 this.update(cx, |state, cx| {
154 this.update(cx, |state, cx| {
115 state.raise_notice("Could not start Google sign-in.".to_owned(), None, cx)
155 clear_google_connect_if(state, generation);
156 state.raise_notice(tr("settings.calendar.sign_in_start_failed"), None, cx);
116 })
157 })
117 .ok();
158 .ok();
118 return;
159 return;
119 }
160 }
120 };
161 };
121 this.update(cx, |state, cx| {
162 let still_current = this
122 crate::external_browser::open_url(cx, &state.store, &authorize_url);
163 .update(cx, |state, cx| {
123 })
164 if state.google_connect_generation != generation {
124 .ok();
165 return false;
166 }
167 state.google_connect_pending = Some(authorize_url.clone());
168 crate::external_browser::open_url(cx, &state.store, &authorize_url);
169 cx.notify();
170 true
171 })
172 .unwrap_or(false);
173 if !still_current {
174 return;
175 }
125 let finished = runtime::spawn(async move {
176 let finished = runtime::spawn(async move {
126 finish_google_connect(oauth, pending, listener, store).await
177 finish_google_connect(oauth, pending, listener, store).await
127 });
178 });
128 match finished.await {
179 match finished.await {
129 Ok(Ok(email)) => {
180 Ok(Ok(email)) => {
130 this.update(cx, |state, cx| {
181 this.update(cx, |state, cx| {
131 state.raise_notice(
182 if state.google_connect_generation != generation {
132 format!("Google Calendar connected ({email})."),
183 return;
133 None,
184 }
134 cx,
185 state.google_connect_pending = None;
135 );
186 let mut args = std::collections::HashMap::new();
187 args.insert("email".to_owned(), email);
188 state.raise_notice(tr_args("settings.calendar.connected", &args), None, cx);
136 state.refresh_calendar(cx);
189 state.refresh_calendar(cx);
137 cx.notify();
190 cx.notify();
138 })
191 })
139 .ok();
192 .ok();
140 }
193 }
141 Ok(Err(error)) => {
194 Ok(Err(error)) => {
142 this.update(cx, |state, cx| state.raise_notice(error, None, cx))
195 this.update(cx, |state, cx| {
143 .ok();
196 if state.google_connect_generation != generation {
197 return;
198 }
199 state.google_connect_pending = None;
200 state.raise_notice(error, None, cx);
201 cx.notify();
202 })
203 .ok();
144 }
204 }
145 Err(_) => {
205 Err(_) => {
146 this.update(cx, |state, cx| {
206 this.update(cx, |state, cx| {
147 state.raise_notice("Google sign-in was cancelled.".to_owned(), None, cx)
207 if state.google_connect_generation != generation {
208 return;
209 }
210 state.google_connect_pending = None;
211 state.raise_notice(tr("settings.calendar.sign_in_cancelled"), None, cx);
212 cx.notify();
148 })
213 })
149 .ok();
214 .ok();
150 }
215 }
@@ -154,6 +219,12 @@ impl AppState {
154 }
219 }
155}
220}
156
221
222fn clear_google_connect_if(state: &mut AppState, generation: u64) {
223 if state.google_connect_generation == generation {
224 state.google_connect_pending = None;
225 }
226}
227
157async fn finish_google_connect(
228async fn finish_google_connect(
158 oauth: GoogleOAuth,
229 oauth: GoogleOAuth,
159 pending: chatsvc::AuthPending,
230 pending: chatsvc::AuthPending,
crates/app-state/src/call/mod.rs +4 −4
@@ -25,10 +25,10 @@ pub mod view_actions;
25 25 pub mod week;
26 26
27 27 pub use app_call_model::{
28 agenda, background, bubbles, calendar_now, calendar_prefs, caption_style, demo, end_screen,
29 fullscreen, health, media, mic, model, options_dialog, people, preview, record_rights,
30 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
31 week_grid,
28 agenda, background, bubbles, calendar_list, calendar_now, calendar_prefs, caption_style, demo,
29 end_screen, fullscreen, health, media, mic, model, options_dialog, people, preview,
30 record_rights, recording_menu, report, ring, share_view, stage_layout, stage_split, transcript,
31 view_settings, week_grid,
32 32 };
33 33
34 34 pub use actions::{
@@ -25,10 +25,10 @@ pub mod view_actions;
25pub mod week;
25pub mod week;
26
26
27pub use app_call_model::{
27pub use app_call_model::{
28 agenda, background, bubbles, calendar_now, calendar_prefs, caption_style, demo, end_screen,
28 agenda, background, bubbles, calendar_list, calendar_now, calendar_prefs, caption_style, demo,
29 fullscreen, health, media, mic, model, options_dialog, people, preview, record_rights,
29 end_screen, fullscreen, health, media, mic, model, options_dialog, people, preview,
30 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
30 record_rights, recording_menu, report, ring, share_view, stage_layout, stage_split, transcript,
31 week_grid,
31 view_settings, week_grid,
32};
32};
33
33
34pub use actions::{
34pub use actions::{
crates/app-state/src/call/week.rs +36 −0
@@ -136,7 +136,42 @@ impl AppState {
136 136 self.open_calendar(cx);
137 137 }
138 138
139 /// Month the mini month shows: the user's own choice, else the visible range.
140 pub fn calendar_mini_month_shown(&self) -> NaiveDate {
141 self.calendar_mini_month.unwrap_or_else(|| {
142 let dates = self.calendar_dates();
143 let middle = dates.get(dates.len() / 2).copied();
144 super::week_grid::first_of_month(middle.unwrap_or_else(|| self.calendar_start()))
145 })
146 }
147
148 pub fn move_calendar_mini_month(&mut self, steps: i32, cx: &mut Context<Self>) {
149 let month = self.calendar_mini_month_shown();
150 let moved = if steps >= 0 {
151 month.checked_add_months(chrono::Months::new(steps.unsigned_abs()))
152 } else {
153 month.checked_sub_months(chrono::Months::new(steps.unsigned_abs()))
154 };
155 self.calendar_mini_month = Some(moved.unwrap_or(month));
156 cx.notify();
157 }
158
159 pub fn toggle_calendar_group_expanded(&mut self, group: &str, cx: &mut Context<Self>) {
160 if let Some(index) = self
161 .calendar_expanded_groups
162 .iter()
163 .position(|existing| existing == group)
164 {
165 self.calendar_expanded_groups.remove(index);
166 } else {
167 self.calendar_expanded_groups.push(group.to_owned());
168 }
169 cx.notify();
170 }
171
139 172 pub fn request_calendar_scroll_to_now(&mut self, cx: &mut Context<Self>) {
173 // Every navigation lands here: the mini month follows the grid again.
174 self.calendar_mini_month = None;
140 175 if !crate::call::calendar_now::shows_hour_grid(self.calendar_week.span) {
141 176 return;
142 177 }
@@ -155,6 +190,7 @@ impl AppState {
155 190 };
156 191 self.calendar_week.span = span;
157 192 self.calendar_week.start = Some(self.calendar_span_start(anchor));
193 self.calendar_mini_month = None;
158 194 if self.calendar_prefs.last_span != span {
159 195 self.calendar_prefs.last_span = span;
160 196 save_calendar_prefs(&self.store, &self.calendar_prefs);
@@ -136,7 +136,42 @@ impl AppState {
136 self.open_calendar(cx);
136 self.open_calendar(cx);
137 }
137 }
138
138
139 /// Month the mini month shows: the user's own choice, else the visible range.
140 pub fn calendar_mini_month_shown(&self) -> NaiveDate {
141 self.calendar_mini_month.unwrap_or_else(|| {
142 let dates = self.calendar_dates();
143 let middle = dates.get(dates.len() / 2).copied();
144 super::week_grid::first_of_month(middle.unwrap_or_else(|| self.calendar_start()))
145 })
146 }
147
148 pub fn move_calendar_mini_month(&mut self, steps: i32, cx: &mut Context<Self>) {
149 let month = self.calendar_mini_month_shown();
150 let moved = if steps >= 0 {
151 month.checked_add_months(chrono::Months::new(steps.unsigned_abs()))
152 } else {
153 month.checked_sub_months(chrono::Months::new(steps.unsigned_abs()))
154 };
155 self.calendar_mini_month = Some(moved.unwrap_or(month));
156 cx.notify();
157 }
158
159 pub fn toggle_calendar_group_expanded(&mut self, group: &str, cx: &mut Context<Self>) {
160 if let Some(index) = self
161 .calendar_expanded_groups
162 .iter()
163 .position(|existing| existing == group)
164 {
165 self.calendar_expanded_groups.remove(index);
166 } else {
167 self.calendar_expanded_groups.push(group.to_owned());
168 }
169 cx.notify();
170 }
171
139 pub fn request_calendar_scroll_to_now(&mut self, cx: &mut Context<Self>) {
172 pub fn request_calendar_scroll_to_now(&mut self, cx: &mut Context<Self>) {
173 // Every navigation lands here: the mini month follows the grid again.
174 self.calendar_mini_month = None;
140 if !crate::call::calendar_now::shows_hour_grid(self.calendar_week.span) {
175 if !crate::call::calendar_now::shows_hour_grid(self.calendar_week.span) {
141 return;
176 return;
142 }
177 }
@@ -155,6 +190,7 @@ impl AppState {
155 };
190 };
156 self.calendar_week.span = span;
191 self.calendar_week.span = span;
157 self.calendar_week.start = Some(self.calendar_span_start(anchor));
192 self.calendar_week.start = Some(self.calendar_span_start(anchor));
193 self.calendar_mini_month = None;
158 if self.calendar_prefs.last_span != span {
194 if self.calendar_prefs.last_span != span {
159 self.calendar_prefs.last_span = span;
195 self.calendar_prefs.last_span = span;
160 save_calendar_prefs(&self.store, &self.calendar_prefs);
196 save_calendar_prefs(&self.store, &self.calendar_prefs);
crates/app-state/src/google_calendar_sync.rs +4 −0
@@ -33,6 +33,10 @@ pub async fn fetch_google_events(
33 33 .filter(|calendar| calendar.selected)
34 34 .map(|calendar| (calendar.id.clone(), calendar.summary.clone()))
35 35 .collect();
36 // Every calendar turned off (group check box): the account shows nothing.
37 if calendars.is_empty() && !account.calendars.is_empty() {
38 continue;
39 }
36 40 let calendars = if calendars.is_empty() {
37 41 vec![(
38 42 "primary".to_owned(),
@@ -33,6 +33,10 @@ pub async fn fetch_google_events(
33 .filter(|calendar| calendar.selected)
33 .filter(|calendar| calendar.selected)
34 .map(|calendar| (calendar.id.clone(), calendar.summary.clone()))
34 .map(|calendar| (calendar.id.clone(), calendar.summary.clone()))
35 .collect();
35 .collect();
36 // Every calendar turned off (group check box): the account shows nothing.
37 if calendars.is_empty() && !account.calendars.is_empty() {
38 continue;
39 }
36 let calendars = if calendars.is_empty() {
40 let calendars = if calendars.is_empty() {
37 vec![(
41 vec![(
38 "primary".to_owned(),
42 "primary".to_owned(),
crates/app/src/layout_guard.rs +7 −0
@@ -265,6 +265,7 @@ mod frames {
265 265 ];
266 266 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
267 267 const CALENDAR: &str = "shell/islands/calendar";
268 use crate::views::calendar_picker::{CALENDAR_PANE_TAG, MINI_MONTH_TAG};
268 269 use crate::views::calendar_view::{
269 270 CALENDAR_DAY_HEADERS_TAG, CALENDAR_HEADER_TAG, CALENDAR_NEW_MEETING_TAG,
270 271 };
@@ -639,6 +640,8 @@ mod frames {
639 640 &CALENDAR_HEADER_TAG,
640 641 &CALENDAR_DAY_HEADERS_TAG,
641 642 &CALENDAR_NEW_MEETING_TAG,
643 &CALENDAR_PANE_TAG,
644 &MINI_MONTH_TAG,
642 645 &CALL_TRANSCRIPT,
643 646 &MENU,
644 647 &RECAP_TAB,
@@ -1050,6 +1053,10 @@ mod frames {
1050 1053 });
1051 1054 expected.push(CALENDAR);
1052 1055 expected.extend([CALENDAR_HEADER_TAG, CALENDAR_DAY_HEADERS_TAG]);
1056 // The calendar list pane hides on narrow windows.
1057 if width >= crate::views::calendar_view::COMPACT_HEADER_WIDTH {
1058 expected.extend([CALENDAR_PANE_TAG, MINI_MONTH_TAG]);
1059 }
1053 1060 }
1054 1061 "prejoin" => expected.extend(PREJOIN_TAGS),
1055 1062 _ => {}
@@ -265,6 +265,7 @@ mod frames {
265 ];
265 ];
266 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
266 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
267 const CALENDAR: &str = "shell/islands/calendar";
267 const CALENDAR: &str = "shell/islands/calendar";
268 use crate::views::calendar_picker::{CALENDAR_PANE_TAG, MINI_MONTH_TAG};
268 use crate::views::calendar_view::{
269 use crate::views::calendar_view::{
269 CALENDAR_DAY_HEADERS_TAG, CALENDAR_HEADER_TAG, CALENDAR_NEW_MEETING_TAG,
270 CALENDAR_DAY_HEADERS_TAG, CALENDAR_HEADER_TAG, CALENDAR_NEW_MEETING_TAG,
270 };
271 };
@@ -639,6 +640,8 @@ mod frames {
639 &CALENDAR_HEADER_TAG,
640 &CALENDAR_HEADER_TAG,
640 &CALENDAR_DAY_HEADERS_TAG,
641 &CALENDAR_DAY_HEADERS_TAG,
641 &CALENDAR_NEW_MEETING_TAG,
642 &CALENDAR_NEW_MEETING_TAG,
643 &CALENDAR_PANE_TAG,
644 &MINI_MONTH_TAG,
642 &CALL_TRANSCRIPT,
645 &CALL_TRANSCRIPT,
643 &MENU,
646 &MENU,
644 &RECAP_TAB,
647 &RECAP_TAB,
@@ -1050,6 +1053,10 @@ mod frames {
1050 });
1053 });
1051 expected.push(CALENDAR);
1054 expected.push(CALENDAR);
1052 expected.extend([CALENDAR_HEADER_TAG, CALENDAR_DAY_HEADERS_TAG]);
1055 expected.extend([CALENDAR_HEADER_TAG, CALENDAR_DAY_HEADERS_TAG]);
1056 // The calendar list pane hides on narrow windows.
1057 if width >= crate::views::calendar_view::COMPACT_HEADER_WIDTH {
1058 expected.extend([CALENDAR_PANE_TAG, MINI_MONTH_TAG]);
1059 }
1053 }
1060 }
1054 "prejoin" => expected.extend(PREJOIN_TAGS),
1061 "prejoin" => expected.extend(PREJOIN_TAGS),
1055 _ => {}
1062 _ => {}
crates/app/src/views/calendar_date_picker.rs +18 −69
@@ -1,17 +1,17 @@
1 1 use std::cell::RefCell;
2 2 use std::rc::Rc;
3 3
4 use chrono::{Datelike, Duration, Local, Months, NaiveDate, Weekday};
4 use chrono::{Local, Months, NaiveDate, Weekday};
5 5 use gpui_kit::assets::IconName;
6 6 use gpui_kit::component::Sizable as _;
7 7 use gpui_kit::component::button::{Button, ButtonVariants as _};
8 8 use gpui_kit::component::popover::{Popover, PopoverState};
9 9 use gpui_kit::component::{h_flex, v_flex};
10 use gpui_kit::prelude::FluentBuilder as _;
11 10 use gpui_kit::*;
12 11
12 use super::calendar_mini_month::mini_month_grid;
13 13 use crate::app_state::AppState;
14 use crate::call::week_grid::{MONTH_GRID_DAYS, first_of_month, month_grid_start};
14 use crate::call::week_grid::first_of_month;
15 15 use crate::theme;
16 16
17 17 pub const DATE_PICKER_TAG: &str = "shell/islands/calendar/date-picker";
@@ -60,54 +60,25 @@ impl DatePicker {
60 60 .update(cx, |popover, cx| popover.dismiss(window, cx))
61 61 .ok();
62 62 }
63
64 fn day_cell(&self, date: NaiveDate, today: NaiveDate, cx: &mut Context<Self>) -> Stateful<Div> {
65 let in_month = date.month() == self.month.month();
66 let shown = self.shown.contains(&date);
67 let is_today = date == today;
68 div()
69 .id(SharedString::from(format!("date-picker-{date}")))
70 .size(px(CELL_SIZE))
71 .flex()
72 .items_center()
73 .justify_center()
74 .rounded_full()
75 .cursor_pointer()
76 .text_size(px(12.))
77 .text_color(if in_month {
78 theme::text()
79 } else {
80 theme::text_faint()
81 })
82 .when(shown && !is_today, |cell| cell.bg(theme::popup_hover()))
83 .when(is_today, |cell| {
84 cell.bg(theme::accent()).text_color(theme::on_accent())
85 })
86 .when(!is_today, |cell| {
87 cell.hover(|cell| cell.bg(theme::border_strong()))
88 })
89 .child(date.day().to_string())
90 .on_click(cx.listener(move |this, _, window, cx| this.pick(date, window, cx)))
91 }
92 63 }
93 64
94 65 impl Render for DatePicker {
95 66 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
96 67 let today = Local::now().date_naive();
97 let start = month_grid_start(self.month, self.first_day);
98 let days: Vec<NaiveDate> = (0..MONTH_GRID_DAYS)
99 .map(|offset| start + Duration::days(offset))
100 .collect();
101 let weeks = days
102 .chunks(7)
103 .map(|week| {
104 h_flex().children(
105 week.iter()
106 .map(|date| self.day_cell(*date, today, cx))
107 .collect::<Vec<_>>(),
108 )
109 })
110 .collect::<Vec<_>>();
68 let picker = cx.entity().downgrade();
69 let grid = mini_month_grid(
70 "date-picker",
71 self.month,
72 &self.shown,
73 self.first_day,
74 today,
75 CELL_SIZE,
76 Rc::new(move |date, window, cx| {
77 picker
78 .update(cx, |picker, cx| picker.pick(date, window, cx))
79 .ok();
80 }),
81 );
111 82 v_flex()
112 83 .debug_selector(|| DATE_PICKER_TAG.into())
113 84 .p(px(PICKER_PADDING))
@@ -149,32 +120,10 @@ impl Render for DatePicker {
149 120 ),
150 121 ),
151 122 )
152 .child(
153 h_flex().children(weekday_letters(self.first_day).map(|letter| {
154 div()
155 .size(px(CELL_SIZE))
156 .flex()
157 .items_center()
158 .justify_center()
159 .text_size(px(11.))
160 .text_color(theme::text_muted())
161 .child(letter)
162 })),
163 )
164 .children(weeks)
123 .child(grid)
165 124 }
166 125 }
167 126
168 /// Weekday initials in column order from the first day, in the app language.
169 fn weekday_letters(first_day: Weekday) -> [String; 7] {
170 let mut day = first_day;
171 std::array::from_fn(|_| {
172 let letter = app_base::format::weekday_name(day, app_base::format::WeekdayWidth::Letter);
173 day = day.succ();
174 letter
175 })
176 }
177
178 127 pub fn date_picker_button(
179 128 app: &Entity<AppState>,
180 129 title: String,
@@ -1,17 +1,17 @@
1use std::cell::RefCell;
1use std::cell::RefCell;
2use std::rc::Rc;
2use std::rc::Rc;
3
3
4use chrono::{Datelike, Duration, Local, Months, NaiveDate, Weekday};
4use chrono::{Local, Months, NaiveDate, Weekday};
5use gpui_kit::assets::IconName;
5use gpui_kit::assets::IconName;
6use gpui_kit::component::Sizable as _;
6use gpui_kit::component::Sizable as _;
7use gpui_kit::component::button::{Button, ButtonVariants as _};
7use gpui_kit::component::button::{Button, ButtonVariants as _};
8use gpui_kit::component::popover::{Popover, PopoverState};
8use gpui_kit::component::popover::{Popover, PopoverState};
9use gpui_kit::component::{h_flex, v_flex};
9use gpui_kit::component::{h_flex, v_flex};
10use gpui_kit::prelude::FluentBuilder as _;
11use gpui_kit::*;
10use gpui_kit::*;
12
11
12use super::calendar_mini_month::mini_month_grid;
13use crate::app_state::AppState;
13use crate::app_state::AppState;
14use crate::call::week_grid::{MONTH_GRID_DAYS, first_of_month, month_grid_start};
14use crate::call::week_grid::first_of_month;
15use crate::theme;
15use crate::theme;
16
16
17pub const DATE_PICKER_TAG: &str = "shell/islands/calendar/date-picker";
17pub const DATE_PICKER_TAG: &str = "shell/islands/calendar/date-picker";
@@ -60,54 +60,25 @@ impl DatePicker {
60 .update(cx, |popover, cx| popover.dismiss(window, cx))
60 .update(cx, |popover, cx| popover.dismiss(window, cx))
61 .ok();
61 .ok();
62 }
62 }
63
64 fn day_cell(&self, date: NaiveDate, today: NaiveDate, cx: &mut Context<Self>) -> Stateful<Div> {
65 let in_month = date.month() == self.month.month();
66 let shown = self.shown.contains(&date);
67 let is_today = date == today;
68 div()
69 .id(SharedString::from(format!("date-picker-{date}")))
70 .size(px(CELL_SIZE))
71 .flex()
72 .items_center()
73 .justify_center()
74 .rounded_full()
75 .cursor_pointer()
76 .text_size(px(12.))
77 .text_color(if in_month {
78 theme::text()
79 } else {
80 theme::text_faint()
81 })
82 .when(shown && !is_today, |cell| cell.bg(theme::popup_hover()))
83 .when(is_today, |cell| {
84 cell.bg(theme::accent()).text_color(theme::on_accent())
85 })
86 .when(!is_today, |cell| {
87 cell.hover(|cell| cell.bg(theme::border_strong()))
88 })
89 .child(date.day().to_string())
90 .on_click(cx.listener(move |this, _, window, cx| this.pick(date, window, cx)))
91 }
92}
63}
93
64
94impl Render for DatePicker {
65impl Render for DatePicker {
95 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
66 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
96 let today = Local::now().date_naive();
67 let today = Local::now().date_naive();
97 let start = month_grid_start(self.month, self.first_day);
68 let picker = cx.entity().downgrade();
98 let days: Vec<NaiveDate> = (0..MONTH_GRID_DAYS)
69 let grid = mini_month_grid(
99 .map(|offset| start + Duration::days(offset))
70 "date-picker",
100 .collect();
71 self.month,
101 let weeks = days
72 &self.shown,
102 .chunks(7)
73 self.first_day,
103 .map(|week| {
74 today,
104 h_flex().children(
75 CELL_SIZE,
105 week.iter()
76 Rc::new(move |date, window, cx| {
106 .map(|date| self.day_cell(*date, today, cx))
77 picker
107 .collect::<Vec<_>>(),
78 .update(cx, |picker, cx| picker.pick(date, window, cx))
108 )
79 .ok();
109 })
80 }),
110 .collect::<Vec<_>>();
81 );
111 v_flex()
82 v_flex()
112 .debug_selector(|| DATE_PICKER_TAG.into())
83 .debug_selector(|| DATE_PICKER_TAG.into())
113 .p(px(PICKER_PADDING))
84 .p(px(PICKER_PADDING))
@@ -149,32 +120,10 @@ impl Render for DatePicker {
149 ),
120 ),
150 ),
121 ),
151 )
122 )
152 .child(
123 .child(grid)
153 h_flex().children(weekday_letters(self.first_day).map(|letter| {
154 div()
155 .size(px(CELL_SIZE))
156 .flex()
157 .items_center()
158 .justify_center()
159 .text_size(px(11.))
160 .text_color(theme::text_muted())
161 .child(letter)
162 })),
163 )
164 .children(weeks)
165 }
124 }
166}
125}
167
126
168/// Weekday initials in column order from the first day, in the app language.
169fn weekday_letters(first_day: Weekday) -> [String; 7] {
170 let mut day = first_day;
171 std::array::from_fn(|_| {
172 let letter = app_base::format::weekday_name(day, app_base::format::WeekdayWidth::Letter);
173 day = day.succ();
174 letter
175 })
176}
177
178pub fn date_picker_button(
127pub fn date_picker_button(
179 app: &Entity<AppState>,
128 app: &Entity<AppState>,
180 title: String,
129 title: String,
crates/app/src/views/calendar_mini_month.rs added +95 −0
@@ -0,0 +1,95 @@
1 //! Mini month grid shared by the date picker popover and the calendar list pane.
2
3 use std::rc::Rc;
4
5 use chrono::{Datelike, Duration, NaiveDate, Weekday};
6 use gpui_kit::component::{h_flex, v_flex};
7 use gpui_kit::prelude::FluentBuilder as _;
8 use gpui_kit::*;
9
10 use crate::call::calendar_list::mini_month_cell;
11 use crate::call::week_grid::{MONTH_GRID_DAYS, month_grid_start};
12 use crate::theme;
13
14 pub type PickDate = Rc<dyn Fn(NaiveDate, &mut Window, &mut App)>;
15
16 /// Weekday initials in column order from the first day, in the app language.
17 pub fn weekday_letters(first_day: Weekday) -> [String; 7] {
18 let mut day = first_day;
19 std::array::from_fn(|_| {
20 let letter = app_base::format::weekday_name(day, app_base::format::WeekdayWidth::Letter);
21 day = day.succ();
22 letter
23 })
24 }
25
26 /// Weekday initials and six weeks of day cells; the shown range is a band, today a circle.
27 #[allow(clippy::too_many_arguments)]
28 pub fn mini_month_grid(
29 id: &'static str,
30 month: NaiveDate,
31 shown: &[NaiveDate],
32 first_day: Weekday,
33 today: NaiveDate,
34 cell_size: f32,
35 on_pick: PickDate,
36 ) -> Div {
37 let start = month_grid_start(month, first_day);
38 let weeks = (0..MONTH_GRID_DAYS)
39 .map(|offset| start + Duration::days(offset))
40 .collect::<Vec<_>>()
41 .chunks(7)
42 .map(|week| {
43 h_flex().children(week.iter().map(|date| {
44 let cell = mini_month_cell(*date, month, shown, today);
45 let pick = on_pick.clone();
46 let date = *date;
47 div()
48 .id(SharedString::from(format!("{id}-{date}")))
49 .size(px(cell_size))
50 .flex()
51 .items_center()
52 .justify_center()
53 .when(cell.shown, |band| band.bg(theme::popup_hover()))
54 .child(
55 div()
56 .size(px(cell_size - 4.))
57 .flex()
58 .items_center()
59 .justify_center()
60 .rounded_full()
61 .cursor_pointer()
62 .text_size(px(12.))
63 .text_color(if cell.in_month {
64 theme::text()
65 } else {
66 theme::text_faint()
67 })
68 .when(cell.today, |circle| {
69 circle
70 .bg(theme::accent())
71 .text_color(theme::on_accent())
72 .font_weight(FontWeight::SEMIBOLD)
73 })
74 .when(!cell.today, |circle| {
75 circle.hover(|circle| circle.bg(theme::border_strong()))
76 })
77 .child(date.day().to_string()),
78 )
79 .on_click(move |_, window, cx| pick(date, window, cx))
80 }))
81 })
82 .collect::<Vec<_>>();
83 v_flex()
84 .child(h_flex().children(weekday_letters(first_day).map(|letter| {
85 div()
86 .size(px(cell_size))
87 .flex()
88 .items_center()
89 .justify_center()
90 .text_size(px(11.))
91 .text_color(theme::text_muted())
92 .child(letter)
93 })))
94 .children(weeks)
95 }
@@ -0,0 +1,95 @@
1//! Mini month grid shared by the date picker popover and the calendar list pane.
2
3use std::rc::Rc;
4
5use chrono::{Datelike, Duration, NaiveDate, Weekday};
6use gpui_kit::component::{h_flex, v_flex};
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9
10use crate::call::calendar_list::mini_month_cell;
11use crate::call::week_grid::{MONTH_GRID_DAYS, month_grid_start};
12use crate::theme;
13
14pub type PickDate = Rc<dyn Fn(NaiveDate, &mut Window, &mut App)>;
15
16/// Weekday initials in column order from the first day, in the app language.
17pub fn weekday_letters(first_day: Weekday) -> [String; 7] {
18 let mut day = first_day;
19 std::array::from_fn(|_| {
20 let letter = app_base::format::weekday_name(day, app_base::format::WeekdayWidth::Letter);
21 day = day.succ();
22 letter
23 })
24}
25
26/// Weekday initials and six weeks of day cells; the shown range is a band, today a circle.
27#[allow(clippy::too_many_arguments)]
28pub fn mini_month_grid(
29 id: &'static str,
30 month: NaiveDate,
31 shown: &[NaiveDate],
32 first_day: Weekday,
33 today: NaiveDate,
34 cell_size: f32,
35 on_pick: PickDate,
36) -> Div {
37 let start = month_grid_start(month, first_day);
38 let weeks = (0..MONTH_GRID_DAYS)
39 .map(|offset| start + Duration::days(offset))
40 .collect::<Vec<_>>()
41 .chunks(7)
42 .map(|week| {
43 h_flex().children(week.iter().map(|date| {
44 let cell = mini_month_cell(*date, month, shown, today);
45 let pick = on_pick.clone();
46 let date = *date;
47 div()
48 .id(SharedString::from(format!("{id}-{date}")))
49 .size(px(cell_size))
50 .flex()
51 .items_center()
52 .justify_center()
53 .when(cell.shown, |band| band.bg(theme::popup_hover()))
54 .child(
55 div()
56 .size(px(cell_size - 4.))
57 .flex()
58 .items_center()
59 .justify_center()
60 .rounded_full()
61 .cursor_pointer()
62 .text_size(px(12.))
63 .text_color(if cell.in_month {
64 theme::text()
65 } else {
66 theme::text_faint()
67 })
68 .when(cell.today, |circle| {
69 circle
70 .bg(theme::accent())
71 .text_color(theme::on_accent())
72 .font_weight(FontWeight::SEMIBOLD)
73 })
74 .when(!cell.today, |circle| {
75 circle.hover(|circle| circle.bg(theme::border_strong()))
76 })
77 .child(date.day().to_string()),
78 )
79 .on_click(move |_, window, cx| pick(date, window, cx))
80 }))
81 })
82 .collect::<Vec<_>>();
83 v_flex()
84 .child(h_flex().children(weekday_letters(first_day).map(|letter| {
85 div()
86 .size(px(cell_size))
87 .flex()
88 .items_center()
89 .justify_center()
90 .text_size(px(11.))
91 .text_color(theme::text_muted())
92 .child(letter)
93 })))
94 .children(weeks)
95}
crates/app/src/views/calendar_picker.rs +335 −77
@@ -1,21 +1,40 @@
1 //! Calendar list pane left of the grid, laid out like Teams: heading, mini month,
2 //! Add calendar, and one collapsible group per account with show/hide boxes.
3
4 use std::rc::Rc;
5
6 use chrono::Local;
1 7 use gpui_kit::assets::IconName;
8 use gpui_kit::component::Sizable as _;
9 use gpui_kit::component::button::{Button, ButtonVariants as _};
2 10 use gpui_kit::component::{h_flex, v_flex};
3 11 use gpui_kit::prelude::FluentBuilder as _;
4 12 use gpui_kit::*;
5 use store::CalendarAccounts;
13 use store::{CalendarAccounts, GoogleAccount};
6 14
15 use super::calendar_mini_month::mini_month_grid;
7 16 use crate::app_state::AppState;
17 use crate::call::calendar_list::{GroupCheck, group_check, listed_calendars, offers_show_all};
18 use crate::call::calendar_prefs::OUTLOOK_GROUP;
19 use crate::call::week_grid::google_calendar_index;
20 use crate::i18n::tr;
21 use crate::settings_section::SettingsSection;
8 22 use crate::theme;
9 23 use crate::views::widgets::icon;
10 24
11 pub const PICKER_WIDTH: f32 = 220.;
25 pub const PICKER_WIDTH: f32 = 236.;
26 pub const CALENDAR_PANE_TAG: &str = "shell/islands/calendar/picker";
27 pub const MINI_MONTH_TAG: &str = "shell/islands/calendar/picker/mini-month";
12 28 const ROW_HEIGHT: f32 = 28.;
29 const MINI_CELL: f32 = 30.;
30 const CHECK_SIZE: f32 = 14.;
13 31
14 /// Teams-like calendar list: Outlook + each connected Google calendar with show toggles.
15 32 pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
16 let accounts = app.read(cx).calendar_accounts();
33 let state = app.read(cx);
34 let accounts = state.calendar_accounts();
35 let prefs = &state.calendar_prefs;
17 36 let mut column = v_flex()
18 .debug_selector(|| "shell/islands/calendar/picker".into())
37 .debug_selector(|| CALENDAR_PANE_TAG.into())
19 38 .w(px(PICKER_WIDTH))
20 39 .flex_none()
21 40 .h_full()
@@ -27,76 +46,293 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
27 46 .gap(px(4.))
28 47 .child(
29 48 div()
30 .text_size(px(11.))
31 .font_weight(FontWeight::SEMIBOLD)
32 .text_color(theme::text_muted())
33 .mb(px(6.))
34 .child("CALENDARS"),
49 .text_size(px(16.))
50 .font_weight(FontWeight::BOLD)
51 .text_color(theme::text())
52 .pb(px(8.))
53 .child(tr("calendar.view.title")),
35 54 )
36 .child(outlook_row(app, &accounts));
55 .child(mini_month(app, state))
56 .child(add_calendar_row(app))
57 .child(outlook_group(
58 app,
59 &accounts,
60 prefs.group_collapsed(OUTLOOK_GROUP),
61 ));
37 62 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 );
63 column = column.child(google_group(
64 app,
65 &accounts,
66 account,
67 prefs.group_collapsed(&account.id),
68 state.calendar_expanded_groups.contains(&account.id),
69 ));
78 70 }
79 71 column
80 72 }
81 73
82 fn outlook_row(app: &Entity<AppState>, accounts: &CalendarAccounts) -> Stateful<Div> {
74 /// Mini month with its own month arrows; a click shows the span around that day.
75 fn mini_month(app: &Entity<AppState>, state: &AppState) -> Div {
76 let month = state.calendar_mini_month_shown();
77 let (back, forward, pick) = (app.clone(), app.clone(), app.clone());
78 v_flex()
79 .debug_selector(|| MINI_MONTH_TAG.into())
80 .pb(px(8.))
81 .child(
82 h_flex()
83 .items_center()
84 .justify_between()
85 .pb(px(4.))
86 .child(
87 div()
88 .pl(px(4.))
89 .text_size(px(13.))
90 .font_weight(FontWeight::SEMIBOLD)
91 .text_color(theme::text())
92 .child(app_base::format::month_year_label(month)),
93 )
94 .child(
95 h_flex()
96 .child(
97 Button::new("calendar-mini-back")
98 .xsmall()
99 .ghost()
100 .icon(IconName::ChevronUp)
101 .tooltip(tr("calendar.view.previous_month_short"))
102 .on_click(move |_, _, cx| {
103 back.update(cx, |state, cx| {
104 state.move_calendar_mini_month(-1, cx)
105 })
106 }),
107 )
108 .child(
109 Button::new("calendar-mini-forward")
110 .xsmall()
111 .ghost()
112 .icon(IconName::ChevronDown)
113 .tooltip(tr("calendar.view.next_month_short"))
114 .on_click(move |_, _, cx| {
115 forward.update(cx, |state, cx| {
116 state.move_calendar_mini_month(1, cx)
117 })
118 }),
119 ),
120 ),
121 )
122 .child(mini_month_grid(
123 "calendar-mini",
124 month,
125 &state.calendar_dates(),
126 state.calendar_layout().first_day,
127 Local::now().date_naive(),
128 MINI_CELL,
129 Rc::new(move |date, _, cx| {
130 pick.update(cx, |state, cx| state.show_calendar_date(date, cx))
131 }),
132 ))
133 }
134
135 fn add_calendar_row(app: &Entity<AppState>) -> Stateful<Div> {
83 136 let app = app.clone();
84 toggle_row(
85 "calendar-picker-outlook",
86 "Outlook",
87 accounts.outlook_selected,
88 theme::accent(),
137 h_flex()
138 .id("calendar-add-calendar")
139 .h(px(ROW_HEIGHT))
140 .flex_none()
141 .w_full()
142 .items_center()
143 .gap(px(8.))
144 .px(px(4.))
145 .rounded(px(6.))
146 .cursor_pointer()
147 .hover(|row| row.bg(theme::popup_hover()))
148 .text_size(px(13.))
149 .text_color(theme::accent_text())
150 .child(icon(IconName::Plus, 14., theme::accent_text()))
151 .child(tr("calendar.view.add_calendar"))
152 .on_click(move |_, _, cx| {
153 app.update(cx, |state, cx| {
154 state.open_settings(SettingsSection::Calendar, cx)
155 })
156 })
157 }
158
159 fn outlook_group(app: &Entity<AppState>, accounts: &CalendarAccounts, collapsed: bool) -> Div {
160 let on = accounts.outlook_selected;
161 let (toggle_group, toggle_row) = (app.clone(), app.clone());
162 let collapse = app.clone();
163 group(
164 format!("calendar-group-{OUTLOOK_GROUP}"),
165 tr("calendar.view.my_calendars"),
166 if on {
167 GroupCheck::All
168 } else {
169 GroupCheck::None
170 },
171 collapsed,
172 move |cx| toggle_group.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx)),
173 move |cx| {
174 collapse.update(cx, |state, cx| {
175 state.update_calendar_prefs(|prefs| prefs.toggle_group(OUTLOOK_GROUP), cx)
176 })
177 },
178 )
179 .when(!collapsed, |group| {
180 group.child(calendar_row(
181 "calendar-picker-outlook",
182 "Outlook".to_owned(),
183 on,
184 theme::calendar_color(0),
185 move |cx| toggle_row.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx)),
186 ))
187 })
188 }
189
190 fn google_group(
191 app: &Entity<AppState>,
192 accounts: &CalendarAccounts,
193 account: &GoogleAccount,
194 collapsed: bool,
195 expanded: bool,
196 ) -> Div {
197 let selected: Vec<bool> = account
198 .calendars
199 .iter()
200 .map(|calendar| calendar.selected)
201 .collect();
202 let primary: Vec<bool> = account
203 .calendars
204 .iter()
205 .map(|calendar| calendar.primary)
206 .collect();
207 let check = group_check(&selected);
208 let (toggle_group, collapse, expand) = (app.clone(), app.clone(), app.clone());
209 let (group_id, collapse_id, expand_id) =
210 (account.id.clone(), account.id.clone(), account.id.clone());
211 let mut body = group(
212 format!("calendar-group-{}", account.id),
213 account.email.clone(),
214 check,
215 collapsed,
89 216 move |cx| {
90 app.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx));
217 toggle_group.update(cx, |state, cx| {
218 state.set_google_account_selected(&group_id, check != GroupCheck::All, cx)
219 })
91 220 },
221 move |cx| {
222 collapse.update(cx, |state, cx| {
223 state.update_calendar_prefs(|prefs| prefs.toggle_group(&collapse_id), cx)
224 })
225 },
226 );
227 if collapsed {
228 return body;
229 }
230 for index in listed_calendars(&selected, &primary, expanded) {
231 let calendar = &account.calendars[index];
232 let toggle = app.clone();
233 let (account_id, calendar_id) = (account.id.clone(), calendar.id.clone());
234 let color = google_calendar_index(accounts, &account.id, &calendar.id)
235 .map_or_else(theme::accent, theme::calendar_color);
236 body = body.child(calendar_row(
237 format!("calendar-picker-{}-{}", account.id, calendar.id),
238 calendar.summary.clone(),
239 calendar.selected,
240 color,
241 move |cx| {
242 toggle.update(cx, |state, cx| {
243 state.toggle_google_calendar_selected(&account_id, &calendar_id, cx)
244 });
245 },
246 ));
247 }
248 if offers_show_all(account.calendars.len()) {
249 body = body.child(
250 div()
251 .id(SharedString::from(format!(
252 "calendar-show-all-{}",
253 account.id
254 )))
255 .pl(px(28.))
256 .h(px(ROW_HEIGHT))
257 .flex_none()
258 .flex()
259 .items_center()
260 .cursor_pointer()
261 .text_size(px(12.))
262 .text_color(theme::accent_text())
263 .child(if expanded {
264 tr("calendar.view.show_fewer")
265 } else {
266 tr("calendar.view.show_all")
267 })
268 .on_click(move |_, _, cx| {
269 expand.update(cx, |state, cx| {
270 state.toggle_calendar_group_expanded(&expand_id, cx)
271 })
272 }),
273 );
274 }
275 body
276 }
277
278 /// Group header: chevron to collapse, a check box for the whole group, the title.
279 fn group(
280 id: String,
281 title: String,
282 check: GroupCheck,
283 collapsed: bool,
284 toggle: impl Fn(&mut App) + 'static,
285 collapse: impl Fn(&mut App) + 'static,
286 ) -> Div {
287 v_flex().w_full().pt(px(6.)).child(
288 h_flex()
289 .h(px(ROW_HEIGHT))
290 .flex_none()
291 .w_full()
292 .items_center()
293 .gap(px(6.))
294 .child(
295 div()
296 .id(SharedString::from(format!("{id}-chevron")))
297 .flex_none()
298 .cursor_pointer()
299 .child(icon(
300 if collapsed {
301 IconName::ChevronRight
302 } else {
303 IconName::ChevronDown
304 },
305 14.,
306 theme::text_muted(),
307 ))
308 .on_click(move |_, _, cx| collapse(cx)),
309 )
310 .child(
311 div()
312 .id(SharedString::from(format!("{id}-check")))
313 .flex_none()
314 .cursor_pointer()
315 .child(check_box(check, theme::accent()))
316 .on_click(move |_, _, cx| toggle(cx)),
317 )
318 .child(
319 div()
320 .flex_1()
321 .min_w_0()
322 .truncate()
323 .text_size(px(13.))
324 .font_weight(FontWeight::SEMIBOLD)
325 .text_color(theme::text())
326 .child(title),
327 ),
92 328 )
93 329 }
94 330
95 fn toggle_row(
331 fn calendar_row(
96 332 id: impl Into<ElementId>,
97 label: impl Into<SharedString>,
333 label: String,
98 334 on: bool,
99 swatch: Hsla,
335 color: Hsla,
100 336 on_click: impl Fn(&mut App) + 'static,
101 337 ) -> Stateful<Div> {
102 338 h_flex()
@@ -106,25 +342,20 @@ fn toggle_row(
106 342 .w_full()
107 343 .items_center()
108 344 .gap(px(8.))
345 .pl(px(24.))
346 .pr(px(4.))
109 347 .rounded(px(6.))
110 .px(px(4.))
111 348 .cursor_pointer()
112 349 .hover(|row| row.bg(theme::popup_hover()))
113 350 .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 )
351 .child(check_box(
352 if on {
353 GroupCheck::All
354 } else {
355 GroupCheck::None
356 },
357 color,
358 ))
128 359 .child(
129 360 div()
130 361 .flex_1()
@@ -132,6 +363,33 @@ fn toggle_row(
132 363 .truncate()
133 364 .text_size(px(13.))
134 365 .text_color(theme::text())
135 .child(label.into()),
366 .child(label),
136 367 )
137 368 }
369
370 /// Check box in the calendar's colour: filled with a tick when on, a dash when partly on.
371 fn check_box(check: GroupCheck, color: Hsla) -> Div {
372 div()
373 .size(px(CHECK_SIZE))
374 .flex_none()
375 .flex()
376 .items_center()
377 .justify_center()
378 .rounded(px(3.))
379 .map(|check_box| match check {
380 GroupCheck::All => {
381 check_box
382 .bg(color)
383 .child(icon(IconName::Check, 10., theme::on_accent()))
384 }
385 GroupCheck::Some => check_box.bg(color.opacity(0.5)).child(
386 div()
387 .w(px(8.))
388 .h(px(2.))
389 .rounded_full()
390 .bg(theme::on_accent()),
391 ),
392 // Lines stay soft: an empty box is a light fill of the calendar colour.
393 GroupCheck::None => check_box.bg(color.opacity(0.22)),
394 })
395 }
@@ -1,21 +1,40 @@
1//! Calendar list pane left of the grid, laid out like Teams: heading, mini month,
2//! Add calendar, and one collapsible group per account with show/hide boxes.
3
4use std::rc::Rc;
5
6use chrono::Local;
1use gpui_kit::assets::IconName;
7use gpui_kit::assets::IconName;
8use gpui_kit::component::Sizable as _;
9use gpui_kit::component::button::{Button, ButtonVariants as _};
2use gpui_kit::component::{h_flex, v_flex};
10use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
11use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
12use gpui_kit::*;
5use store::CalendarAccounts;
13use store::{CalendarAccounts, GoogleAccount};
6
14
15use super::calendar_mini_month::mini_month_grid;
7use crate::app_state::AppState;
16use crate::app_state::AppState;
17use crate::call::calendar_list::{GroupCheck, group_check, listed_calendars, offers_show_all};
18use crate::call::calendar_prefs::OUTLOOK_GROUP;
19use crate::call::week_grid::google_calendar_index;
20use crate::i18n::tr;
21use crate::settings_section::SettingsSection;
8use crate::theme;
22use crate::theme;
9use crate::views::widgets::icon;
23use crate::views::widgets::icon;
10
24
11pub const PICKER_WIDTH: f32 = 220.;
25pub const PICKER_WIDTH: f32 = 236.;
26pub const CALENDAR_PANE_TAG: &str = "shell/islands/calendar/picker";
27pub const MINI_MONTH_TAG: &str = "shell/islands/calendar/picker/mini-month";
12const ROW_HEIGHT: f32 = 28.;
28const ROW_HEIGHT: f32 = 28.;
29const MINI_CELL: f32 = 30.;
30const CHECK_SIZE: f32 = 14.;
13
31
14/// Teams-like calendar list: Outlook + each connected Google calendar with show toggles.
15pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
32pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
16 let accounts = app.read(cx).calendar_accounts();
33 let state = app.read(cx);
34 let accounts = state.calendar_accounts();
35 let prefs = &state.calendar_prefs;
17 let mut column = v_flex()
36 let mut column = v_flex()
18 .debug_selector(|| "shell/islands/calendar/picker".into())
37 .debug_selector(|| CALENDAR_PANE_TAG.into())
19 .w(px(PICKER_WIDTH))
38 .w(px(PICKER_WIDTH))
20 .flex_none()
39 .flex_none()
21 .h_full()
40 .h_full()
@@ -27,76 +46,293 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
27 .gap(px(4.))
46 .gap(px(4.))
28 .child(
47 .child(
29 div()
48 div()
30 .text_size(px(11.))
49 .text_size(px(16.))
31 .font_weight(FontWeight::SEMIBOLD)
50 .font_weight(FontWeight::BOLD)
32 .text_color(theme::text_muted())
51 .text_color(theme::text())
33 .mb(px(6.))
52 .pb(px(8.))
34 .child("CALENDARS"),
53 .child(tr("calendar.view.title")),
35 )
54 )
36 .child(outlook_row(app, &accounts));
55 .child(mini_month(app, state))
56 .child(add_calendar_row(app))
57 .child(outlook_group(
58 app,
59 &accounts,
60 prefs.group_collapsed(OUTLOOK_GROUP),
61 ));
37 for account in &accounts.google_accounts {
62 for account in &accounts.google_accounts {
38 column = column.child(
63 column = column.child(google_group(
39 div()
64 app,
40 .mt(px(8.))
65 &accounts,
41 .mb(px(2.))
66 account,
42 .text_size(px(11.))
67 prefs.group_collapsed(&account.id),
43 .font_weight(FontWeight::SEMIBOLD)
68 state.calendar_expanded_groups.contains(&account.id),
44 .text_color(theme::text_muted())
69 ));
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 }
70 }
79 column
71 column
80}
72}
81
73
82fn outlook_row(app: &Entity<AppState>, accounts: &CalendarAccounts) -> Stateful<Div> {
74/// Mini month with its own month arrows; a click shows the span around that day.
75fn mini_month(app: &Entity<AppState>, state: &AppState) -> Div {
76 let month = state.calendar_mini_month_shown();
77 let (back, forward, pick) = (app.clone(), app.clone(), app.clone());
78 v_flex()
79 .debug_selector(|| MINI_MONTH_TAG.into())
80 .pb(px(8.))
81 .child(
82 h_flex()
83 .items_center()
84 .justify_between()
85 .pb(px(4.))
86 .child(
87 div()
88 .pl(px(4.))
89 .text_size(px(13.))
90 .font_weight(FontWeight::SEMIBOLD)
91 .text_color(theme::text())
92 .child(app_base::format::month_year_label(month)),
93 )
94 .child(
95 h_flex()
96 .child(
97 Button::new("calendar-mini-back")
98 .xsmall()
99 .ghost()
100 .icon(IconName::ChevronUp)
101 .tooltip(tr("calendar.view.previous_month_short"))
102 .on_click(move |_, _, cx| {
103 back.update(cx, |state, cx| {
104 state.move_calendar_mini_month(-1, cx)
105 })
106 }),
107 )
108 .child(
109 Button::new("calendar-mini-forward")
110 .xsmall()
111 .ghost()
112 .icon(IconName::ChevronDown)
113 .tooltip(tr("calendar.view.next_month_short"))
114 .on_click(move |_, _, cx| {
115 forward.update(cx, |state, cx| {
116 state.move_calendar_mini_month(1, cx)
117 })
118 }),
119 ),
120 ),
121 )
122 .child(mini_month_grid(
123 "calendar-mini",
124 month,
125 &state.calendar_dates(),
126 state.calendar_layout().first_day,
127 Local::now().date_naive(),
128 MINI_CELL,
129 Rc::new(move |date, _, cx| {
130 pick.update(cx, |state, cx| state.show_calendar_date(date, cx))
131 }),
132 ))
133}
134
135fn add_calendar_row(app: &Entity<AppState>) -> Stateful<Div> {
83 let app = app.clone();
136 let app = app.clone();
84 toggle_row(
137 h_flex()
85 "calendar-picker-outlook",
138 .id("calendar-add-calendar")
86 "Outlook",
139 .h(px(ROW_HEIGHT))
87 accounts.outlook_selected,
140 .flex_none()
88 theme::accent(),
141 .w_full()
142 .items_center()
143 .gap(px(8.))
144 .px(px(4.))
145 .rounded(px(6.))
146 .cursor_pointer()
147 .hover(|row| row.bg(theme::popup_hover()))
148 .text_size(px(13.))
149 .text_color(theme::accent_text())
150 .child(icon(IconName::Plus, 14., theme::accent_text()))
151 .child(tr("calendar.view.add_calendar"))
152 .on_click(move |_, _, cx| {
153 app.update(cx, |state, cx| {
154 state.open_settings(SettingsSection::Calendar, cx)
155 })
156 })
157}
158
159fn outlook_group(app: &Entity<AppState>, accounts: &CalendarAccounts, collapsed: bool) -> Div {
160 let on = accounts.outlook_selected;
161 let (toggle_group, toggle_row) = (app.clone(), app.clone());
162 let collapse = app.clone();
163 group(
164 format!("calendar-group-{OUTLOOK_GROUP}"),
165 tr("calendar.view.my_calendars"),
166 if on {
167 GroupCheck::All
168 } else {
169 GroupCheck::None
170 },
171 collapsed,
172 move |cx| toggle_group.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx)),
173 move |cx| {
174 collapse.update(cx, |state, cx| {
175 state.update_calendar_prefs(|prefs| prefs.toggle_group(OUTLOOK_GROUP), cx)
176 })
177 },
178 )
179 .when(!collapsed, |group| {
180 group.child(calendar_row(
181 "calendar-picker-outlook",
182 "Outlook".to_owned(),
183 on,
184 theme::calendar_color(0),
185 move |cx| toggle_row.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx)),
186 ))
187 })
188}
189
190fn google_group(
191 app: &Entity<AppState>,
192 accounts: &CalendarAccounts,
193 account: &GoogleAccount,
194 collapsed: bool,
195 expanded: bool,
196) -> Div {
197 let selected: Vec<bool> = account
198 .calendars
199 .iter()
200 .map(|calendar| calendar.selected)
201 .collect();
202 let primary: Vec<bool> = account
203 .calendars
204 .iter()
205 .map(|calendar| calendar.primary)
206 .collect();
207 let check = group_check(&selected);
208 let (toggle_group, collapse, expand) = (app.clone(), app.clone(), app.clone());
209 let (group_id, collapse_id, expand_id) =
210 (account.id.clone(), account.id.clone(), account.id.clone());
211 let mut body = group(
212 format!("calendar-group-{}", account.id),
213 account.email.clone(),
214 check,
215 collapsed,
89 move |cx| {
216 move |cx| {
90 app.update(cx, |state, cx| state.toggle_outlook_calendar_selected(cx));
217 toggle_group.update(cx, |state, cx| {
218 state.set_google_account_selected(&group_id, check != GroupCheck::All, cx)
219 })
91 },
220 },
221 move |cx| {
222 collapse.update(cx, |state, cx| {
223 state.update_calendar_prefs(|prefs| prefs.toggle_group(&collapse_id), cx)
224 })
225 },
226 );
227 if collapsed {
228 return body;
229 }
230 for index in listed_calendars(&selected, &primary, expanded) {
231 let calendar = &account.calendars[index];
232 let toggle = app.clone();
233 let (account_id, calendar_id) = (account.id.clone(), calendar.id.clone());
234 let color = google_calendar_index(accounts, &account.id, &calendar.id)
235 .map_or_else(theme::accent, theme::calendar_color);
236 body = body.child(calendar_row(
237 format!("calendar-picker-{}-{}", account.id, calendar.id),
238 calendar.summary.clone(),
239 calendar.selected,
240 color,
241 move |cx| {
242 toggle.update(cx, |state, cx| {
243 state.toggle_google_calendar_selected(&account_id, &calendar_id, cx)
244 });
245 },
246 ));
247 }
248 if offers_show_all(account.calendars.len()) {
249 body = body.child(
250 div()
251 .id(SharedString::from(format!(
252 "calendar-show-all-{}",
253 account.id
254 )))
255 .pl(px(28.))
256 .h(px(ROW_HEIGHT))
257 .flex_none()
258 .flex()
259 .items_center()
260 .cursor_pointer()
261 .text_size(px(12.))
262 .text_color(theme::accent_text())
263 .child(if expanded {
264 tr("calendar.view.show_fewer")
265 } else {
266 tr("calendar.view.show_all")
267 })
268 .on_click(move |_, _, cx| {
269 expand.update(cx, |state, cx| {
270 state.toggle_calendar_group_expanded(&expand_id, cx)
271 })
272 }),
273 );
274 }
275 body
276}
277
278/// Group header: chevron to collapse, a check box for the whole group, the title.
279fn group(
280 id: String,
281 title: String,
282 check: GroupCheck,
283 collapsed: bool,
284 toggle: impl Fn(&mut App) + 'static,
285 collapse: impl Fn(&mut App) + 'static,
286) -> Div {
287 v_flex().w_full().pt(px(6.)).child(
288 h_flex()
289 .h(px(ROW_HEIGHT))
290 .flex_none()
291 .w_full()
292 .items_center()
293 .gap(px(6.))
294 .child(
295 div()
296 .id(SharedString::from(format!("{id}-chevron")))
297 .flex_none()
298 .cursor_pointer()
299 .child(icon(
300 if collapsed {
301 IconName::ChevronRight
302 } else {
303 IconName::ChevronDown
304 },
305 14.,
306 theme::text_muted(),
307 ))
308 .on_click(move |_, _, cx| collapse(cx)),
309 )
310 .child(
311 div()
312 .id(SharedString::from(format!("{id}-check")))
313 .flex_none()
314 .cursor_pointer()
315 .child(check_box(check, theme::accent()))
316 .on_click(move |_, _, cx| toggle(cx)),
317 )
318 .child(
319 div()
320 .flex_1()
321 .min_w_0()
322 .truncate()
323 .text_size(px(13.))
324 .font_weight(FontWeight::SEMIBOLD)
325 .text_color(theme::text())
326 .child(title),
327 ),
92 )
328 )
93}
329}
94
330
95fn toggle_row(
331fn calendar_row(
96 id: impl Into<ElementId>,
332 id: impl Into<ElementId>,
97 label: impl Into<SharedString>,
333 label: String,
98 on: bool,
334 on: bool,
99 swatch: Hsla,
335 color: Hsla,
100 on_click: impl Fn(&mut App) + 'static,
336 on_click: impl Fn(&mut App) + 'static,
101) -> Stateful<Div> {
337) -> Stateful<Div> {
102 h_flex()
338 h_flex()
@@ -106,25 +342,20 @@ fn toggle_row(
106 .w_full()
342 .w_full()
107 .items_center()
343 .items_center()
108 .gap(px(8.))
344 .gap(px(8.))
345 .pl(px(24.))
346 .pr(px(4.))
109 .rounded(px(6.))
347 .rounded(px(6.))
110 .px(px(4.))
111 .cursor_pointer()
348 .cursor_pointer()
112 .hover(|row| row.bg(theme::popup_hover()))
349 .hover(|row| row.bg(theme::popup_hover()))
113 .on_click(move |_, _, cx| on_click(cx))
350 .on_click(move |_, _, cx| on_click(cx))
114 .child(
351 .child(check_box(
115 div()
352 if on {
116 .size(px(14.))
353 GroupCheck::All
117 .flex_none()
354 } else {
118 .rounded(px(3.))
355 GroupCheck::None
119 .bg(if on { swatch } else { theme::border() })
356 },
120 .when(on, |box_| {
357 color,
121 box_.flex().items_center().justify_center().child(icon(
358 ))
122 IconName::Check,
123 10.,
124 theme::text(),
125 ))
126 }),
127 )
128 .child(
359 .child(
129 div()
360 div()
130 .flex_1()
361 .flex_1()
@@ -132,6 +363,33 @@ fn toggle_row(
132 .truncate()
363 .truncate()
133 .text_size(px(13.))
364 .text_size(px(13.))
134 .text_color(theme::text())
365 .text_color(theme::text())
135 .child(label.into()),
366 .child(label),
136 )
367 )
137}
368}
369
370/// Check box in the calendar's colour: filled with a tick when on, a dash when partly on.
371fn check_box(check: GroupCheck, color: Hsla) -> Div {
372 div()
373 .size(px(CHECK_SIZE))
374 .flex_none()
375 .flex()
376 .items_center()
377 .justify_center()
378 .rounded(px(3.))
379 .map(|check_box| match check {
380 GroupCheck::All => {
381 check_box
382 .bg(color)
383 .child(icon(IconName::Check, 10., theme::on_accent()))
384 }
385 GroupCheck::Some => check_box.bg(color.opacity(0.5)).child(
386 div()
387 .w(px(8.))
388 .h(px(2.))
389 .rounded_full()
390 .bg(theme::on_accent()),
391 ),
392 // Lines stay soft: an empty box is a light fill of the calendar colour.
393 GroupCheck::None => check_box.bg(color.opacity(0.22)),
394 })
395}
crates/app/src/views/calendar_view.rs +1 −1
@@ -45,7 +45,7 @@ const NOW_ELSEWHERE_OPACITY: f32 = 0.4;
45 45 pub const CALENDAR_HEADER_TAG: &str = "shell/islands/calendar/header";
46 46 pub const CALENDAR_DAY_HEADERS_TAG: &str = "shell/islands/calendar/day-headers";
47 47 pub const CALENDAR_NEW_MEETING_TAG: &str = "shell/islands/calendar/header/new-meeting";
48 const COMPACT_HEADER_WIDTH: f32 = 960.;
48 pub const COMPACT_HEADER_WIDTH: f32 = 960.;
49 49 const BUSY_FILL_OPACITY: f32 = 0.28;
50 50 const FREE_FILL_OPACITY: f32 = 0.12;
51 51 const STATUS_BAR_WIDTH: f32 = 4.;
@@ -45,7 +45,7 @@ const NOW_ELSEWHERE_OPACITY: f32 = 0.4;
45pub const CALENDAR_HEADER_TAG: &str = "shell/islands/calendar/header";
45pub const CALENDAR_HEADER_TAG: &str = "shell/islands/calendar/header";
46pub const CALENDAR_DAY_HEADERS_TAG: &str = "shell/islands/calendar/day-headers";
46pub const CALENDAR_DAY_HEADERS_TAG: &str = "shell/islands/calendar/day-headers";
47pub const CALENDAR_NEW_MEETING_TAG: &str = "shell/islands/calendar/header/new-meeting";
47pub const CALENDAR_NEW_MEETING_TAG: &str = "shell/islands/calendar/header/new-meeting";
48const COMPACT_HEADER_WIDTH: f32 = 960.;
48pub const COMPACT_HEADER_WIDTH: f32 = 960.;
49const BUSY_FILL_OPACITY: f32 = 0.28;
49const BUSY_FILL_OPACITY: f32 = 0.28;
50const FREE_FILL_OPACITY: f32 = 0.12;
50const FREE_FILL_OPACITY: f32 = 0.12;
51const STATUS_BAR_WIDTH: f32 = 4.;
51const STATUS_BAR_WIDTH: f32 = 4.;
crates/app/src/views/mod.rs +1 −0
@@ -8,6 +8,7 @@ pub mod attachments;
8 8 pub mod avatar;
9 9 pub mod calendar_date_picker;
10 10 pub mod calendar_event_dialog;
11 pub mod calendar_mini_month;
11 12 pub mod calendar_month;
12 13 pub mod calendar_picker;
13 14 pub mod calendar_view;
@@ -8,6 +8,7 @@ pub mod attachments;
8pub mod avatar;
8pub mod avatar;
9pub mod calendar_date_picker;
9pub mod calendar_date_picker;
10pub mod calendar_event_dialog;
10pub mod calendar_event_dialog;
11pub mod calendar_mini_month;
11pub mod calendar_month;
12pub mod calendar_month;
12pub mod calendar_picker;
13pub mod calendar_picker;
13pub mod calendar_view;
14pub mod calendar_view;