BlueGit

ict rusty-teams

feat(calendar): calendar in the rail with a work week view

- Calendar rail entry after Channels (Ctrl+Shift+4); the calendar takes the sidebar and main area like Teams
- Work week grid Mon-Fri (coming week on weekends), overlapping meetings in lanes, all-day row, current time line
- Header: Today, previous/next week, month label, Join with an ID, Meet now, New meeting
- Join on running online meetings, click opens the meeting chat; declined meetings hidden, canceled marked
- Week loaded on demand from the calendar view endpoint, stale answers dropped
- Selecting a conversation (search, notification) leaves the calendar; layout guard covers the calendar screen

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
8986570f42e0616a5c39d79a361f5a8bf0c9bb46
Parent
2c1323ee
14 files changed +1008 −24
crates/app-call-model/src/lib.rs +1 −0
@@ -24,3 +24,4 @@ pub mod stage_layout;
24 24 pub mod stage_split;
25 25 pub mod transcript;
26 26 pub mod view_settings;
27 pub mod week_grid;
@@ -24,3 +24,4 @@ pub mod stage_layout;
24pub mod stage_split;
24pub mod stage_split;
25pub mod transcript;
25pub mod transcript;
26pub mod view_settings;
26pub mod view_settings;
27pub mod week_grid;
crates/app-call-model/src/week_grid.rs added +251 −0
@@ -0,0 +1,251 @@
1 use chatsvc::{CalendarEvent, ResponseType};
2 use chrono::{DateTime, Datelike, Duration, FixedOffset, NaiveDate, Utc, Weekday};
3
4 pub const WORK_WEEK_DAYS: i64 = 5;
5 pub const MINUTES_PER_DAY: i64 = 24 * 60;
6
7 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
8 pub struct WeekBlock {
9 pub event_index: usize,
10 pub start_minute: i64,
11 pub end_minute: i64,
12 pub lane: usize,
13 pub lanes: usize,
14 }
15
16 #[derive(Debug, Clone, PartialEq, Eq)]
17 pub struct WeekDay {
18 pub date: NaiveDate,
19 pub all_day: Vec<usize>,
20 pub blocks: Vec<WeekBlock>,
21 }
22
23 pub fn week_start(date: NaiveDate) -> NaiveDate {
24 date - Duration::days(i64::from(date.weekday().num_days_from_monday()))
25 }
26
27 /// On a weekend the work week view shows the coming week, as Outlook does.
28 pub fn work_week_for(today: NaiveDate) -> NaiveDate {
29 match today.weekday() {
30 Weekday::Sat | Weekday::Sun => week_start(today) + Duration::weeks(1),
31 _ => week_start(today),
32 }
33 }
34
35 pub fn local_midnight(date: NaiveDate, offset: FixedOffset) -> DateTime<Utc> {
36 date.and_hms_opt(0, 0, 0)
37 .and_then(|local| local.and_local_timezone(offset).single())
38 .map(|local| local.with_timezone(&Utc))
39 .unwrap_or_else(|| date.and_hms_opt(0, 0, 0).unwrap_or_default().and_utc())
40 }
41
42 pub fn week_range(
43 start: NaiveDate,
44 days: i64,
45 offset: FixedOffset,
46 ) -> (DateTime<Utc>, DateTime<Utc>) {
47 (
48 local_midnight(start, offset),
49 local_midnight(start + Duration::days(days), offset),
50 )
51 }
52
53 pub fn shown_in_calendar(event: &CalendarEvent) -> bool {
54 event.response != ResponseType::Declined
55 }
56
57 pub fn week_days(
58 events: &[CalendarEvent],
59 start: NaiveDate,
60 days: i64,
61 offset: FixedOffset,
62 ) -> Vec<WeekDay> {
63 (0..days)
64 .map(|day| {
65 let date = start + Duration::days(day);
66 let (day_start, day_end) = week_range(date, 1, offset);
67 let mut all_day = Vec::new();
68 let mut spans = Vec::new();
69 for (index, event) in events.iter().enumerate() {
70 if !shown_in_calendar(event) || event.end <= day_start || event.start >= day_end {
71 continue;
72 }
73 if event.all_day {
74 all_day.push(index);
75 continue;
76 }
77 let start_minute = (event.start.max(day_start) - day_start).num_minutes();
78 let end_minute = (event.end.min(day_end) - day_start).num_minutes();
79 spans.push((index, start_minute, end_minute.max(start_minute + 1)));
80 }
81 WeekDay {
82 date,
83 all_day,
84 blocks: lay_out(spans),
85 }
86 })
87 .collect()
88 }
89
90 fn lay_out(mut spans: Vec<(usize, i64, i64)>) -> Vec<WeekBlock> {
91 spans.sort_by_key(|&(index, start, end)| (start, std::cmp::Reverse(end), index));
92 let mut blocks: Vec<WeekBlock> = Vec::with_capacity(spans.len());
93 let mut cluster_start = 0;
94 let mut cluster_end = i64::MIN;
95 let mut lane_ends: Vec<i64> = Vec::new();
96 for (index, start, end) in spans {
97 if start >= cluster_end {
98 close_cluster(&mut blocks[cluster_start..], lane_ends.len());
99 cluster_start = blocks.len();
100 lane_ends.clear();
101 }
102 let lane = match lane_ends.iter().position(|&lane_end| lane_end <= start) {
103 Some(free) => {
104 lane_ends[free] = end;
105 free
106 }
107 None => {
108 lane_ends.push(end);
109 lane_ends.len() - 1
110 }
111 };
112 cluster_end = cluster_end.max(end);
113 blocks.push(WeekBlock {
114 event_index: index,
115 start_minute: start,
116 end_minute: end,
117 lane,
118 lanes: 1,
119 });
120 }
121 close_cluster(&mut blocks[cluster_start..], lane_ends.len());
122 blocks
123 }
124
125 fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {
126 for block in blocks {
127 block.lanes = lanes.max(1);
128 }
129 }
130
131 pub fn range_label(start: NaiveDate, days: i64) -> String {
132 let end = start + Duration::days(days - 1);
133 if start.month() == end.month() {
134 start.format("%B %Y").to_string()
135 } else if start.year() == end.year() {
136 format!("{} - {}", start.format("%B"), end.format("%B %Y"))
137 } else {
138 format!("{} - {}", start.format("%B %Y"), end.format("%B %Y"))
139 }
140 }
141
142 pub fn hour_label(hour: u32) -> String {
143 match hour {
144 0 => "12 AM".to_owned(),
145 12 => "12 PM".to_owned(),
146 hour if hour < 12 => format!("{hour} AM"),
147 hour => format!("{} PM", hour - 12),
148 }
149 }
150
151 #[cfg(test)]
152 mod tests {
153 use chrono::TimeZone;
154
155 use super::*;
156
157 fn event(start_hour: u32, start_minute: u32, minutes: i64) -> CalendarEvent {
158 let start = Utc
159 .with_ymd_and_hms(2026, 11, 9, start_hour, start_minute, 0)
160 .unwrap();
161 CalendarEvent {
162 object_id: format!("{start_hour}:{start_minute}"),
163 subject: "Sync".into(),
164 start,
165 end: start + Duration::minutes(minutes),
166 all_day: false,
167 cancelled: false,
168 online: true,
169 join_url: None,
170 thread_id: None,
171 organizer_name: None,
172 organizer_address: None,
173 ical_uid: None,
174 response: ResponseType::Accepted,
175 }
176 }
177
178 fn utc() -> FixedOffset {
179 FixedOffset::east_opt(0).unwrap()
180 }
181
182 #[test]
183 fn the_week_starts_on_monday() {
184 let sunday = NaiveDate::from_ymd_opt(2026, 11, 15).unwrap();
185 assert_eq!(
186 week_start(sunday),
187 NaiveDate::from_ymd_opt(2026, 11, 9).unwrap()
188 );
189 assert_eq!(week_start(week_start(sunday)), week_start(sunday));
190 assert_eq!(
191 work_week_for(sunday),
192 NaiveDate::from_ymd_opt(2026, 11, 16).unwrap()
193 );
194 let friday = NaiveDate::from_ymd_opt(2026, 11, 13).unwrap();
195 assert_eq!(
196 work_week_for(friday),
197 NaiveDate::from_ymd_opt(2026, 11, 9).unwrap()
198 );
199 }
200
201 #[test]
202 fn overlapping_meetings_share_the_column_in_lanes() {
203 let events = vec![
204 event(9, 0, 60),
205 event(9, 30, 60),
206 event(10, 0, 30),
207 event(13, 0, 30),
208 ];
209 let monday = NaiveDate::from_ymd_opt(2026, 11, 9).unwrap();
210 let days = week_days(&events, monday, WORK_WEEK_DAYS, utc());
211 assert_eq!(days.len(), 5);
212 let lanes: Vec<(usize, usize, usize)> = days[0]
213 .blocks
214 .iter()
215 .map(|block| (block.event_index, block.lane, block.lanes))
216 .collect();
217 assert_eq!(lanes, [(0, 0, 2), (1, 1, 2), (2, 0, 2), (3, 0, 1)]);
218 assert_eq!(days[0].blocks[0].start_minute, 9 * 60);
219 assert!(days[1].blocks.is_empty());
220 }
221
222 #[test]
223 fn declined_and_other_days_are_left_out_and_all_day_is_separate() {
224 let mut declined = event(9, 0, 30);
225 declined.response = ResponseType::Declined;
226 let mut all_day = event(0, 0, 24 * 60);
227 all_day.all_day = true;
228 let late = event(23, 30, 60);
229 let monday = NaiveDate::from_ymd_opt(2026, 11, 9).unwrap();
230 let days = week_days(&[declined, all_day, late], monday, 2, utc());
231 assert!(days[0].blocks.iter().all(|block| block.event_index != 0));
232 assert_eq!(days[0].all_day, [1]);
233 assert_eq!(days[0].blocks[0].end_minute, MINUTES_PER_DAY);
234 assert_eq!(
235 (days[1].blocks[0].start_minute, days[1].blocks[0].end_minute),
236 (0, 30)
237 );
238 }
239
240 #[test]
241 fn labels_read_like_teams() {
242 let monday = NaiveDate::from_ymd_opt(2026, 11, 30).unwrap();
243 assert_eq!(range_label(monday, 5), "November - December 2026");
244 assert_eq!(
245 range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 5),
246 "November 2026"
247 );
248 assert_eq!(hour_label(0), "12 AM");
249 assert_eq!(hour_label(13), "1 PM");
250 }
251 }
@@ -0,0 +1,251 @@
1use chatsvc::{CalendarEvent, ResponseType};
2use chrono::{DateTime, Datelike, Duration, FixedOffset, NaiveDate, Utc, Weekday};
3
4pub const WORK_WEEK_DAYS: i64 = 5;
5pub const MINUTES_PER_DAY: i64 = 24 * 60;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub struct WeekBlock {
9 pub event_index: usize,
10 pub start_minute: i64,
11 pub end_minute: i64,
12 pub lane: usize,
13 pub lanes: usize,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct WeekDay {
18 pub date: NaiveDate,
19 pub all_day: Vec<usize>,
20 pub blocks: Vec<WeekBlock>,
21}
22
23pub fn week_start(date: NaiveDate) -> NaiveDate {
24 date - Duration::days(i64::from(date.weekday().num_days_from_monday()))
25}
26
27/// On a weekend the work week view shows the coming week, as Outlook does.
28pub fn work_week_for(today: NaiveDate) -> NaiveDate {
29 match today.weekday() {
30 Weekday::Sat | Weekday::Sun => week_start(today) + Duration::weeks(1),
31 _ => week_start(today),
32 }
33}
34
35pub fn local_midnight(date: NaiveDate, offset: FixedOffset) -> DateTime<Utc> {
36 date.and_hms_opt(0, 0, 0)
37 .and_then(|local| local.and_local_timezone(offset).single())
38 .map(|local| local.with_timezone(&Utc))
39 .unwrap_or_else(|| date.and_hms_opt(0, 0, 0).unwrap_or_default().and_utc())
40}
41
42pub fn week_range(
43 start: NaiveDate,
44 days: i64,
45 offset: FixedOffset,
46) -> (DateTime<Utc>, DateTime<Utc>) {
47 (
48 local_midnight(start, offset),
49 local_midnight(start + Duration::days(days), offset),
50 )
51}
52
53pub fn shown_in_calendar(event: &CalendarEvent) -> bool {
54 event.response != ResponseType::Declined
55}
56
57pub fn week_days(
58 events: &[CalendarEvent],
59 start: NaiveDate,
60 days: i64,
61 offset: FixedOffset,
62) -> Vec<WeekDay> {
63 (0..days)
64 .map(|day| {
65 let date = start + Duration::days(day);
66 let (day_start, day_end) = week_range(date, 1, offset);
67 let mut all_day = Vec::new();
68 let mut spans = Vec::new();
69 for (index, event) in events.iter().enumerate() {
70 if !shown_in_calendar(event) || event.end <= day_start || event.start >= day_end {
71 continue;
72 }
73 if event.all_day {
74 all_day.push(index);
75 continue;
76 }
77 let start_minute = (event.start.max(day_start) - day_start).num_minutes();
78 let end_minute = (event.end.min(day_end) - day_start).num_minutes();
79 spans.push((index, start_minute, end_minute.max(start_minute + 1)));
80 }
81 WeekDay {
82 date,
83 all_day,
84 blocks: lay_out(spans),
85 }
86 })
87 .collect()
88}
89
90fn lay_out(mut spans: Vec<(usize, i64, i64)>) -> Vec<WeekBlock> {
91 spans.sort_by_key(|&(index, start, end)| (start, std::cmp::Reverse(end), index));
92 let mut blocks: Vec<WeekBlock> = Vec::with_capacity(spans.len());
93 let mut cluster_start = 0;
94 let mut cluster_end = i64::MIN;
95 let mut lane_ends: Vec<i64> = Vec::new();
96 for (index, start, end) in spans {
97 if start >= cluster_end {
98 close_cluster(&mut blocks[cluster_start..], lane_ends.len());
99 cluster_start = blocks.len();
100 lane_ends.clear();
101 }
102 let lane = match lane_ends.iter().position(|&lane_end| lane_end <= start) {
103 Some(free) => {
104 lane_ends[free] = end;
105 free
106 }
107 None => {
108 lane_ends.push(end);
109 lane_ends.len() - 1
110 }
111 };
112 cluster_end = cluster_end.max(end);
113 blocks.push(WeekBlock {
114 event_index: index,
115 start_minute: start,
116 end_minute: end,
117 lane,
118 lanes: 1,
119 });
120 }
121 close_cluster(&mut blocks[cluster_start..], lane_ends.len());
122 blocks
123}
124
125fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {
126 for block in blocks {
127 block.lanes = lanes.max(1);
128 }
129}
130
131pub fn range_label(start: NaiveDate, days: i64) -> String {
132 let end = start + Duration::days(days - 1);
133 if start.month() == end.month() {
134 start.format("%B %Y").to_string()
135 } else if start.year() == end.year() {
136 format!("{} - {}", start.format("%B"), end.format("%B %Y"))
137 } else {
138 format!("{} - {}", start.format("%B %Y"), end.format("%B %Y"))
139 }
140}
141
142pub fn hour_label(hour: u32) -> String {
143 match hour {
144 0 => "12 AM".to_owned(),
145 12 => "12 PM".to_owned(),
146 hour if hour < 12 => format!("{hour} AM"),
147 hour => format!("{} PM", hour - 12),
148 }
149}
150
151#[cfg(test)]
152mod tests {
153 use chrono::TimeZone;
154
155 use super::*;
156
157 fn event(start_hour: u32, start_minute: u32, minutes: i64) -> CalendarEvent {
158 let start = Utc
159 .with_ymd_and_hms(2026, 11, 9, start_hour, start_minute, 0)
160 .unwrap();
161 CalendarEvent {
162 object_id: format!("{start_hour}:{start_minute}"),
163 subject: "Sync".into(),
164 start,
165 end: start + Duration::minutes(minutes),
166 all_day: false,
167 cancelled: false,
168 online: true,
169 join_url: None,
170 thread_id: None,
171 organizer_name: None,
172 organizer_address: None,
173 ical_uid: None,
174 response: ResponseType::Accepted,
175 }
176 }
177
178 fn utc() -> FixedOffset {
179 FixedOffset::east_opt(0).unwrap()
180 }
181
182 #[test]
183 fn the_week_starts_on_monday() {
184 let sunday = NaiveDate::from_ymd_opt(2026, 11, 15).unwrap();
185 assert_eq!(
186 week_start(sunday),
187 NaiveDate::from_ymd_opt(2026, 11, 9).unwrap()
188 );
189 assert_eq!(week_start(week_start(sunday)), week_start(sunday));
190 assert_eq!(
191 work_week_for(sunday),
192 NaiveDate::from_ymd_opt(2026, 11, 16).unwrap()
193 );
194 let friday = NaiveDate::from_ymd_opt(2026, 11, 13).unwrap();
195 assert_eq!(
196 work_week_for(friday),
197 NaiveDate::from_ymd_opt(2026, 11, 9).unwrap()
198 );
199 }
200
201 #[test]
202 fn overlapping_meetings_share_the_column_in_lanes() {
203 let events = vec![
204 event(9, 0, 60),
205 event(9, 30, 60),
206 event(10, 0, 30),
207 event(13, 0, 30),
208 ];
209 let monday = NaiveDate::from_ymd_opt(2026, 11, 9).unwrap();
210 let days = week_days(&events, monday, WORK_WEEK_DAYS, utc());
211 assert_eq!(days.len(), 5);
212 let lanes: Vec<(usize, usize, usize)> = days[0]
213 .blocks
214 .iter()
215 .map(|block| (block.event_index, block.lane, block.lanes))
216 .collect();
217 assert_eq!(lanes, [(0, 0, 2), (1, 1, 2), (2, 0, 2), (3, 0, 1)]);
218 assert_eq!(days[0].blocks[0].start_minute, 9 * 60);
219 assert!(days[1].blocks.is_empty());
220 }
221
222 #[test]
223 fn declined_and_other_days_are_left_out_and_all_day_is_separate() {
224 let mut declined = event(9, 0, 30);
225 declined.response = ResponseType::Declined;
226 let mut all_day = event(0, 0, 24 * 60);
227 all_day.all_day = true;
228 let late = event(23, 30, 60);
229 let monday = NaiveDate::from_ymd_opt(2026, 11, 9).unwrap();
230 let days = week_days(&[declined, all_day, late], monday, 2, utc());
231 assert!(days[0].blocks.iter().all(|block| block.event_index != 0));
232 assert_eq!(days[0].all_day, [1]);
233 assert_eq!(days[0].blocks[0].end_minute, MINUTES_PER_DAY);
234 assert_eq!(
235 (days[1].blocks[0].start_minute, days[1].blocks[0].end_minute),
236 (0, 30)
237 );
238 }
239
240 #[test]
241 fn labels_read_like_teams() {
242 let monday = NaiveDate::from_ymd_opt(2026, 11, 30).unwrap();
243 assert_eq!(range_label(monday, 5), "November - December 2026");
244 assert_eq!(
245 range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 5),
246 "November 2026"
247 );
248 assert_eq!(hour_label(0), "12 AM");
249 assert_eq!(hour_label(13), "1 PM");
250 }
251}
crates/app-state/src/app_state.rs +2 −0
@@ -179,6 +179,7 @@ pub struct AppState {
179 179 pub rsvp_send_response: bool,
180 180 pub meeting_toasts: crate::call::MeetingToasts,
181 181 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
182 pub calendar_week: crate::call::week::CalendarWeek,
182 183 pub call_backgrounds: crate::call::BackgroundLibrary,
183 184 pub transfer_picker: Option<AnyView>,
184 185 pub transcript_panel: Option<AnyView>,
@@ -349,6 +350,7 @@ impl AppState {
349 350 rsvp_send_response: true,
350 351 meeting_toasts: crate::call::MeetingToasts::default(),
351 352 demo_meetings: Vec::new(),
353 calendar_week: crate::call::week::CalendarWeek::default(),
352 354 call_backgrounds: if mode.demo {
353 355 crate::call::demo_library()
354 356 } else {
@@ -179,6 +179,7 @@ pub struct AppState {
179 pub rsvp_send_response: bool,
179 pub rsvp_send_response: bool,
180 pub meeting_toasts: crate::call::MeetingToasts,
180 pub meeting_toasts: crate::call::MeetingToasts,
181 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
181 pub demo_meetings: Vec<chatsvc::CalendarEvent>,
182 pub calendar_week: crate::call::week::CalendarWeek,
182 pub call_backgrounds: crate::call::BackgroundLibrary,
183 pub call_backgrounds: crate::call::BackgroundLibrary,
183 pub transfer_picker: Option<AnyView>,
184 pub transfer_picker: Option<AnyView>,
184 pub transcript_panel: Option<AnyView>,
185 pub transcript_panel: Option<AnyView>,
@@ -349,6 +350,7 @@ impl AppState {
349 rsvp_send_response: true,
350 rsvp_send_response: true,
350 meeting_toasts: crate::call::MeetingToasts::default(),
351 meeting_toasts: crate::call::MeetingToasts::default(),
351 demo_meetings: Vec::new(),
352 demo_meetings: Vec::new(),
353 calendar_week: crate::call::week::CalendarWeek::default(),
352 call_backgrounds: if mode.demo {
354 call_backgrounds: if mode.demo {
353 crate::call::demo_library()
355 crate::call::demo_library()
354 } else {
356 } else {
crates/app-state/src/call/calendar.rs +21 −4
@@ -11,6 +11,10 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
11 11 const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
12 12 static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();
13 13
14 pub(crate) fn demo_anchor() -> DateTime<Utc> {
15 *DEMO_ANCHOR.get_or_init(Utc::now)
16 }
17
14 18 impl AppState {
15 19 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
16 20 self.calendar_events = events;
@@ -21,7 +25,7 @@ impl AppState {
21 25
22 26 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
23 27 if self.mode.demo {
24 let mut events = demo_events(*DEMO_ANCHOR.get_or_init(Utc::now));
28 let mut events = demo_events(demo_anchor());
25 29 events.extend(self.demo_meetings.iter().cloned());
26 30 events.sort_by_key(|event| (event.start, event.end));
27 31 self.apply_calendar(events, cx);
@@ -52,16 +56,29 @@ impl AppState {
52 56 }
53 57
54 58 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
55 if let Some(url) = &row.join_url {
59 self.join_calendar_meeting(row.join_url.as_deref(), &row.subject, cx);
60 }
61
62 pub fn join_calendar_meeting(
63 &mut self,
64 join_url: Option<&str>,
65 subject: &str,
66 cx: &mut Context<Self>,
67 ) {
68 if let Some(url) = join_url {
56 69 self.join_meeting_link(url, cx);
57 70 if let Some(pending) = self.prejoin.as_mut() {
58 pending.join.title = row.subject.clone();
71 pending.join.title = subject.to_owned();
59 72 }
60 73 }
61 74 }
62 75
63 76 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
64 let Some(thread_id) = &row.thread_id else {
77 self.open_meeting_chat(row.thread_id.as_deref(), cx);
78 }
79
80 pub fn open_meeting_chat(&mut self, thread_id: Option<&str>, cx: &mut Context<Self>) {
81 let Some(thread_id) = thread_id else {
65 82 return;
66 83 };
67 84 match selection_for(&self.sidebar, thread_id) {
@@ -11,6 +11,10 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
11const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
11const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
12static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();
12static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();
13
13
14pub(crate) fn demo_anchor() -> DateTime<Utc> {
15 *DEMO_ANCHOR.get_or_init(Utc::now)
16}
17
14impl AppState {
18impl AppState {
15 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
19 pub fn apply_calendar(&mut self, events: Vec<CalendarEvent>, cx: &mut Context<Self>) {
16 self.calendar_events = events;
20 self.calendar_events = events;
@@ -21,7 +25,7 @@ impl AppState {
21
25
22 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
26 pub fn refresh_calendar(&mut self, cx: &mut Context<Self>) {
23 if self.mode.demo {
27 if self.mode.demo {
24 let mut events = demo_events(*DEMO_ANCHOR.get_or_init(Utc::now));
28 let mut events = demo_events(demo_anchor());
25 events.extend(self.demo_meetings.iter().cloned());
29 events.extend(self.demo_meetings.iter().cloned());
26 events.sort_by_key(|event| (event.start, event.end));
30 events.sort_by_key(|event| (event.start, event.end));
27 self.apply_calendar(events, cx);
31 self.apply_calendar(events, cx);
@@ -52,16 +56,29 @@ impl AppState {
52 }
56 }
53
57
54 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
58 pub fn join_agenda_row(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
55 if let Some(url) = &row.join_url {
59 self.join_calendar_meeting(row.join_url.as_deref(), &row.subject, cx);
60 }
61
62 pub fn join_calendar_meeting(
63 &mut self,
64 join_url: Option<&str>,
65 subject: &str,
66 cx: &mut Context<Self>,
67 ) {
68 if let Some(url) = join_url {
56 self.join_meeting_link(url, cx);
69 self.join_meeting_link(url, cx);
57 if let Some(pending) = self.prejoin.as_mut() {
70 if let Some(pending) = self.prejoin.as_mut() {
58 pending.join.title = row.subject.clone();
71 pending.join.title = subject.to_owned();
59 }
72 }
60 }
73 }
61 }
74 }
62
75
63 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
76 pub fn open_agenda_chat(&mut self, row: &AgendaRow, cx: &mut Context<Self>) {
64 let Some(thread_id) = &row.thread_id else {
77 self.open_meeting_chat(row.thread_id.as_deref(), cx);
78 }
79
80 pub fn open_meeting_chat(&mut self, thread_id: Option<&str>, cx: &mut Context<Self>) {
81 let Some(thread_id) = thread_id else {
65 return;
82 return;
66 };
83 };
67 match selection_for(&self.sidebar, thread_id) {
84 match selection_for(&self.sidebar, thread_id) {
crates/app-state/src/call/launcher.rs +16 −0
@@ -225,6 +225,22 @@ impl CallLauncher {
225 225 .map_err(|error| error.to_string())
226 226 }
227 227
228 pub async fn calendar_view(
229 &self,
230 start: chrono::DateTime<chrono::Utc>,
231 end: chrono::DateTime<chrono::Utc>,
232 ) -> Result<Vec<chatsvc::CalendarEvent>, String> {
233 let session = self
234 .ready_engine()
235 .await
236 .ok_or_else(|| NOT_READY.to_owned())?
237 .session();
238 chatsvc::Calendar::new(&session)
239 .calendar_view(start, end)
240 .await
241 .map_err(|error| error.to_string())
242 }
243
228 244 pub async fn reminder_view(
229 245 &self,
230 246 start: chrono::DateTime<chrono::Utc>,
@@ -225,6 +225,22 @@ impl CallLauncher {
225 .map_err(|error| error.to_string())
225 .map_err(|error| error.to_string())
226 }
226 }
227
227
228 pub async fn calendar_view(
229 &self,
230 start: chrono::DateTime<chrono::Utc>,
231 end: chrono::DateTime<chrono::Utc>,
232 ) -> Result<Vec<chatsvc::CalendarEvent>, String> {
233 let session = self
234 .ready_engine()
235 .await
236 .ok_or_else(|| NOT_READY.to_owned())?
237 .session();
238 chatsvc::Calendar::new(&session)
239 .calendar_view(start, end)
240 .await
241 .map_err(|error| error.to_string())
242 }
243
228 pub async fn reminder_view(
244 pub async fn reminder_view(
229 &self,
245 &self,
230 start: chrono::DateTime<chrono::Utc>,
246 start: chrono::DateTime<chrono::Utc>,
crates/app-state/src/call/mod.rs +2 −0
@@ -20,11 +20,13 @@ pub mod schedule;
20 20 pub mod target;
21 21 pub mod view_actions;
22 22 pub mod web_call;
23 pub mod week;
23 24
24 25 pub use app_call_model::{
25 26 agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,
26 27 model, options_dialog, people, preview, record_rights,
27 28 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
29 week_grid,
28 30 };
29 31
30 32 pub use actions::{
@@ -20,11 +20,13 @@ pub mod schedule;
20pub mod target;
20pub mod target;
21pub mod view_actions;
21pub mod view_actions;
22pub mod web_call;
22pub mod web_call;
23pub mod week;
23
24
24pub use app_call_model::{
25pub use app_call_model::{
25 agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,
26 agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,
26 model, options_dialog, people, preview, record_rights,
27 model, options_dialog, people, preview, record_rights,
27 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
28 recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
29 week_grid,
28};
30};
29
31
30pub use actions::{
32pub use actions::{
crates/app-state/src/call/week.rs added +169 −0
@@ -0,0 +1,169 @@
1 use chatsvc::{CalendarEvent, ResponseType};
2 use chrono::{Duration, FixedOffset, Local, NaiveDate, Offset};
3 use gpui_kit::Context;
4
5 use super::agenda::demo_events;
6 use super::calendar::demo_anchor;
7 use super::week_grid::{WORK_WEEK_DAYS, local_midnight, week_range, work_week_for};
8 use crate::app_state::AppState;
9
10 pub const CALENDAR_LOAD_FAILURE: &str = "We couldn't load your calendar.";
11
12 #[derive(Debug, Clone, Default)]
13 pub struct CalendarWeek {
14 pub start: Option<NaiveDate>,
15 pub events: Vec<CalendarEvent>,
16 pub loading: bool,
17 request: u64,
18 }
19
20 impl AppState {
21 pub fn calendar_start(&self) -> NaiveDate {
22 self.calendar_week
23 .start
24 .unwrap_or_else(|| work_week_for(Local::now().date_naive()))
25 }
26
27 pub fn open_calendar(&mut self, cx: &mut Context<Self>) {
28 if self.calendar_week.start.is_none() {
29 self.calendar_week.start = Some(work_week_for(Local::now().date_naive()));
30 }
31 self.load_calendar_week(cx);
32 }
33
34 pub fn shift_calendar_week(&mut self, weeks: i64, cx: &mut Context<Self>) {
35 self.calendar_week.start = Some(self.calendar_start() + Duration::weeks(weeks));
36 self.load_calendar_week(cx);
37 }
38
39 pub fn calendar_to_today(&mut self, cx: &mut Context<Self>) {
40 self.calendar_week.start = Some(work_week_for(Local::now().date_naive()));
41 self.load_calendar_week(cx);
42 }
43
44 fn load_calendar_week(&mut self, cx: &mut Context<Self>) {
45 let start = self.calendar_start();
46 let offset = Local::now().offset().fix();
47 let (from, to) = week_range(start, WORK_WEEK_DAYS, offset);
48 if self.mode.demo {
49 let mut events = demo_events(demo_anchor());
50 events.extend(demo_week(start, offset));
51 events.extend(self.demo_meetings.iter().cloned());
52 events.retain(|event| event.end > from && event.start < to);
53 events.sort_by_key(|event| (event.start, event.end));
54 self.calendar_week.events = events;
55 cx.notify();
56 return;
57 }
58 let Some(launcher) = self.call_launcher.clone() else {
59 return;
60 };
61 self.calendar_week.request += 1;
62 let request = self.calendar_week.request;
63 self.calendar_week.loading = true;
64 cx.notify();
65 let receiver = crate::runtime::spawn(async move { launcher.calendar_view(from, to).await });
66 cx.spawn(async move |this, cx| {
67 let loaded = receiver.await.ok().and_then(Result::ok);
68 this.update(cx, |state, cx| {
69 if state.calendar_week.request != request {
70 return;
71 }
72 state.calendar_week.loading = false;
73 match loaded {
74 Some(events) => state.calendar_week.events = events,
75 None => state.raise_notice(CALENDAR_LOAD_FAILURE.to_owned(), None, cx),
76 }
77 cx.notify();
78 })
79 .ok();
80 })
81 .detach();
82 }
83 }
84
85 fn demo_week(monday: NaiveDate, offset: FixedOffset) -> Vec<CalendarEvent> {
86 let slots: [(&str, &str, i64, i64, i64, ResponseType); 7] = [
87 (
88 "Team standup",
89 "Mara Lindqvist",
90 0,
91 9 * 60 + 30,
92 15,
93 ResponseType::Accepted,
94 ),
95 (
96 "Release review",
97 "Jonas Ortega",
98 0,
99 11 * 60,
100 60,
101 ResponseType::Organizer,
102 ),
103 (
104 "Customer sync",
105 "Priya Nair",
106 0,
107 11 * 60 + 30,
108 60,
109 ResponseType::NotResponded,
110 ),
111 (
112 "Team standup",
113 "Mara Lindqvist",
114 1,
115 9 * 60 + 30,
116 15,
117 ResponseType::Accepted,
118 ),
119 (
120 "Architecture deep dive",
121 "Lena Brandt",
122 2,
123 14 * 60,
124 90,
125 ResponseType::Tentative,
126 ),
127 (
128 "1:1 Jonas",
129 "Jonas Ortega",
130 3,
131 10 * 60,
132 30,
133 ResponseType::Accepted,
134 ),
135 (
136 "Sprint retro",
137 "Mara Lindqvist",
138 4,
139 15 * 60,
140 60,
141 ResponseType::Accepted,
142 ),
143 ];
144 slots
145 .iter()
146 .enumerate()
147 .map(|(index, (subject, organizer, day, minute, length, response))| {
148 let start =
149 local_midnight(monday + Duration::days(*day), offset) + Duration::minutes(*minute);
150 CalendarEvent {
151 object_id: format!("demo-week-{index}"),
152 subject: (*subject).to_owned(),
153 start,
154 end: start + Duration::minutes(*length),
155 all_day: false,
156 cancelled: false,
157 online: true,
158 join_url: Some(format!(
159 "https://teams.microsoft.com/l/meetup-join/19%3ameeting_demoweek{index}%40thread.v2/0"
160 )),
161 thread_id: None,
162 organizer_name: Some((*organizer).to_owned()),
163 organizer_address: None,
164 ical_uid: None,
165 response: *response,
166 }
167 })
168 .collect()
169 }
@@ -0,0 +1,169 @@
1use chatsvc::{CalendarEvent, ResponseType};
2use chrono::{Duration, FixedOffset, Local, NaiveDate, Offset};
3use gpui_kit::Context;
4
5use super::agenda::demo_events;
6use super::calendar::demo_anchor;
7use super::week_grid::{WORK_WEEK_DAYS, local_midnight, week_range, work_week_for};
8use crate::app_state::AppState;
9
10pub const CALENDAR_LOAD_FAILURE: &str = "We couldn't load your calendar.";
11
12#[derive(Debug, Clone, Default)]
13pub struct CalendarWeek {
14 pub start: Option<NaiveDate>,
15 pub events: Vec<CalendarEvent>,
16 pub loading: bool,
17 request: u64,
18}
19
20impl AppState {
21 pub fn calendar_start(&self) -> NaiveDate {
22 self.calendar_week
23 .start
24 .unwrap_or_else(|| work_week_for(Local::now().date_naive()))
25 }
26
27 pub fn open_calendar(&mut self, cx: &mut Context<Self>) {
28 if self.calendar_week.start.is_none() {
29 self.calendar_week.start = Some(work_week_for(Local::now().date_naive()));
30 }
31 self.load_calendar_week(cx);
32 }
33
34 pub fn shift_calendar_week(&mut self, weeks: i64, cx: &mut Context<Self>) {
35 self.calendar_week.start = Some(self.calendar_start() + Duration::weeks(weeks));
36 self.load_calendar_week(cx);
37 }
38
39 pub fn calendar_to_today(&mut self, cx: &mut Context<Self>) {
40 self.calendar_week.start = Some(work_week_for(Local::now().date_naive()));
41 self.load_calendar_week(cx);
42 }
43
44 fn load_calendar_week(&mut self, cx: &mut Context<Self>) {
45 let start = self.calendar_start();
46 let offset = Local::now().offset().fix();
47 let (from, to) = week_range(start, WORK_WEEK_DAYS, offset);
48 if self.mode.demo {
49 let mut events = demo_events(demo_anchor());
50 events.extend(demo_week(start, offset));
51 events.extend(self.demo_meetings.iter().cloned());
52 events.retain(|event| event.end > from && event.start < to);
53 events.sort_by_key(|event| (event.start, event.end));
54 self.calendar_week.events = events;
55 cx.notify();
56 return;
57 }
58 let Some(launcher) = self.call_launcher.clone() else {
59 return;
60 };
61 self.calendar_week.request += 1;
62 let request = self.calendar_week.request;
63 self.calendar_week.loading = true;
64 cx.notify();
65 let receiver = crate::runtime::spawn(async move { launcher.calendar_view(from, to).await });
66 cx.spawn(async move |this, cx| {
67 let loaded = receiver.await.ok().and_then(Result::ok);
68 this.update(cx, |state, cx| {
69 if state.calendar_week.request != request {
70 return;
71 }
72 state.calendar_week.loading = false;
73 match loaded {
74 Some(events) => state.calendar_week.events = events,
75 None => state.raise_notice(CALENDAR_LOAD_FAILURE.to_owned(), None, cx),
76 }
77 cx.notify();
78 })
79 .ok();
80 })
81 .detach();
82 }
83}
84
85fn demo_week(monday: NaiveDate, offset: FixedOffset) -> Vec<CalendarEvent> {
86 let slots: [(&str, &str, i64, i64, i64, ResponseType); 7] = [
87 (
88 "Team standup",
89 "Mara Lindqvist",
90 0,
91 9 * 60 + 30,
92 15,
93 ResponseType::Accepted,
94 ),
95 (
96 "Release review",
97 "Jonas Ortega",
98 0,
99 11 * 60,
100 60,
101 ResponseType::Organizer,
102 ),
103 (
104 "Customer sync",
105 "Priya Nair",
106 0,
107 11 * 60 + 30,
108 60,
109 ResponseType::NotResponded,
110 ),
111 (
112 "Team standup",
113 "Mara Lindqvist",
114 1,
115 9 * 60 + 30,
116 15,
117 ResponseType::Accepted,
118 ),
119 (
120 "Architecture deep dive",
121 "Lena Brandt",
122 2,
123 14 * 60,
124 90,
125 ResponseType::Tentative,
126 ),
127 (
128 "1:1 Jonas",
129 "Jonas Ortega",
130 3,
131 10 * 60,
132 30,
133 ResponseType::Accepted,
134 ),
135 (
136 "Sprint retro",
137 "Mara Lindqvist",
138 4,
139 15 * 60,
140 60,
141 ResponseType::Accepted,
142 ),
143 ];
144 slots
145 .iter()
146 .enumerate()
147 .map(|(index, (subject, organizer, day, minute, length, response))| {
148 let start =
149 local_midnight(monday + Duration::days(*day), offset) + Duration::minutes(*minute);
150 CalendarEvent {
151 object_id: format!("demo-week-{index}"),
152 subject: (*subject).to_owned(),
153 start,
154 end: start + Duration::minutes(*length),
155 all_day: false,
156 cancelled: false,
157 online: true,
158 join_url: Some(format!(
159 "https://teams.microsoft.com/l/meetup-join/19%3ameeting_demoweek{index}%40thread.v2/0"
160 )),
161 thread_id: None,
162 organizer_name: Some((*organizer).to_owned()),
163 organizer_address: None,
164 ical_uid: None,
165 response: *response,
166 }
167 })
168 .collect()
169}
crates/app/src/layout_guard.rs +13 −1
@@ -217,7 +217,7 @@ mod frames {
217 217 };
218 218 use crate::views::shortcuts::{
219 219 ClearChatFilters, FilterMutedChats, FindInChat, OpenActivity, OpenAgents, OpenCallsTab,
220 OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
220 OpenCalendar, OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
221 221 };
222 222 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
223 223 use crate::views::sidebar::chat_row_selector;
@@ -263,6 +263,7 @@ mod frames {
263 263 "shell/islands/main/call-controls/leave",
264 264 ];
265 265 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
266 const CALENDAR: &str = "shell/islands/calendar";
266 267 const CHAT_FILTER_TAGS: &[&str] = &[FILTER_TAG, FILTER_PILLS_TAG];
267 268 const CHAT_FILTER_OPEN_TAGS: &[&str] = &[FILTER_INPUT_TAG, FILTER_EMPTY_TAG];
268 269 const FIND_TAGS: &[&str] = &[
@@ -622,6 +623,7 @@ mod frames {
622 623 .chain([
623 624 &ACTIVITY_PROPOSALS_TAG,
624 625 &AGENTS_LIST,
626 &CALENDAR,
625 627 &CALL_TRANSCRIPT,
626 628 &MENU,
627 629 &RECAP_TAB,
@@ -857,6 +859,10 @@ mod frames {
857 859 Some(|visual| visual.dispatch_action(OpenChannelsTab)),
858 860 ),
859 861 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
862 Screen::Tab(
863 "calendar",
864 Some(|visual| visual.dispatch_action(OpenCalendar)),
865 ),
860 866 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
861 867 Screen::Tab("agents", Some(|visual| visual.dispatch_action(OpenAgents))),
862 868 Screen::Prejoin,
@@ -988,6 +994,12 @@ mod frames {
988 994 "find" => expected.extend(FIND_TAGS),
989 995 "calls" => expected.extend(CALLS_TAGS),
990 996 "agents" => expected.push(AGENTS_LIST),
997 "calendar" => {
998 expected.retain(|path| {
999 !matches!(*path, "shell/islands/sidebar" | "shell/islands/main")
1000 });
1001 expected.push(CALENDAR);
1002 }
991 1003 "prejoin" => expected.extend(PREJOIN_TAGS),
992 1004 _ => {}
993 1005 }
@@ -217,7 +217,7 @@ mod frames {
217 };
217 };
218 use crate::views::shortcuts::{
218 use crate::views::shortcuts::{
219 ClearChatFilters, FilterMutedChats, FindInChat, OpenActivity, OpenAgents, OpenCallsTab,
219 ClearChatFilters, FilterMutedChats, FindInChat, OpenActivity, OpenAgents, OpenCallsTab,
220 OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
220 OpenCalendar, OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
221 };
221 };
222 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
222 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
223 use crate::views::sidebar::chat_row_selector;
223 use crate::views::sidebar::chat_row_selector;
@@ -263,6 +263,7 @@ mod frames {
263 "shell/islands/main/call-controls/leave",
263 "shell/islands/main/call-controls/leave",
264 ];
264 ];
265 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
265 const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
266 const CALENDAR: &str = "shell/islands/calendar";
266 const CHAT_FILTER_TAGS: &[&str] = &[FILTER_TAG, FILTER_PILLS_TAG];
267 const CHAT_FILTER_TAGS: &[&str] = &[FILTER_TAG, FILTER_PILLS_TAG];
267 const CHAT_FILTER_OPEN_TAGS: &[&str] = &[FILTER_INPUT_TAG, FILTER_EMPTY_TAG];
268 const CHAT_FILTER_OPEN_TAGS: &[&str] = &[FILTER_INPUT_TAG, FILTER_EMPTY_TAG];
268 const FIND_TAGS: &[&str] = &[
269 const FIND_TAGS: &[&str] = &[
@@ -622,6 +623,7 @@ mod frames {
622 .chain([
623 .chain([
623 &ACTIVITY_PROPOSALS_TAG,
624 &ACTIVITY_PROPOSALS_TAG,
624 &AGENTS_LIST,
625 &AGENTS_LIST,
626 &CALENDAR,
625 &CALL_TRANSCRIPT,
627 &CALL_TRANSCRIPT,
626 &MENU,
628 &MENU,
627 &RECAP_TAB,
629 &RECAP_TAB,
@@ -857,6 +859,10 @@ mod frames {
857 Some(|visual| visual.dispatch_action(OpenChannelsTab)),
859 Some(|visual| visual.dispatch_action(OpenChannelsTab)),
858 ),
860 ),
859 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
861 Screen::Tab("saved", Some(|visual| visual.dispatch_action(OpenSaved))),
862 Screen::Tab(
863 "calendar",
864 Some(|visual| visual.dispatch_action(OpenCalendar)),
865 ),
860 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
866 Screen::Tab("calls", Some(|visual| visual.dispatch_action(OpenCallsTab))),
861 Screen::Tab("agents", Some(|visual| visual.dispatch_action(OpenAgents))),
867 Screen::Tab("agents", Some(|visual| visual.dispatch_action(OpenAgents))),
862 Screen::Prejoin,
868 Screen::Prejoin,
@@ -988,6 +994,12 @@ mod frames {
988 "find" => expected.extend(FIND_TAGS),
994 "find" => expected.extend(FIND_TAGS),
989 "calls" => expected.extend(CALLS_TAGS),
995 "calls" => expected.extend(CALLS_TAGS),
990 "agents" => expected.push(AGENTS_LIST),
996 "agents" => expected.push(AGENTS_LIST),
997 "calendar" => {
998 expected.retain(|path| {
999 !matches!(*path, "shell/islands/sidebar" | "shell/islands/main")
1000 });
1001 expected.push(CALENDAR);
1002 }
991 "prejoin" => expected.extend(PREJOIN_TAGS),
1003 "prejoin" => expected.extend(PREJOIN_TAGS),
992 _ => {}
1004 _ => {}
993 }
1005 }
crates/app/src/views/calendar_view.rs added +435 −0
@@ -0,0 +1,435 @@
1 use chatsvc::{CalendarEvent, ResponseType};
2 use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};
3 use gpui_kit::assets::IconName;
4 use gpui_kit::component::Sizable as _;
5 use gpui_kit::component::button::{Button, ButtonVariants as _};
6 use gpui_kit::component::{h_flex, v_flex};
7 use gpui_kit::prelude::FluentBuilder as _;
8 use gpui_kit::*;
9
10 use super::join_dialog::open_join_with_id;
11 use super::new_meeting_dialog::open_new_meeting;
12 use crate::app_state::AppState;
13 use crate::call::join_available;
14 use crate::call::week_grid::{
15 WORK_WEEK_DAYS, WeekBlock, WeekDay, hour_label, range_label, week_days,
16 };
17 use crate::theme;
18
19 const HOUR_HEIGHT: f32 = 48.;
20 const GUTTER_WIDTH: f32 = 64.;
21 const HEADER_HEIGHT: f32 = 52.;
22 const DAY_HEADER_HEIGHT: f32 = 56.;
23 const ALL_DAY_HEIGHT: f32 = 26.;
24 const BLOCK_GAP: f32 = 2.;
25 const FIRST_VISIBLE_HOUR: f32 = 8.;
26 const CANCELED_PREFIX: &str = "Canceled: ";
27 const COMPACT_HEADER_WIDTH: f32 = 960.;
28 const EVENT_FILL_OPACITY: f32 = 0.28;
29
30 pub struct CalendarView {
31 state: Entity<AppState>,
32 scroll: ScrollHandle,
33 scrolled_to_morning: bool,
34 _observation: Subscription,
35 }
36
37 impl CalendarView {
38 pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {
39 let observation = cx.observe(&state, |_, _, cx| cx.notify());
40 CalendarView {
41 state,
42 scroll: ScrollHandle::new(),
43 scrolled_to_morning: false,
44 _observation: observation,
45 }
46 }
47
48 fn header(&self, start: NaiveDate, compact: bool) -> impl IntoElement {
49 let label = |text: &'static str| (!compact).then_some(text);
50 let (today, back, forward) = (self.state.clone(), self.state.clone(), self.state.clone());
51 let (join_state, meet_state, new_state) =
52 (self.state.clone(), self.state.clone(), self.state.clone());
53 h_flex()
54 .h(px(HEADER_HEIGHT))
55 .flex_none()
56 .items_center()
57 .gap(px(8.))
58 .px(px(16.))
59 .child(
60 div()
61 .flex_none()
62 .text_size(px(16.))
63 .font_weight(FontWeight::BOLD)
64 .mr(px(8.))
65 .child("Calendar"),
66 )
67 .child(
68 Button::new("calendar-today")
69 .small()
70 .outline()
71 .icon(IconName::Calendar)
72 .when_some(label("Today"), |button, text| button.label(text))
73 .tooltip("Today")
74 .on_click(move |_, _, cx| {
75 today.update(cx, |state, cx| state.calendar_to_today(cx))
76 }),
77 )
78 .child(
79 Button::new("calendar-back")
80 .small()
81 .ghost()
82 .icon(IconName::ChevronLeft)
83 .tooltip("Go to previous week")
84 .on_click(move |_, _, cx| {
85 back.update(cx, |state, cx| state.shift_calendar_week(-1, cx))
86 }),
87 )
88 .child(
89 Button::new("calendar-forward")
90 .small()
91 .ghost()
92 .icon(IconName::ChevronRight)
93 .tooltip("Go to next week")
94 .on_click(move |_, _, cx| {
95 forward.update(cx, |state, cx| state.shift_calendar_week(1, cx))
96 }),
97 )
98 .child(
99 div()
100 .flex_1()
101 .min_w_0()
102 .truncate()
103 .text_size(px(14.))
104 .font_weight(FontWeight::SEMIBOLD)
105 .child(range_label(start, WORK_WEEK_DAYS)),
106 )
107 .child(
108 Button::new("calendar-join-id")
109 .small()
110 .outline()
111 .icon(IconName::Hash)
112 .when_some(label("Join with an ID"), |button, text| button.label(text))
113 .tooltip("Join with an ID")
114 .on_click(move |_, window, cx| {
115 open_join_with_id(join_state.clone(), window, cx)
116 }),
117 )
118 .child(
119 Button::new("calendar-meet-now")
120 .small()
121 .outline()
122 .icon(IconName::Video)
123 .when_some(label("Meet now"), |button, text| button.label(text))
124 .tooltip("Meet now")
125 .on_click(move |_, _, cx| {
126 meet_state.update(cx, |state, cx| state.start_meet_now(cx))
127 }),
128 )
129 .child(
130 Button::new("calendar-new-meeting")
131 .small()
132 .primary()
133 .icon(IconName::Plus)
134 .when_some(label("New meeting"), |button, text| button.label(text))
135 .tooltip("New meeting")
136 .on_click(move |_, window, cx| open_new_meeting(new_state.clone(), window, cx)),
137 )
138 }
139
140 fn day_headers(&self, days: &[WeekDay], today: NaiveDate) -> impl IntoElement {
141 h_flex()
142 .h(px(DAY_HEADER_HEIGHT))
143 .flex_none()
144 .border_b_1()
145 .border_color(theme::border())
146 .child(div().w(px(GUTTER_WIDTH)).flex_none())
147 .children(days.iter().map(|day| {
148 let is_today = day.date == today;
149 let color = if is_today {
150 theme::accent_text()
151 } else {
152 theme::text_soft()
153 };
154 v_flex()
155 .flex_1()
156 .min_w_0()
157 .h_full()
158 .justify_center()
159 .px(px(8.))
160 .border_l_1()
161 .border_color(theme::border())
162 .child(
163 div()
164 .text_size(px(20.))
165 .font_weight(FontWeight::SEMIBOLD)
166 .text_color(color)
167 .child(day.date.format("%d").to_string()),
168 )
169 .child(
170 div()
171 .text_size(px(12.))
172 .text_color(color)
173 .child(day.date.format("%A").to_string()),
174 )
175 }))
176 }
177
178 fn all_day_row(&self, days: &[WeekDay], events: &[CalendarEvent]) -> Option<Div> {
179 if days.iter().all(|day| day.all_day.is_empty()) {
180 return None;
181 }
182 Some(
183 h_flex()
184 .flex_none()
185 .border_b_1()
186 .border_color(theme::border())
187 .child(div().w(px(GUTTER_WIDTH)).flex_none())
188 .children(days.iter().map(|day| {
189 v_flex()
190 .flex_1()
191 .min_w_0()
192 .gap(px(BLOCK_GAP))
193 .p(px(BLOCK_GAP))
194 .border_l_1()
195 .border_color(theme::border())
196 .children(day.all_day.iter().map(|&index| {
197 div()
198 .h(px(ALL_DAY_HEIGHT - 2. * BLOCK_GAP))
199 .px(px(6.))
200 .flex()
201 .items_center()
202 .rounded(px(4.))
203 .bg(event_fill(events[index].response))
204 .text_size(px(12.))
205 .truncate()
206 .child(event_title(&events[index]))
207 }))
208 })),
209 )
210 }
211
212 fn event_block(
213 &self,
214 block: &WeekBlock,
215 event: &CalendarEvent,
216 now: DateTime<Utc>,
217 ) -> impl IntoElement {
218 let top = block.start_minute as f32 / 60. * HOUR_HEIGHT;
219 let height = ((block.end_minute - block.start_minute) as f32 / 60. * HOUR_HEIGHT
220 - BLOCK_GAP)
221 .max(14.);
222 let width = 1. / block.lanes as f32;
223 let compact = height < 36.;
224 let can_join = event.online
225 && !event.cancelled
226 && event.join_url.is_some()
227 && join_available(event.start, event.end, now);
228 let time = format!(
229 "{} - {}",
230 event.start.with_timezone(&Local).format("%-I:%M %p"),
231 event.end.with_timezone(&Local).format("%-I:%M %p")
232 );
233 let (open_state, thread_id) = (self.state.clone(), event.thread_id.clone());
234 let (join_state, join_url, subject) = (
235 self.state.clone(),
236 event.join_url.clone(),
237 event.subject.clone(),
238 );
239 div()
240 .id(SharedString::from(format!(
241 "calendar-event-{}",
242 event.object_id
243 )))
244 .absolute()
245 .top(px(top))
246 .h(px(height))
247 .left(relative(width * block.lane as f32))
248 .w(relative(width))
249 .pr(px(BLOCK_GAP))
250 .child(
251 h_flex()
252 .size_full()
253 .overflow_hidden()
254 .rounded(px(4.))
255 .bg(event_fill(event.response))
256 .border_l_2()
257 .border_color(theme::accent())
258 .when(event.cancelled, |block| block.opacity(0.6))
259 .cursor_pointer()
260 .child(
261 v_flex()
262 .flex_1()
263 .min_w_0()
264 .px(px(6.))
265 .py(px(if compact { 1. } else { 4. }))
266 .child(
267 div()
268 .text_size(px(12.))
269 .font_weight(FontWeight::SEMIBOLD)
270 .truncate()
271 .child(event_title(event)),
272 )
273 .when(!compact, |body| {
274 body.child(
275 div()
276 .text_size(px(11.))
277 .text_color(theme::text_soft())
278 .truncate()
279 .child(match &event.organizer_name {
280 Some(organizer) => format!("{time} {organizer}"),
281 None => time,
282 }),
283 )
284 }),
285 )
286 .when(can_join, |block| {
287 block.child(
288 div().flex_none().pr(px(4.)).pt(px(3.)).h_full().child(
289 Button::new(SharedString::from(format!(
290 "calendar-join-{}",
291 event.object_id
292 )))
293 .xsmall()
294 .primary()
295 .label("Join")
296 .on_click(move |_, _, cx| {
297 cx.stop_propagation();
298 join_state.update(cx, |state, cx| {
299 state.join_calendar_meeting(
300 join_url.as_deref(),
301 &subject,
302 cx,
303 )
304 });
305 }),
306 ),
307 )
308 }),
309 )
310 .on_click(move |_, _, cx| {
311 open_state.update(cx, |state, cx| {
312 state.open_meeting_chat(thread_id.as_deref(), cx)
313 });
314 })
315 }
316
317 fn grid(
318 &self,
319 days: &[WeekDay],
320 events: &[CalendarEvent],
321 today: NaiveDate,
322 now: DateTime<Utc>,
323 ) -> impl IntoElement {
324 let total_height = 24. * HOUR_HEIGHT;
325 let now_minute = {
326 let local = now.with_timezone(&Local);
327 local.hour() * 60 + local.minute()
328 };
329 div()
330 .id("calendar-grid")
331 .flex_1()
332 .min_h_0()
333 .overflow_y_scroll()
334 .track_scroll(&self.scroll)
335 .child(
336 h_flex()
337 .h(px(total_height))
338 .w_full()
339 .child(
340 v_flex()
341 .w(px(GUTTER_WIDTH))
342 .flex_none()
343 .children((0..24).map(|hour| {
344 div()
345 .h(px(HOUR_HEIGHT))
346 .pr(px(8.))
347 .flex()
348 .justify_end()
349 .text_size(px(11.))
350 .text_color(theme::text_muted())
351 .when(hour > 0, |label| label.child(hour_label(hour)))
352 })),
353 )
354 .children(days.iter().map(|day| {
355 div()
356 .relative()
357 .flex_1()
358 .min_w_0()
359 .h_full()
360 .border_l_1()
361 .border_color(theme::border())
362 .children((1..24).map(|hour| {
363 div()
364 .absolute()
365 .top(px(hour as f32 * HOUR_HEIGHT))
366 .left_0()
367 .right_0()
368 .h(px(1.))
369 .bg(theme::border())
370 }))
371 .children(day.blocks.iter().map(|block| {
372 self.event_block(block, &events[block.event_index], now)
373 }))
374 .when(day.date == today, |column| {
375 column.child(
376 div()
377 .absolute()
378 .top(px(now_minute as f32 / 60. * HOUR_HEIGHT))
379 .left_0()
380 .right_0()
381 .h(px(2.))
382 .bg(theme::red()),
383 )
384 })
385 })),
386 )
387 }
388 }
389
390 fn event_fill(response: ResponseType) -> Hsla {
391 match response {
392 ResponseType::NotResponded => theme::surface_raised(),
393 ResponseType::Tentative => theme::accent().opacity(EVENT_FILL_OPACITY / 2.),
394 _ => theme::accent().opacity(EVENT_FILL_OPACITY),
395 }
396 }
397
398 fn event_title(event: &CalendarEvent) -> String {
399 if event.cancelled {
400 format!("{CANCELED_PREFIX}{}", event.subject)
401 } else {
402 event.subject.clone()
403 }
404 }
405
406 impl Render for CalendarView {
407 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
408 let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;
409 if !self.scrolled_to_morning {
410 self.scrolled_to_morning = true;
411 self.scroll
412 .set_offset(point(px(0.), px(-FIRST_VISIBLE_HOUR * HOUR_HEIGHT)));
413 }
414 let state = self.state.read(cx);
415 let start = state.calendar_start();
416 let events = state.calendar_week.events.clone();
417 let offset = Local::now().offset().fix();
418 let days = week_days(&events, start, WORK_WEEK_DAYS, offset);
419 let today = Local::now().date_naive();
420 let now = Utc::now();
421 v_flex()
422 .debug_selector(|| "shell/islands/calendar".into())
423 .flex_1()
424 .w_full()
425 .min_w_0()
426 .h_full()
427 .rounded(px(10.))
428 .bg(theme::surface())
429 .overflow_hidden()
430 .child(self.header(start, compact))
431 .child(self.day_headers(&days, today))
432 .children(self.all_day_row(&days, &events))
433 .child(self.grid(&days, &events, today, now))
434 }
435 }
@@ -0,0 +1,435 @@
1use chatsvc::{CalendarEvent, ResponseType};
2use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};
3use gpui_kit::assets::IconName;
4use gpui_kit::component::Sizable as _;
5use gpui_kit::component::button::{Button, ButtonVariants as _};
6use gpui_kit::component::{h_flex, v_flex};
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9
10use super::join_dialog::open_join_with_id;
11use super::new_meeting_dialog::open_new_meeting;
12use crate::app_state::AppState;
13use crate::call::join_available;
14use crate::call::week_grid::{
15 WORK_WEEK_DAYS, WeekBlock, WeekDay, hour_label, range_label, week_days,
16};
17use crate::theme;
18
19const HOUR_HEIGHT: f32 = 48.;
20const GUTTER_WIDTH: f32 = 64.;
21const HEADER_HEIGHT: f32 = 52.;
22const DAY_HEADER_HEIGHT: f32 = 56.;
23const ALL_DAY_HEIGHT: f32 = 26.;
24const BLOCK_GAP: f32 = 2.;
25const FIRST_VISIBLE_HOUR: f32 = 8.;
26const CANCELED_PREFIX: &str = "Canceled: ";
27const COMPACT_HEADER_WIDTH: f32 = 960.;
28const EVENT_FILL_OPACITY: f32 = 0.28;
29
30pub struct CalendarView {
31 state: Entity<AppState>,
32 scroll: ScrollHandle,
33 scrolled_to_morning: bool,
34 _observation: Subscription,
35}
36
37impl CalendarView {
38 pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {
39 let observation = cx.observe(&state, |_, _, cx| cx.notify());
40 CalendarView {
41 state,
42 scroll: ScrollHandle::new(),
43 scrolled_to_morning: false,
44 _observation: observation,
45 }
46 }
47
48 fn header(&self, start: NaiveDate, compact: bool) -> impl IntoElement {
49 let label = |text: &'static str| (!compact).then_some(text);
50 let (today, back, forward) = (self.state.clone(), self.state.clone(), self.state.clone());
51 let (join_state, meet_state, new_state) =
52 (self.state.clone(), self.state.clone(), self.state.clone());
53 h_flex()
54 .h(px(HEADER_HEIGHT))
55 .flex_none()
56 .items_center()
57 .gap(px(8.))
58 .px(px(16.))
59 .child(
60 div()
61 .flex_none()
62 .text_size(px(16.))
63 .font_weight(FontWeight::BOLD)
64 .mr(px(8.))
65 .child("Calendar"),
66 )
67 .child(
68 Button::new("calendar-today")
69 .small()
70 .outline()
71 .icon(IconName::Calendar)
72 .when_some(label("Today"), |button, text| button.label(text))
73 .tooltip("Today")
74 .on_click(move |_, _, cx| {
75 today.update(cx, |state, cx| state.calendar_to_today(cx))
76 }),
77 )
78 .child(
79 Button::new("calendar-back")
80 .small()
81 .ghost()
82 .icon(IconName::ChevronLeft)
83 .tooltip("Go to previous week")
84 .on_click(move |_, _, cx| {
85 back.update(cx, |state, cx| state.shift_calendar_week(-1, cx))
86 }),
87 )
88 .child(
89 Button::new("calendar-forward")
90 .small()
91 .ghost()
92 .icon(IconName::ChevronRight)
93 .tooltip("Go to next week")
94 .on_click(move |_, _, cx| {
95 forward.update(cx, |state, cx| state.shift_calendar_week(1, cx))
96 }),
97 )
98 .child(
99 div()
100 .flex_1()
101 .min_w_0()
102 .truncate()
103 .text_size(px(14.))
104 .font_weight(FontWeight::SEMIBOLD)
105 .child(range_label(start, WORK_WEEK_DAYS)),
106 )
107 .child(
108 Button::new("calendar-join-id")
109 .small()
110 .outline()
111 .icon(IconName::Hash)
112 .when_some(label("Join with an ID"), |button, text| button.label(text))
113 .tooltip("Join with an ID")
114 .on_click(move |_, window, cx| {
115 open_join_with_id(join_state.clone(), window, cx)
116 }),
117 )
118 .child(
119 Button::new("calendar-meet-now")
120 .small()
121 .outline()
122 .icon(IconName::Video)
123 .when_some(label("Meet now"), |button, text| button.label(text))
124 .tooltip("Meet now")
125 .on_click(move |_, _, cx| {
126 meet_state.update(cx, |state, cx| state.start_meet_now(cx))
127 }),
128 )
129 .child(
130 Button::new("calendar-new-meeting")
131 .small()
132 .primary()
133 .icon(IconName::Plus)
134 .when_some(label("New meeting"), |button, text| button.label(text))
135 .tooltip("New meeting")
136 .on_click(move |_, window, cx| open_new_meeting(new_state.clone(), window, cx)),
137 )
138 }
139
140 fn day_headers(&self, days: &[WeekDay], today: NaiveDate) -> impl IntoElement {
141 h_flex()
142 .h(px(DAY_HEADER_HEIGHT))
143 .flex_none()
144 .border_b_1()
145 .border_color(theme::border())
146 .child(div().w(px(GUTTER_WIDTH)).flex_none())
147 .children(days.iter().map(|day| {
148 let is_today = day.date == today;
149 let color = if is_today {
150 theme::accent_text()
151 } else {
152 theme::text_soft()
153 };
154 v_flex()
155 .flex_1()
156 .min_w_0()
157 .h_full()
158 .justify_center()
159 .px(px(8.))
160 .border_l_1()
161 .border_color(theme::border())
162 .child(
163 div()
164 .text_size(px(20.))
165 .font_weight(FontWeight::SEMIBOLD)
166 .text_color(color)
167 .child(day.date.format("%d").to_string()),
168 )
169 .child(
170 div()
171 .text_size(px(12.))
172 .text_color(color)
173 .child(day.date.format("%A").to_string()),
174 )
175 }))
176 }
177
178 fn all_day_row(&self, days: &[WeekDay], events: &[CalendarEvent]) -> Option<Div> {
179 if days.iter().all(|day| day.all_day.is_empty()) {
180 return None;
181 }
182 Some(
183 h_flex()
184 .flex_none()
185 .border_b_1()
186 .border_color(theme::border())
187 .child(div().w(px(GUTTER_WIDTH)).flex_none())
188 .children(days.iter().map(|day| {
189 v_flex()
190 .flex_1()
191 .min_w_0()
192 .gap(px(BLOCK_GAP))
193 .p(px(BLOCK_GAP))
194 .border_l_1()
195 .border_color(theme::border())
196 .children(day.all_day.iter().map(|&index| {
197 div()
198 .h(px(ALL_DAY_HEIGHT - 2. * BLOCK_GAP))
199 .px(px(6.))
200 .flex()
201 .items_center()
202 .rounded(px(4.))
203 .bg(event_fill(events[index].response))
204 .text_size(px(12.))
205 .truncate()
206 .child(event_title(&events[index]))
207 }))
208 })),
209 )
210 }
211
212 fn event_block(
213 &self,
214 block: &WeekBlock,
215 event: &CalendarEvent,
216 now: DateTime<Utc>,
217 ) -> impl IntoElement {
218 let top = block.start_minute as f32 / 60. * HOUR_HEIGHT;
219 let height = ((block.end_minute - block.start_minute) as f32 / 60. * HOUR_HEIGHT
220 - BLOCK_GAP)
221 .max(14.);
222 let width = 1. / block.lanes as f32;
223 let compact = height < 36.;
224 let can_join = event.online
225 && !event.cancelled
226 && event.join_url.is_some()
227 && join_available(event.start, event.end, now);
228 let time = format!(
229 "{} - {}",
230 event.start.with_timezone(&Local).format("%-I:%M %p"),
231 event.end.with_timezone(&Local).format("%-I:%M %p")
232 );
233 let (open_state, thread_id) = (self.state.clone(), event.thread_id.clone());
234 let (join_state, join_url, subject) = (
235 self.state.clone(),
236 event.join_url.clone(),
237 event.subject.clone(),
238 );
239 div()
240 .id(SharedString::from(format!(
241 "calendar-event-{}",
242 event.object_id
243 )))
244 .absolute()
245 .top(px(top))
246 .h(px(height))
247 .left(relative(width * block.lane as f32))
248 .w(relative(width))
249 .pr(px(BLOCK_GAP))
250 .child(
251 h_flex()
252 .size_full()
253 .overflow_hidden()
254 .rounded(px(4.))
255 .bg(event_fill(event.response))
256 .border_l_2()
257 .border_color(theme::accent())
258 .when(event.cancelled, |block| block.opacity(0.6))
259 .cursor_pointer()
260 .child(
261 v_flex()
262 .flex_1()
263 .min_w_0()
264 .px(px(6.))
265 .py(px(if compact { 1. } else { 4. }))
266 .child(
267 div()
268 .text_size(px(12.))
269 .font_weight(FontWeight::SEMIBOLD)
270 .truncate()
271 .child(event_title(event)),
272 )
273 .when(!compact, |body| {
274 body.child(
275 div()
276 .text_size(px(11.))
277 .text_color(theme::text_soft())
278 .truncate()
279 .child(match &event.organizer_name {
280 Some(organizer) => format!("{time} {organizer}"),
281 None => time,
282 }),
283 )
284 }),
285 )
286 .when(can_join, |block| {
287 block.child(
288 div().flex_none().pr(px(4.)).pt(px(3.)).h_full().child(
289 Button::new(SharedString::from(format!(
290 "calendar-join-{}",
291 event.object_id
292 )))
293 .xsmall()
294 .primary()
295 .label("Join")
296 .on_click(move |_, _, cx| {
297 cx.stop_propagation();
298 join_state.update(cx, |state, cx| {
299 state.join_calendar_meeting(
300 join_url.as_deref(),
301 &subject,
302 cx,
303 )
304 });
305 }),
306 ),
307 )
308 }),
309 )
310 .on_click(move |_, _, cx| {
311 open_state.update(cx, |state, cx| {
312 state.open_meeting_chat(thread_id.as_deref(), cx)
313 });
314 })
315 }
316
317 fn grid(
318 &self,
319 days: &[WeekDay],
320 events: &[CalendarEvent],
321 today: NaiveDate,
322 now: DateTime<Utc>,
323 ) -> impl IntoElement {
324 let total_height = 24. * HOUR_HEIGHT;
325 let now_minute = {
326 let local = now.with_timezone(&Local);
327 local.hour() * 60 + local.minute()
328 };
329 div()
330 .id("calendar-grid")
331 .flex_1()
332 .min_h_0()
333 .overflow_y_scroll()
334 .track_scroll(&self.scroll)
335 .child(
336 h_flex()
337 .h(px(total_height))
338 .w_full()
339 .child(
340 v_flex()
341 .w(px(GUTTER_WIDTH))
342 .flex_none()
343 .children((0..24).map(|hour| {
344 div()
345 .h(px(HOUR_HEIGHT))
346 .pr(px(8.))
347 .flex()
348 .justify_end()
349 .text_size(px(11.))
350 .text_color(theme::text_muted())
351 .when(hour > 0, |label| label.child(hour_label(hour)))
352 })),
353 )
354 .children(days.iter().map(|day| {
355 div()
356 .relative()
357 .flex_1()
358 .min_w_0()
359 .h_full()
360 .border_l_1()
361 .border_color(theme::border())
362 .children((1..24).map(|hour| {
363 div()
364 .absolute()
365 .top(px(hour as f32 * HOUR_HEIGHT))
366 .left_0()
367 .right_0()
368 .h(px(1.))
369 .bg(theme::border())
370 }))
371 .children(day.blocks.iter().map(|block| {
372 self.event_block(block, &events[block.event_index], now)
373 }))
374 .when(day.date == today, |column| {
375 column.child(
376 div()
377 .absolute()
378 .top(px(now_minute as f32 / 60. * HOUR_HEIGHT))
379 .left_0()
380 .right_0()
381 .h(px(2.))
382 .bg(theme::red()),
383 )
384 })
385 })),
386 )
387 }
388}
389
390fn event_fill(response: ResponseType) -> Hsla {
391 match response {
392 ResponseType::NotResponded => theme::surface_raised(),
393 ResponseType::Tentative => theme::accent().opacity(EVENT_FILL_OPACITY / 2.),
394 _ => theme::accent().opacity(EVENT_FILL_OPACITY),
395 }
396}
397
398fn event_title(event: &CalendarEvent) -> String {
399 if event.cancelled {
400 format!("{CANCELED_PREFIX}{}", event.subject)
401 } else {
402 event.subject.clone()
403 }
404}
405
406impl Render for CalendarView {
407 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
408 let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;
409 if !self.scrolled_to_morning {
410 self.scrolled_to_morning = true;
411 self.scroll
412 .set_offset(point(px(0.), px(-FIRST_VISIBLE_HOUR * HOUR_HEIGHT)));
413 }
414 let state = self.state.read(cx);
415 let start = state.calendar_start();
416 let events = state.calendar_week.events.clone();
417 let offset = Local::now().offset().fix();
418 let days = week_days(&events, start, WORK_WEEK_DAYS, offset);
419 let today = Local::now().date_naive();
420 let now = Utc::now();
421 v_flex()
422 .debug_selector(|| "shell/islands/calendar".into())
423 .flex_1()
424 .w_full()
425 .min_w_0()
426 .h_full()
427 .rounded(px(10.))
428 .bg(theme::surface())
429 .overflow_hidden()
430 .child(self.header(start, compact))
431 .child(self.day_headers(&days, today))
432 .children(self.all_day_row(&days, &events))
433 .child(self.grid(&days, &events, today, now))
434 }
435}
crates/app/src/views/mod.rs +1 −0
@@ -25,6 +25,7 @@ pub mod call_stage;
25 25 pub mod call_transcript;
26 26 pub mod call_view;
27 27 pub mod call_view_menu;
28 pub mod calendar_view;
28 29 pub mod calls_tab;
29 30 pub mod card_carousel;
30 31 #[cfg(test)]
@@ -25,6 +25,7 @@ pub mod call_stage;
25pub mod call_transcript;
25pub mod call_transcript;
26pub mod call_view;
26pub mod call_view;
27pub mod call_view_menu;
27pub mod call_view_menu;
28pub mod calendar_view;
28pub mod calls_tab;
29pub mod calls_tab;
29pub mod card_carousel;
30pub mod card_carousel;
30#[cfg(test)]
31#[cfg(test)]
crates/app/src/views/rail.rs +15 −6
@@ -73,6 +73,13 @@ fn rail_items(
73 73 RailBadge::None
74 74 },
75 75 },
76 RailItem {
77 tab: SidebarTab::Calendar,
78 label: "Calendar",
79 shortcut_label: "Open Calendar",
80 icon: IconName::Calendar,
81 badge: RailBadge::None,
82 },
76 83 RailItem {
77 84 tab: SidebarTab::Calls,
78 85 label: "Calls",
@@ -267,6 +274,7 @@ mod tests {
267 274 SidebarTab::Activity,
268 275 SidebarTab::Chats,
269 276 SidebarTab::Channels,
277 SidebarTab::Calendar,
270 278 SidebarTab::Calls,
271 279 SidebarTab::Saved
272 280 ]
@@ -275,13 +283,13 @@ mod tests {
275 283
276 284 #[test]
277 285 fn agents_comes_last_and_only_when_actions_exist() {
278 assert_eq!(rail_items(0, 0, false, None).len(), 5);
286 assert_eq!(rail_items(0, 0, false, None).len(), 6);
279 287 let with_agents = rail_items(0, 0, false, Some(2));
280 assert_eq!(with_agents.len(), 6);
281 assert_eq!(with_agents[5].tab, SidebarTab::Agents);
282 assert_eq!(with_agents[5].label, "Agents");
283 assert_eq!(with_agents[5].badge, RailBadge::Count(2));
284 assert_eq!(rail_items(0, 0, false, Some(0))[5].badge, RailBadge::None);
288 assert_eq!(with_agents.len(), 7);
289 assert_eq!(with_agents[6].tab, SidebarTab::Agents);
290 assert_eq!(with_agents[6].label, "Agents");
291 assert_eq!(with_agents[6].badge, RailBadge::Count(2));
292 assert_eq!(rail_items(0, 0, false, Some(0))[6].badge, RailBadge::None);
285 293 }
286 294
287 295 #[test]
@@ -292,6 +300,7 @@ mod tests {
292 300 assert_eq!(items[2].badge, RailBadge::Dot);
293 301 assert_eq!(items[3].badge, RailBadge::None);
294 302 assert_eq!(items[4].badge, RailBadge::None);
303 assert_eq!(items[5].badge, RailBadge::None);
295 304 let quiet = rail_items(0, 0, false, None);
296 305 assert!(quiet.iter().all(|item| item.badge == RailBadge::None));
297 306 assert_eq!(count_badge_for(usize::MAX), RailBadge::Count(u32::MAX));
@@ -73,6 +73,13 @@ fn rail_items(
73 RailBadge::None
73 RailBadge::None
74 },
74 },
75 },
75 },
76 RailItem {
77 tab: SidebarTab::Calendar,
78 label: "Calendar",
79 shortcut_label: "Open Calendar",
80 icon: IconName::Calendar,
81 badge: RailBadge::None,
82 },
76 RailItem {
83 RailItem {
77 tab: SidebarTab::Calls,
84 tab: SidebarTab::Calls,
78 label: "Calls",
85 label: "Calls",
@@ -267,6 +274,7 @@ mod tests {
267 SidebarTab::Activity,
274 SidebarTab::Activity,
268 SidebarTab::Chats,
275 SidebarTab::Chats,
269 SidebarTab::Channels,
276 SidebarTab::Channels,
277 SidebarTab::Calendar,
270 SidebarTab::Calls,
278 SidebarTab::Calls,
271 SidebarTab::Saved
279 SidebarTab::Saved
272 ]
280 ]
@@ -275,13 +283,13 @@ mod tests {
275
283
276 #[test]
284 #[test]
277 fn agents_comes_last_and_only_when_actions_exist() {
285 fn agents_comes_last_and_only_when_actions_exist() {
278 assert_eq!(rail_items(0, 0, false, None).len(), 5);
286 assert_eq!(rail_items(0, 0, false, None).len(), 6);
279 let with_agents = rail_items(0, 0, false, Some(2));
287 let with_agents = rail_items(0, 0, false, Some(2));
280 assert_eq!(with_agents.len(), 6);
288 assert_eq!(with_agents.len(), 7);
281 assert_eq!(with_agents[5].tab, SidebarTab::Agents);
289 assert_eq!(with_agents[6].tab, SidebarTab::Agents);
282 assert_eq!(with_agents[5].label, "Agents");
290 assert_eq!(with_agents[6].label, "Agents");
283 assert_eq!(with_agents[5].badge, RailBadge::Count(2));
291 assert_eq!(with_agents[6].badge, RailBadge::Count(2));
284 assert_eq!(rail_items(0, 0, false, Some(0))[5].badge, RailBadge::None);
292 assert_eq!(rail_items(0, 0, false, Some(0))[6].badge, RailBadge::None);
285 }
293 }
286
294
287 #[test]
295 #[test]
@@ -292,6 +300,7 @@ mod tests {
292 assert_eq!(items[2].badge, RailBadge::Dot);
300 assert_eq!(items[2].badge, RailBadge::Dot);
293 assert_eq!(items[3].badge, RailBadge::None);
301 assert_eq!(items[3].badge, RailBadge::None);
294 assert_eq!(items[4].badge, RailBadge::None);
302 assert_eq!(items[4].badge, RailBadge::None);
303 assert_eq!(items[5].badge, RailBadge::None);
295 let quiet = rail_items(0, 0, false, None);
304 let quiet = rail_items(0, 0, false, None);
296 assert!(quiet.iter().all(|item| item.badge == RailBadge::None));
305 assert!(quiet.iter().all(|item| item.badge == RailBadge::None));
297 assert_eq!(count_badge_for(usize::MAX), RailBadge::Count(u32::MAX));
306 assert_eq!(count_badge_for(usize::MAX), RailBadge::Count(u32::MAX));
crates/app/src/views/shell.rs +61 −9
@@ -11,6 +11,7 @@ use super::call_stage::{render_call_overlay, render_stage_overlay};
11 11 use super::call_end_view::render_call_end;
12 12 use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
13 13 use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};
14 use super::calendar_view::CalendarView;
14 15 use super::conversation::ConversationView;
15 16 use super::dialog_overlay::render_task_dialog;
16 17 use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
@@ -24,7 +25,7 @@ use super::saved_panel::{SavedPanel, SavedPanelEvent};
24 25 use super::shortcuts::{
25 26 ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats,
26 27 FilterNonMeetingChats, FilterUnreadChats, FindInChat, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
27 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, PopOutSelectedChat, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
28 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, PopOutSelectedChat, OpenLobbyList, OpenSaved, OpenCalendar, PreviousConversation, PushToTalk,
28 29 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
29 30 ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,
30 31 ZoomShareReset,
@@ -33,7 +34,7 @@ use super::window_zoom::{WindowZoom, change_zoom};
33 34 use super::call_pop_out::zoom_listener;
34 35 use super::chat_pop_out;
35 36 use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
36 use super::sidebar::{SidebarEvent, SidebarView};
37 use super::sidebar::{SidebarEvent, SidebarTab, SidebarView};
37 38 use app_ui_kit::render::hooks::RenderHooks;
38 39 use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
39 40 use super::connection_banner::render_connection_banner;
@@ -152,6 +153,8 @@ pub struct AppShell {
152 153 state: Entity<AppState>,
153 154 rail: Entity<RailView>,
154 155 sidebar: Entity<SidebarView>,
156 calendar: Entity<CalendarView>,
157 shown_selection: Option<Selection>,
155 158 conversation: Entity<ConversationView>,
156 159 call_chat: Option<(String, Entity<ConversationView>)>,
157 160 prejoin: Option<Entity<PrejoinView>>,
@@ -209,6 +212,25 @@ impl AppShell {
209 212 }
210 213 }
211 214
215 fn leave_calendar_on_selection(&mut self, cx: &mut Context<Self>) {
216 let selection = self.state.read(cx).selection.clone();
217 if selection == self.shown_selection {
218 return;
219 }
220 self.shown_selection = selection.clone();
221 if self.sidebar.read(cx).tab() != SidebarTab::Calendar {
222 return;
223 }
224 let sidebar = self.sidebar.clone();
225 cx.defer(move |cx| {
226 sidebar.update(cx, |sidebar, cx| match selection {
227 Some(Selection::Channel(_)) => sidebar.show_channels(cx),
228 Some(Selection::Chat(_)) => sidebar.show_chats(cx),
229 None => {}
230 })
231 });
232 }
233
212 234 fn sync_prejoin(&mut self, window: &mut Window, cx: &mut Context<Self>) {
213 235 let wanted = self.state.read(cx).prejoin.clone();
214 236 let open = self.prejoin.as_ref().map(|view| view.read(cx).pending_id());
@@ -297,9 +319,18 @@ impl AppShell {
297 319 )
298 320 });
299 321 let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));
300 let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, _: &SidebarEvent, window, cx| {
301 this.restore_focus(window, cx);
322 let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, event: &SidebarEvent, window, cx| {
323 match event {
324 SidebarEvent::RestoreFocus => this.restore_focus(window, cx),
325 SidebarEvent::TabChanged => {
326 if this.sidebar.read(cx).tab() == SidebarTab::Calendar {
327 this.restore_focus(window, cx);
328 }
329 cx.notify();
330 }
331 }
302 332 });
333 let calendar = cx.new(|cx| CalendarView::new(state.clone(), cx));
303 334 let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));
304 335 let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));
305 336 let timeline = conversation.read(cx).timeline_bounds();
@@ -357,6 +388,8 @@ impl AppShell {
357 388 state,
358 389 rail,
359 390 sidebar,
391 calendar,
392 shown_selection: None,
360 393 conversation,
361 394 call_chat: None,
362 395 prejoin: None,
@@ -842,7 +875,12 @@ impl AppShell {
842 875 }
843 876
844 877 impl AppShell {
845 fn islands(&self, call_view: Option<AnyElement>, show_sidebar: bool) -> impl IntoElement {
878 fn islands(
879 &self,
880 call_view: Option<AnyElement>,
881 show_sidebar: bool,
882 calendar_open: bool,
883 ) -> impl IntoElement {
846 884 h_flex()
847 885 .debug_selector(|| "shell/islands".into())
848 886 .flex_1()
@@ -872,6 +910,11 @@ impl AppShell {
872 910 (None, Some(prejoin)) => prejoin
873 911 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
874 912 .into_any_element(),
913 (None, None) if calendar_open => self
914 .calendar
915 .clone()
916 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
917 .into_any_element(),
875 918 (None, None) => self
876 919 .conversation
877 920 .clone()
@@ -930,6 +973,7 @@ impl Render for AppShell {
930 973 let chat_thread = self.state.read(cx).call_chat_thread();
931 974 self.sync_call_chat(chat_thread, window, cx);
932 975 self.sync_prejoin(window, cx);
976 self.leave_calendar_on_selection(cx);
933 977 let notice = self.state.read(cx).notice.clone();
934 978 self.toasts.sync(&self.state, notice.as_ref(), window, cx);
935 979 let update_failure = match &self.update {
@@ -938,6 +982,7 @@ impl Render for AppShell {
938 982 };
939 983 self.toasts.update_failed(update_failure.as_deref(), window, cx);
940 984 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
985 let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar;
941 986 let state = self.state.read(cx);
942 987 let call_fullscreen = state.call_fullscreen();
943 988 let window_width = f32::from(window.viewport_size().width);
@@ -945,9 +990,11 @@ impl Render for AppShell {
945 990 .call
946 991 .as_ref()
947 992 .is_some_and(|call| call.chat_open || call.people_open || call.transcript_open);
948 let show_sidebar = !(state.viewing_call()
949 && !call_fullscreen
950 && sidebar_hidden_in_call(window_width, panel_open));
993 let calendar_open = calendar_tab && !state.viewing_call();
994 let show_sidebar = !calendar_open
995 && !(state.viewing_call()
996 && !call_fullscreen
997 && sidebar_hidden_in_call(window_width, panel_open));
951 998 let island_width = window_width
952 999 - RAIL_WIDTH
953 1000 - if show_sidebar { SIDEBAR_WIDTH } else { 0. }
@@ -1036,6 +1083,11 @@ impl Render for AppShell {
1036 1083 this.sidebar
1037 1084 .update(cx, |sidebar, cx| sidebar.show_saved(cx));
1038 1085 }))
1086 .on_action(cx.listener(|this, _: &OpenCalendar, window, cx| {
1087 this.close_image_viewer(window, cx);
1088 this.sidebar
1089 .update(cx, |sidebar, cx| sidebar.show_calendar(cx));
1090 }))
1039 1091 .on_action(cx.listener(|this, _: &OpenAgents, window, cx| {
1040 1092 this.close_image_viewer(window, cx);
1041 1093 this.sidebar
@@ -1178,7 +1230,7 @@ impl Render for AppShell {
1178 1230 .size_full()
1179 1231 .child(title_bar)
1180 1232 .children(banner)
1181 .child(self.islands(call_view, show_sidebar)),
1233 .child(self.islands(call_view, show_sidebar, calendar_open)),
1182 1234 )
1183 1235 .children(call_mini)
1184 1236 .children(call_overlay)
@@ -11,6 +11,7 @@ use super::call_stage::{render_call_overlay, render_stage_overlay};
11use super::call_end_view::render_call_end;
11use super::call_end_view::render_call_end;
12use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
12use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
13use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};
13use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};
14use super::calendar_view::CalendarView;
14use super::conversation::ConversationView;
15use super::conversation::ConversationView;
15use super::dialog_overlay::render_task_dialog;
16use super::dialog_overlay::render_task_dialog;
16use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
17use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
@@ -24,7 +25,7 @@ use super::saved_panel::{SavedPanel, SavedPanelEvent};
24use super::shortcuts::{
25use super::shortcuts::{
25 ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats,
26 ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats,
26 FilterNonMeetingChats, FilterUnreadChats, FindInChat, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
27 FilterNonMeetingChats, FilterUnreadChats, FindInChat, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
27 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, PopOutSelectedChat, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
28 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, PopOutSelectedChat, OpenLobbyList, OpenSaved, OpenCalendar, PreviousConversation, PushToTalk,
28 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
29 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
29 ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,
30 ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,
30 ZoomShareReset,
31 ZoomShareReset,
@@ -33,7 +34,7 @@ use super::window_zoom::{WindowZoom, change_zoom};
33use super::call_pop_out::zoom_listener;
34use super::call_pop_out::zoom_listener;
34use super::chat_pop_out;
35use super::chat_pop_out;
35use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
36use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
36use super::sidebar::{SidebarEvent, SidebarView};
37use super::sidebar::{SidebarEvent, SidebarTab, SidebarView};
37use app_ui_kit::render::hooks::RenderHooks;
38use app_ui_kit::render::hooks::RenderHooks;
38use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
39use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
39use super::connection_banner::render_connection_banner;
40use super::connection_banner::render_connection_banner;
@@ -152,6 +153,8 @@ pub struct AppShell {
152 state: Entity<AppState>,
153 state: Entity<AppState>,
153 rail: Entity<RailView>,
154 rail: Entity<RailView>,
154 sidebar: Entity<SidebarView>,
155 sidebar: Entity<SidebarView>,
156 calendar: Entity<CalendarView>,
157 shown_selection: Option<Selection>,
155 conversation: Entity<ConversationView>,
158 conversation: Entity<ConversationView>,
156 call_chat: Option<(String, Entity<ConversationView>)>,
159 call_chat: Option<(String, Entity<ConversationView>)>,
157 prejoin: Option<Entity<PrejoinView>>,
160 prejoin: Option<Entity<PrejoinView>>,
@@ -209,6 +212,25 @@ impl AppShell {
209 }
212 }
210 }
213 }
211
214
215 fn leave_calendar_on_selection(&mut self, cx: &mut Context<Self>) {
216 let selection = self.state.read(cx).selection.clone();
217 if selection == self.shown_selection {
218 return;
219 }
220 self.shown_selection = selection.clone();
221 if self.sidebar.read(cx).tab() != SidebarTab::Calendar {
222 return;
223 }
224 let sidebar = self.sidebar.clone();
225 cx.defer(move |cx| {
226 sidebar.update(cx, |sidebar, cx| match selection {
227 Some(Selection::Channel(_)) => sidebar.show_channels(cx),
228 Some(Selection::Chat(_)) => sidebar.show_chats(cx),
229 None => {}
230 })
231 });
232 }
233
212 fn sync_prejoin(&mut self, window: &mut Window, cx: &mut Context<Self>) {
234 fn sync_prejoin(&mut self, window: &mut Window, cx: &mut Context<Self>) {
213 let wanted = self.state.read(cx).prejoin.clone();
235 let wanted = self.state.read(cx).prejoin.clone();
214 let open = self.prejoin.as_ref().map(|view| view.read(cx).pending_id());
236 let open = self.prejoin.as_ref().map(|view| view.read(cx).pending_id());
@@ -297,9 +319,18 @@ impl AppShell {
297 )
319 )
298 });
320 });
299 let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));
321 let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));
300 let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, _: &SidebarEvent, window, cx| {
322 let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, event: &SidebarEvent, window, cx| {
301 this.restore_focus(window, cx);
323 match event {
324 SidebarEvent::RestoreFocus => this.restore_focus(window, cx),
325 SidebarEvent::TabChanged => {
326 if this.sidebar.read(cx).tab() == SidebarTab::Calendar {
327 this.restore_focus(window, cx);
328 }
329 cx.notify();
330 }
331 }
302 });
332 });
333 let calendar = cx.new(|cx| CalendarView::new(state.clone(), cx));
303 let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));
334 let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));
304 let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));
335 let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));
305 let timeline = conversation.read(cx).timeline_bounds();
336 let timeline = conversation.read(cx).timeline_bounds();
@@ -357,6 +388,8 @@ impl AppShell {
357 state,
388 state,
358 rail,
389 rail,
359 sidebar,
390 sidebar,
391 calendar,
392 shown_selection: None,
360 conversation,
393 conversation,
361 call_chat: None,
394 call_chat: None,
362 prejoin: None,
395 prejoin: None,
@@ -842,7 +875,12 @@ impl AppShell {
842}
875}
843
876
844impl AppShell {
877impl AppShell {
845 fn islands(&self, call_view: Option<AnyElement>, show_sidebar: bool) -> impl IntoElement {
878 fn islands(
879 &self,
880 call_view: Option<AnyElement>,
881 show_sidebar: bool,
882 calendar_open: bool,
883 ) -> impl IntoElement {
846 h_flex()
884 h_flex()
847 .debug_selector(|| "shell/islands".into())
885 .debug_selector(|| "shell/islands".into())
848 .flex_1()
886 .flex_1()
@@ -872,6 +910,11 @@ impl AppShell {
872 (None, Some(prejoin)) => prejoin
910 (None, Some(prejoin)) => prejoin
873 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
911 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
874 .into_any_element(),
912 .into_any_element(),
913 (None, None) if calendar_open => self
914 .calendar
915 .clone()
916 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
917 .into_any_element(),
875 (None, None) => self
918 (None, None) => self
876 .conversation
919 .conversation
877 .clone()
920 .clone()
@@ -930,6 +973,7 @@ impl Render for AppShell {
930 let chat_thread = self.state.read(cx).call_chat_thread();
973 let chat_thread = self.state.read(cx).call_chat_thread();
931 self.sync_call_chat(chat_thread, window, cx);
974 self.sync_call_chat(chat_thread, window, cx);
932 self.sync_prejoin(window, cx);
975 self.sync_prejoin(window, cx);
976 self.leave_calendar_on_selection(cx);
933 let notice = self.state.read(cx).notice.clone();
977 let notice = self.state.read(cx).notice.clone();
934 self.toasts.sync(&self.state, notice.as_ref(), window, cx);
978 self.toasts.sync(&self.state, notice.as_ref(), window, cx);
935 let update_failure = match &self.update {
979 let update_failure = match &self.update {
@@ -938,6 +982,7 @@ impl Render for AppShell {
938 };
982 };
939 self.toasts.update_failed(update_failure.as_deref(), window, cx);
983 self.toasts.update_failed(update_failure.as_deref(), window, cx);
940 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
984 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
985 let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar;
941 let state = self.state.read(cx);
986 let state = self.state.read(cx);
942 let call_fullscreen = state.call_fullscreen();
987 let call_fullscreen = state.call_fullscreen();
943 let window_width = f32::from(window.viewport_size().width);
988 let window_width = f32::from(window.viewport_size().width);
@@ -945,9 +990,11 @@ impl Render for AppShell {
945 .call
990 .call
946 .as_ref()
991 .as_ref()
947 .is_some_and(|call| call.chat_open || call.people_open || call.transcript_open);
992 .is_some_and(|call| call.chat_open || call.people_open || call.transcript_open);
948 let show_sidebar = !(state.viewing_call()
993 let calendar_open = calendar_tab && !state.viewing_call();
949 && !call_fullscreen
994 let show_sidebar = !calendar_open
950 && sidebar_hidden_in_call(window_width, panel_open));
995 && !(state.viewing_call()
996 && !call_fullscreen
997 && sidebar_hidden_in_call(window_width, panel_open));
951 let island_width = window_width
998 let island_width = window_width
952 - RAIL_WIDTH
999 - RAIL_WIDTH
953 - if show_sidebar { SIDEBAR_WIDTH } else { 0. }
1000 - if show_sidebar { SIDEBAR_WIDTH } else { 0. }
@@ -1036,6 +1083,11 @@ impl Render for AppShell {
1036 this.sidebar
1083 this.sidebar
1037 .update(cx, |sidebar, cx| sidebar.show_saved(cx));
1084 .update(cx, |sidebar, cx| sidebar.show_saved(cx));
1038 }))
1085 }))
1086 .on_action(cx.listener(|this, _: &OpenCalendar, window, cx| {
1087 this.close_image_viewer(window, cx);
1088 this.sidebar
1089 .update(cx, |sidebar, cx| sidebar.show_calendar(cx));
1090 }))
1039 .on_action(cx.listener(|this, _: &OpenAgents, window, cx| {
1091 .on_action(cx.listener(|this, _: &OpenAgents, window, cx| {
1040 this.close_image_viewer(window, cx);
1092 this.close_image_viewer(window, cx);
1041 this.sidebar
1093 this.sidebar
@@ -1178,7 +1230,7 @@ impl Render for AppShell {
1178 .size_full()
1230 .size_full()
1179 .child(title_bar)
1231 .child(title_bar)
1180 .children(banner)
1232 .children(banner)
1181 .child(self.islands(call_view, show_sidebar)),
1233 .child(self.islands(call_view, show_sidebar, calendar_open)),
1182 )
1234 )
1183 .children(call_mini)
1235 .children(call_mini)
1184 .children(call_overlay)
1236 .children(call_overlay)
crates/app/src/views/shortcuts.rs +2 −0
@@ -30,6 +30,7 @@ actions!(
30 30 OpenChatsTab,
31 31 OpenChannelsTab,
32 32 OpenSaved,
33 OpenCalendar,
33 34 OpenCallsTab,
34 35 OpenAgents,
35 36 OpenChatFilter,
@@ -154,6 +155,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
154 155 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
155 156 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
156 157 shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved),
158 shortcut!(Navigation, GlobalOverTextFields, "Open Calendar", "ctrl-shift-4", Some("cmd-shift-4"), OpenCalendar),
157 159 shortcut!(Navigation, GlobalOverTextFields, "Show Calls", "ctrl-5", Some("cmd-5"), OpenCallsTab),
158 160 shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),
159 161 shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
@@ -30,6 +30,7 @@ actions!(
30 OpenChatsTab,
30 OpenChatsTab,
31 OpenChannelsTab,
31 OpenChannelsTab,
32 OpenSaved,
32 OpenSaved,
33 OpenCalendar,
33 OpenCallsTab,
34 OpenCallsTab,
34 OpenAgents,
35 OpenAgents,
35 OpenChatFilter,
36 OpenChatFilter,
@@ -154,6 +155,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
154 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
155 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
155 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
156 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
156 shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved),
157 shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved),
158 shortcut!(Navigation, GlobalOverTextFields, "Open Calendar", "ctrl-shift-4", Some("cmd-shift-4"), OpenCalendar),
157 shortcut!(Navigation, GlobalOverTextFields, "Show Calls", "ctrl-5", Some("cmd-5"), OpenCallsTab),
159 shortcut!(Navigation, GlobalOverTextFields, "Show Calls", "ctrl-5", Some("cmd-5"), OpenCallsTab),
158 shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),
160 shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),
159 shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
161 shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
crates/app/src/views/sidebar.rs +19 −4
@@ -92,6 +92,7 @@ pub enum SidebarTab {
92 92 Activity,
93 93 Chats,
94 94 Channels,
95 Calendar,
95 96 Calls,
96 97 Saved,
97 98 Agents,
@@ -103,6 +104,7 @@ impl SidebarTab {
103 104 SidebarTab::Activity => "Activity",
104 105 SidebarTab::Chats => "Chats",
105 106 SidebarTab::Channels => "Channels",
107 SidebarTab::Calendar => "Calendar",
106 108 SidebarTab::Calls => "Calls",
107 109 SidebarTab::Saved => "Saved",
108 110 SidebarTab::Agents => "Agents",
@@ -651,6 +653,7 @@ pub(crate) fn confirm_leave(
651 653
652 654 pub enum SidebarEvent {
653 655 RestoreFocus,
656 TabChanged,
654 657 }
655 658
656 659 impl EventEmitter<SidebarEvent> for SidebarView {}
@@ -835,6 +838,10 @@ impl SidebarView {
835 838 self.open_tab(SidebarTab::Calls, cx);
836 839 }
837 840
841 pub fn show_calendar(&mut self, cx: &mut Context<Self>) {
842 self.open_tab(SidebarTab::Calendar, cx);
843 }
844
838 845 pub fn show_saved(&mut self, cx: &mut Context<Self>) {
839 846 self.open_tab(SidebarTab::Saved, cx);
840 847 }
@@ -847,13 +854,18 @@ impl SidebarView {
847 854 if tab == SidebarTab::Agents && !crate::agents::agents_enabled(cx) {
848 855 return;
849 856 }
857 let changed = self.tab != tab;
850 858 self.tab = tab;
859 if changed {
860 cx.emit(SidebarEvent::TabChanged);
861 }
851 862 match tab {
852 863 SidebarTab::Calls => self.state.update(cx, |state, cx| {
853 864 state.refresh_call_history(cx);
854 865 state.refresh_calendar(cx);
855 866 }),
856 867 SidebarTab::Saved => self.state.update(cx, |state, cx| state.refresh_saved(cx)),
868 SidebarTab::Calendar => self.state.update(cx, |state, cx| state.open_calendar(cx)),
857 869 SidebarTab::Activity => {
858 870 let activity = self.activity_panel.read(cx).activity();
859 871 activity.update(cx, |activity, cx| activity.mark_seen(cx));
@@ -871,9 +883,11 @@ impl SidebarView {
871 883 .adjacent_chat_id(step)
872 884 .map(Selection::Chat),
873 885 SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel),
874 SidebarTab::Activity | SidebarTab::Calls | SidebarTab::Saved | SidebarTab::Agents => {
875 None
876 }
886 SidebarTab::Activity
887 | SidebarTab::Calendar
888 | SidebarTab::Calls
889 | SidebarTab::Saved
890 | SidebarTab::Agents => None,
877 891 };
878 892 if let Some(selection) = selection {
879 893 self.state
@@ -2229,6 +2243,7 @@ impl Render for SidebarView {
2229 2243 Some(panel) => panel.clone().into_any_element(),
2230 2244 None => div().into_any_element(),
2231 2245 },
2246 SidebarTab::Calendar => div().into_any_element(),
2232 2247 };
2233 2248 let header = match self.tab {
2234 2249 SidebarTab::Chats => Some(
@@ -2246,7 +2261,7 @@ impl Render for SidebarView {
2246 2261 Some(page_header(self.tab.title()).child(self.channel_list_menu_button(cx)))
2247 2262 }
2248 2263 SidebarTab::Calls | SidebarTab::Agents => Some(page_header(self.tab.title())),
2249 SidebarTab::Activity | SidebarTab::Saved => None,
2264 SidebarTab::Activity | SidebarTab::Saved | SidebarTab::Calendar => None,
2250 2265 };
2251 2266 v_flex()
2252 2267 .debug_selector(|| "shell/islands/sidebar".into())
@@ -92,6 +92,7 @@ pub enum SidebarTab {
92 Activity,
92 Activity,
93 Chats,
93 Chats,
94 Channels,
94 Channels,
95 Calendar,
95 Calls,
96 Calls,
96 Saved,
97 Saved,
97 Agents,
98 Agents,
@@ -103,6 +104,7 @@ impl SidebarTab {
103 SidebarTab::Activity => "Activity",
104 SidebarTab::Activity => "Activity",
104 SidebarTab::Chats => "Chats",
105 SidebarTab::Chats => "Chats",
105 SidebarTab::Channels => "Channels",
106 SidebarTab::Channels => "Channels",
107 SidebarTab::Calendar => "Calendar",
106 SidebarTab::Calls => "Calls",
108 SidebarTab::Calls => "Calls",
107 SidebarTab::Saved => "Saved",
109 SidebarTab::Saved => "Saved",
108 SidebarTab::Agents => "Agents",
110 SidebarTab::Agents => "Agents",
@@ -651,6 +653,7 @@ pub(crate) fn confirm_leave(
651
653
652pub enum SidebarEvent {
654pub enum SidebarEvent {
653 RestoreFocus,
655 RestoreFocus,
656 TabChanged,
654}
657}
655
658
656impl EventEmitter<SidebarEvent> for SidebarView {}
659impl EventEmitter<SidebarEvent> for SidebarView {}
@@ -835,6 +838,10 @@ impl SidebarView {
835 self.open_tab(SidebarTab::Calls, cx);
838 self.open_tab(SidebarTab::Calls, cx);
836 }
839 }
837
840
841 pub fn show_calendar(&mut self, cx: &mut Context<Self>) {
842 self.open_tab(SidebarTab::Calendar, cx);
843 }
844
838 pub fn show_saved(&mut self, cx: &mut Context<Self>) {
845 pub fn show_saved(&mut self, cx: &mut Context<Self>) {
839 self.open_tab(SidebarTab::Saved, cx);
846 self.open_tab(SidebarTab::Saved, cx);
840 }
847 }
@@ -847,13 +854,18 @@ impl SidebarView {
847 if tab == SidebarTab::Agents && !crate::agents::agents_enabled(cx) {
854 if tab == SidebarTab::Agents && !crate::agents::agents_enabled(cx) {
848 return;
855 return;
849 }
856 }
857 let changed = self.tab != tab;
850 self.tab = tab;
858 self.tab = tab;
859 if changed {
860 cx.emit(SidebarEvent::TabChanged);
861 }
851 match tab {
862 match tab {
852 SidebarTab::Calls => self.state.update(cx, |state, cx| {
863 SidebarTab::Calls => self.state.update(cx, |state, cx| {
853 state.refresh_call_history(cx);
864 state.refresh_call_history(cx);
854 state.refresh_calendar(cx);
865 state.refresh_calendar(cx);
855 }),
866 }),
856 SidebarTab::Saved => self.state.update(cx, |state, cx| state.refresh_saved(cx)),
867 SidebarTab::Saved => self.state.update(cx, |state, cx| state.refresh_saved(cx)),
868 SidebarTab::Calendar => self.state.update(cx, |state, cx| state.open_calendar(cx)),
857 SidebarTab::Activity => {
869 SidebarTab::Activity => {
858 let activity = self.activity_panel.read(cx).activity();
870 let activity = self.activity_panel.read(cx).activity();
859 activity.update(cx, |activity, cx| activity.mark_seen(cx));
871 activity.update(cx, |activity, cx| activity.mark_seen(cx));
@@ -871,9 +883,11 @@ impl SidebarView {
871 .adjacent_chat_id(step)
883 .adjacent_chat_id(step)
872 .map(Selection::Chat),
884 .map(Selection::Chat),
873 SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel),
885 SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel),
874 SidebarTab::Activity | SidebarTab::Calls | SidebarTab::Saved | SidebarTab::Agents => {
886 SidebarTab::Activity
875 None
887 | SidebarTab::Calendar
876 }
888 | SidebarTab::Calls
889 | SidebarTab::Saved
890 | SidebarTab::Agents => None,
877 };
891 };
878 if let Some(selection) = selection {
892 if let Some(selection) = selection {
879 self.state
893 self.state
@@ -2229,6 +2243,7 @@ impl Render for SidebarView {
2229 Some(panel) => panel.clone().into_any_element(),
2243 Some(panel) => panel.clone().into_any_element(),
2230 None => div().into_any_element(),
2244 None => div().into_any_element(),
2231 },
2245 },
2246 SidebarTab::Calendar => div().into_any_element(),
2232 };
2247 };
2233 let header = match self.tab {
2248 let header = match self.tab {
2234 SidebarTab::Chats => Some(
2249 SidebarTab::Chats => Some(
@@ -2246,7 +2261,7 @@ impl Render for SidebarView {
2246 Some(page_header(self.tab.title()).child(self.channel_list_menu_button(cx)))
2261 Some(page_header(self.tab.title()).child(self.channel_list_menu_button(cx)))
2247 }
2262 }
2248 SidebarTab::Calls | SidebarTab::Agents => Some(page_header(self.tab.title())),
2263 SidebarTab::Calls | SidebarTab::Agents => Some(page_header(self.tab.title())),
2249 SidebarTab::Activity | SidebarTab::Saved => None,
2264 SidebarTab::Activity | SidebarTab::Saved | SidebarTab::Calendar => None,
2250 };
2265 };
2251 v_flex()
2266 v_flex()
2252 .debug_selector(|| "shell/islands/sidebar".into())
2267 .debug_selector(|| "shell/islands/sidebar".into())