BlueGit

ict rusty-teams

Files

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

calendar_view.rs

calendar_view.rs 30.8 KiB Download Raw
1use std::time::Duration;
2
3use app_base::format::{self, clock_format};
4use chatsvc::{CalendarEvent, ResponseType, join_info_text};
5use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};
6use gpui_kit::assets::IconName;
7use gpui_kit::component::Sizable as _;
8use gpui_kit::component::button::{Button, ButtonVariants as _};
9use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem};
10use gpui_kit::component::{h_flex, v_flex};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use super::calendar_date_picker::date_picker_button;
15use super::calendar_event_dialog::open_calendar_event;
16use super::calendar_month::month_grid;
17use super::calendar_picker;
18use super::join_dialog::open_join_with_id;
19use super::meeting_proposal_card::meeting_proposal_cards;
20use super::new_meeting_dialog::open_new_meeting;
21use super::rsvp_menu::rsvp_menu;
22use super::scroll_edge::scroll_offset;
23use crate::app_state::AppState;
24use crate::call::calendar_now::{
25 DEFAULT_GRID_VIEWPORT, FollowNow, MANUAL_SCROLL_EPSILON, NOW_BIAS_FRACTION,
26 now_scroll_offset_y, offset_differs, shows_hour_grid,
27};
28use crate::call::week_grid::{
29 CalendarSpan, EventLook, WeekBlock, WeekDay, event_look, hour_label, month_shown, week_days,
30};
31use crate::i18n::tr;
32use crate::theme;
33
34const HOUR_HEIGHT: f32 = 120.;
35const QUARTERS_PER_HOUR: usize = 4;
36const QUARTER_LINE_OPACITY: f32 = 0.45;
37const GUTTER_WIDTH: f32 = 50.;
38const HEADER_HEIGHT: f32 = 52.;
39const DAY_HEADER_HEIGHT: f32 = 56.;
40const ALL_DAY_HEIGHT: f32 = 26.;
41const BLOCK_GAP: f32 = 2.;
42const CANCELED_PREFIX: &str = "Canceled: ";
43const COPY_JOIN_INFO: &str = "Copy join info";
44const COMPACT_HEADER_WIDTH: f32 = 960.;
45const BUSY_FILL_OPACITY: f32 = 0.28;
46const FREE_FILL_OPACITY: f32 = 0.12;
47const STATUS_BAR_WIDTH: f32 = 4.;
48const HATCH_STRIPE: f32 = 1.5;
49const HATCH_GAP: f32 = 2.5;
50const SMALL_TITLE_HEIGHT: f32 = 20.;
51const TODAY_MARK_HEIGHT: f32 = 3.;
52const NOW_DOT_SIZE: f32 = 8.;
53const CLOCK_TICK: Duration = Duration::from_secs(30);
54const CHROME_HEIGHT: f32 = HEADER_HEIGHT + DAY_HEADER_HEIGHT + ALL_DAY_HEIGHT;
55
56pub struct CalendarView {
57 state: Entity<AppState>,
58 scroll: ScrollHandle,
59 follow_now: FollowNow,
60 seen_scroll_to_now: u64,
61 last_programmatic_offset: f32,
62 skip_manual_check: bool,
63 clock_running: bool,
64 _observation: Subscription,
65 _agent_observation: Option<Subscription>,
66}
67
68impl CalendarView {
69 pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {
70 let observation = cx.observe(&state, |_, _, cx| cx.notify());
71 let agent_observation =
72 crate::agent_api::handle(cx).map(|api| cx.observe(&api, |_, _, cx| cx.notify()));
73 CalendarView {
74 state,
75 scroll: ScrollHandle::new(),
76 follow_now: FollowNow { active: true },
77 seen_scroll_to_now: 0,
78 last_programmatic_offset: 0.,
79 skip_manual_check: false,
80 clock_running: false,
81 _observation: observation,
82 _agent_observation: agent_observation,
83 }
84 }
85
86 fn grid_viewport_height(window: &Window) -> f32 {
87 (f32::from(window.viewport_size().height) - CHROME_HEIGHT).max(DEFAULT_GRID_VIEWPORT * 0.5)
88 }
89
90 fn align_scroll_to_now(&mut self, window: &Window) {
91 let local = Local::now();
92 let offset = now_scroll_offset_y(
93 local.hour(),
94 local.minute(),
95 HOUR_HEIGHT,
96 Self::grid_viewport_height(window),
97 NOW_BIAS_FRACTION,
98 );
99 self.scroll.set_offset(point(px(0.), px(offset)));
100 self.last_programmatic_offset = offset;
101 self.skip_manual_check = true;
102 }
103
104 fn sync_follow_from_state(&mut self, window: &Window, cx: &mut Context<Self>) {
105 let (scroll_to_now, span, today_visible) = {
106 let state = self.state.read(cx);
107 let start = state.calendar_start();
108 let today = Local::now().date_naive();
109 let today_visible = start <= today
110 && today < start + chrono::Duration::days(state.calendar_week.span.days());
111 (
112 state.calendar_scroll_to_now,
113 state.calendar_week.span,
114 today_visible,
115 )
116 };
117 if !shows_hour_grid(span) {
118 self.stop_clock();
119 return;
120 }
121 self.ensure_clock(cx);
122 if scroll_to_now != self.seen_scroll_to_now {
123 self.seen_scroll_to_now = scroll_to_now;
124 self.follow_now.request_align();
125 }
126 if self.skip_manual_check {
127 self.skip_manual_check = false;
128 } else if self.follow_now.active
129 && offset_differs(
130 f32::from(scroll_offset(&self.scroll).y),
131 self.last_programmatic_offset,
132 MANUAL_SCROLL_EPSILON,
133 )
134 {
135 self.follow_now.note_manual_scroll();
136 }
137 if self.follow_now.should_follow(today_visible) {
138 self.align_scroll_to_now(window);
139 }
140 }
141
142 fn ensure_clock(&mut self, cx: &mut Context<Self>) {
143 if self.clock_running {
144 return;
145 }
146 self.clock_running = true;
147 cx.spawn(async move |this, cx| {
148 loop {
149 cx.background_executor().timer(CLOCK_TICK).await;
150 let keep = this
151 .update(cx, |view, cx| {
152 let span = view.state.read(cx).calendar_week.span;
153 if !shows_hour_grid(span) {
154 view.clock_running = false;
155 return false;
156 }
157 cx.notify();
158 true
159 })
160 .unwrap_or(false);
161 if !keep {
162 break;
163 }
164 }
165 })
166 .detach();
167 }
168
169 fn stop_clock(&mut self) {
170 self.clock_running = false;
171 }
172
173 fn on_grid_scroll_wheel(
174 &mut self,
175 _event: &ScrollWheelEvent,
176 _window: &mut Window,
177 cx: &mut Context<Self>,
178 ) {
179 self.follow_now.note_manual_scroll();
180 cx.notify();
181 }
182
183 fn header(&self, start: NaiveDate, span: CalendarSpan, compact: bool) -> impl IntoElement {
184 let span_state = self.state.clone();
185 let label = |text: &'static str| (!compact).then_some(text);
186 let (today, back, forward) = (self.state.clone(), self.state.clone(), self.state.clone());
187 let (join_state, meet_state, new_state) =
188 (self.state.clone(), self.state.clone(), self.state.clone());
189 h_flex()
190 .h(px(HEADER_HEIGHT))
191 .flex_none()
192 .items_center()
193 .gap(px(8.))
194 .px(px(16.))
195 .child(
196 div()
197 .flex_none()
198 .text_size(px(16.))
199 .font_weight(FontWeight::BOLD)
200 .mr(px(8.))
201 .child("Calendar"),
202 )
203 .child(
204 Button::new("calendar-today")
205 .small()
206 .outline()
207 .icon(IconName::Calendar)
208 .when_some(label("Today"), |button, text| button.label(text))
209 .tooltip("Today")
210 .on_click(move |_, _, cx| {
211 today.update(cx, |state, cx| state.calendar_to_today(cx))
212 }),
213 )
214 .child(
215 Button::new("calendar-back")
216 .small()
217 .ghost()
218 .icon(IconName::ChevronLeft)
219 .tooltip(match span {
220 CalendarSpan::Day => "Go to previous day",
221 CalendarSpan::Month => "Go to previous month",
222 _ => "Go to previous week",
223 })
224 .on_click(move |_, _, cx| {
225 back.update(cx, |state, cx| state.shift_calendar_week(-1, cx))
226 }),
227 )
228 .child(
229 Button::new("calendar-forward")
230 .small()
231 .ghost()
232 .icon(IconName::ChevronRight)
233 .tooltip(match span {
234 CalendarSpan::Day => "Go to next day",
235 CalendarSpan::Month => "Go to next month",
236 _ => "Go to next week",
237 })
238 .on_click(move |_, _, cx| {
239 forward.update(cx, |state, cx| state.shift_calendar_week(1, cx))
240 }),
241 )
242 .child(h_flex().flex_1().min_w_0().child(date_picker_button(
243 &self.state,
244 span.title(start),
245 start,
246 span.days(),
247 if span == CalendarSpan::Month {
248 month_shown(start)
249 } else {
250 start
251 },
252 )))
253 .child(
254 Button::new("calendar-span")
255 .small()
256 .ghost()
257 .label(span.label())
258 .dropdown_caret(true)
259 .dropdown_menu(move |menu, _, _| {
260 CalendarSpan::ALL.iter().fold(menu, |menu, &choice| {
261 let state = span_state.clone();
262 menu.item(
263 PopupMenuItem::new(choice.label())
264 .checked(choice == span)
265 .on_click(move |_, _, cx| {
266 state.update(cx, |state, cx| {
267 state.set_calendar_span(choice, cx)
268 })
269 }),
270 )
271 })
272 }),
273 )
274 .child(
275 Button::new("calendar-join-id")
276 .small()
277 .outline()
278 .icon(IconName::Hash)
279 .when_some(label("Join with an ID"), |button, text| button.label(text))
280 .tooltip("Join with an ID")
281 .on_click(move |_, window, cx| {
282 open_join_with_id(join_state.clone(), window, cx)
283 }),
284 )
285 .child(
286 Button::new("calendar-meet-now")
287 .small()
288 .outline()
289 .icon(IconName::Video)
290 .when_some(label("Meet now"), |button, text| button.label(text))
291 .tooltip("Meet now")
292 .on_click(move |_, _, cx| {
293 meet_state.update(cx, |state, cx| state.start_meet_now(cx))
294 }),
295 )
296 .child(
297 Button::new("calendar-new-meeting")
298 .small()
299 .primary()
300 .icon(IconName::Plus)
301 .when_some(label("New meeting"), |button, text| button.label(text))
302 .tooltip("New meeting")
303 .on_click(move |_, window, cx| open_new_meeting(new_state.clone(), window, cx)),
304 )
305 }
306
307 fn day_headers(&self, days: &[WeekDay], today: NaiveDate) -> impl IntoElement {
308 h_flex()
309 .h(px(DAY_HEADER_HEIGHT))
310 .flex_none()
311 .border_b_1()
312 .border_color(theme::border())
313 .child(div().w(px(GUTTER_WIDTH)).flex_none())
314 .children(days.iter().map(|day| {
315 let is_today = day.date == today;
316 let color = if is_today {
317 theme::accent_text()
318 } else {
319 theme::text_soft()
320 };
321 v_flex()
322 .relative()
323 .flex_1()
324 .min_w_0()
325 .h_full()
326 .justify_center()
327 .px(px(12.))
328 .border_l_1()
329 .border_color(theme::border())
330 .when(is_today, |header| {
331 header.child(
332 div()
333 .absolute()
334 .top_0()
335 .left_0()
336 .right_0()
337 .h(px(TODAY_MARK_HEIGHT))
338 .bg(theme::accent()),
339 )
340 })
341 .child(
342 div()
343 .text_size(px(20.))
344 .line_height(px(24.))
345 .text_color(color)
346 .child(format::calendar_day_number(day.date)),
347 )
348 .child(
349 div()
350 .text_size(px(12.))
351 .text_color(color)
352 .child(day.date.format("%a").to_string()),
353 )
354 }))
355 }
356
357 fn all_day_row(
358 &self,
359 days: &[WeekDay],
360 events: &[CalendarEvent],
361 send_response: bool,
362 ) -> Option<Div> {
363 if days.iter().all(|day| day.all_day.is_empty()) {
364 return None;
365 }
366 Some(
367 h_flex()
368 .flex_none()
369 .border_b_1()
370 .border_color(theme::border())
371 .child(div().w(px(GUTTER_WIDTH)).flex_none())
372 .children(days.iter().map(|day| {
373 v_flex()
374 .flex_1()
375 .min_w_0()
376 .gap(px(BLOCK_GAP))
377 .p(px(BLOCK_GAP))
378 .border_l_1()
379 .border_color(theme::border())
380 .children(day.all_day.iter().map(|&index| {
381 let event = events[index].clone();
382 let open_state = self.state.clone();
383 let (menu_state, menu_event) = (self.state.clone(), event.clone());
384 // Day-qualified id: multi-day all-day chips share object_id.
385 div()
386 .id(SharedString::from(format!(
387 "calendar-all-day-{}-{}",
388 event.object_id, day.date
389 )))
390 .h(px(ALL_DAY_HEIGHT - 2. * BLOCK_GAP))
391 .px(px(6.))
392 .flex()
393 .items_center()
394 .rounded(px(4.))
395 .bg(event_fill(event_look(&event)))
396 .text_size(px(12.))
397 .truncate()
398 .cursor_pointer()
399 .child(event_title(&event))
400 .on_click(move |_, window, cx| {
401 open_calendar_event(
402 open_state.clone(),
403 event.clone(),
404 window,
405 cx,
406 );
407 })
408 .context_menu(move |menu, _, _| {
409 event_menu(menu, &menu_state, &menu_event, send_response)
410 })
411 }))
412 })),
413 )
414 }
415
416 fn event_block(
417 &self,
418 block: &WeekBlock,
419 event: &CalendarEvent,
420 day: NaiveDate,
421 send_response: bool,
422 ) -> impl IntoElement {
423 let top = block.start_minute as f32 / 60. * HOUR_HEIGHT;
424 let height = ((block.end_minute - block.start_minute) as f32 / 60. * HOUR_HEIGHT
425 - BLOCK_GAP)
426 .max(14.);
427 let width = 1. / block.lanes as f32;
428 let compact = height < 36.;
429 let small = height < SMALL_TITLE_HEIGHT;
430 let title_size = if small { 10. } else { 12. };
431 let title_line = if small { 14. } else { 18. };
432 let pad_y = if compact { 1. } else { 4. };
433 // Fill the block: long titles use the free height instead of clamping to 2 lines.
434 let title_lines = (((height - pad_y * 2.) / title_line).floor() as usize).clamp(1, 8);
435 let look = event_look(event);
436 // Join on the block whenever a Teams link exists (same as detail dialog).
437 // Skip on tiny blocks — the button would crush the title.
438 let can_join = !compact && event.online && !event.cancelled && event.join_url.is_some();
439 let open_state = self.state.clone();
440 let open_event = event.clone();
441 let (menu_state, menu_event) = (self.state.clone(), event.clone());
442 let (join_state, join_url, subject) = (
443 self.state.clone(),
444 event.join_url.clone(),
445 event.subject.clone(),
446 );
447 let (title_color, detail_color) = match look {
448 EventLook::Busy => (theme::text(), theme::text_soft()),
449 EventLook::Free | EventLook::Tentative => (theme::text_soft(), theme::text_muted()),
450 };
451 // Day-qualified id: overnight / multi-day spans reuse object_id per column.
452 div()
453 .id(SharedString::from(format!(
454 "calendar-event-{}-{}",
455 event.object_id, day
456 )))
457 .absolute()
458 .top(px(top))
459 .h(px(height))
460 .left(relative(width * block.lane as f32))
461 .w(relative(width))
462 .px(px(BLOCK_GAP))
463 .child(
464 h_flex()
465 .size_full()
466 .items_start()
467 .overflow_hidden()
468 .rounded(px(4.))
469 .bg(event_fill(look))
470 .when(event.cancelled, |block| block.opacity(0.6))
471 .cursor_pointer()
472 .children(status_bar(look))
473 .child(
474 v_flex()
475 .flex_1()
476 .min_w_0()
477 .pl(px(5.))
478 .pr(px(4.))
479 .h_full()
480 .py(px(pad_y))
481 .overflow_hidden()
482 .when(compact, |body| body.justify_center())
483 .child(
484 div()
485 .text_size(px(title_size))
486 .line_height(px(title_line))
487 .font_weight(FontWeight::SEMIBOLD)
488 .text_color(title_color)
489 .when(compact, |title| title.truncate())
490 .when(!compact, |title| title.line_clamp(title_lines))
491 .child(event_title(event)),
492 )
493 .when(!compact && title_lines > 2, |body| {
494 body.children(event.organizer_name.clone().map(|organizer| {
495 div()
496 .text_size(px(12.))
497 .line_height(px(16.))
498 .text_color(detail_color)
499 .truncate()
500 .child(organizer)
501 }))
502 }),
503 )
504 .when(can_join, |block| {
505 block.child(
506 div().flex_none().pr(px(4.)).pt(px(3.)).child(
507 Button::new(SharedString::from(format!(
508 "calendar-join-{}-{}",
509 event.object_id, day
510 )))
511 .xsmall()
512 .primary()
513 .label(tr("common.join"))
514 .on_click(move |_, _, cx| {
515 cx.stop_propagation();
516 join_state.update(cx, |state, cx| {
517 state.join_calendar_meeting(
518 join_url.as_deref(),
519 &subject,
520 cx,
521 )
522 });
523 }),
524 ),
525 )
526 }),
527 )
528 .on_click(move |_, window, cx| {
529 open_calendar_event(open_state.clone(), open_event.clone(), window, cx);
530 })
531 .context_menu(move |menu, _, _| {
532 event_menu(menu, &menu_state, &menu_event, send_response)
533 })
534 }
535
536 fn grid(
537 &self,
538 days: &[WeekDay],
539 events: &[CalendarEvent],
540 today: NaiveDate,
541 now: DateTime<Utc>,
542 send_response: bool,
543 cx: &mut Context<Self>,
544 ) -> impl IntoElement {
545 let total_height = 24. * HOUR_HEIGHT;
546 let twelve_hour = clock_format().contains("%p") || clock_format().contains("%P");
547 let now_minute = {
548 let local = now.with_timezone(&Local);
549 local.hour() * 60 + local.minute()
550 };
551 div()
552 .id("calendar-grid")
553 .flex_1()
554 .min_h_0()
555 .overflow_y_scroll()
556 .track_scroll(&self.scroll)
557 .on_scroll_wheel(cx.listener(Self::on_grid_scroll_wheel))
558 .child(
559 h_flex()
560 .h(px(total_height))
561 .w_full()
562 .child(
563 v_flex()
564 .w(px(GUTTER_WIDTH))
565 .flex_none()
566 .children((0..24).map(|hour| {
567 div()
568 .h(px(HOUR_HEIGHT))
569 .pt(px(4.))
570 .flex()
571 .justify_center()
572 .text_size(px(12.))
573 .text_color(theme::text_soft())
574 .when(hour > 0, |label| {
575 label.child(hour_label(hour, twelve_hour))
576 })
577 })),
578 )
579 .children(days.iter().map(|day| {
580 div()
581 .relative()
582 .flex_1()
583 .min_w_0()
584 .h_full()
585 .border_l_1()
586 .border_color(theme::border())
587 .children((1..24 * QUARTERS_PER_HOUR).map(|quarter| {
588 let line = div()
589 .absolute()
590 .top(
591 px(quarter as f32 * HOUR_HEIGHT / QUARTERS_PER_HOUR as f32),
592 )
593 .left_0()
594 .right_0();
595 if quarter % QUARTERS_PER_HOUR == 0 {
596 line.h(px(1.)).bg(theme::border())
597 } else {
598 line.h(px(1.))
599 .bg(theme::border().opacity(QUARTER_LINE_OPACITY))
600 }
601 }))
602 .children(day.blocks.iter().map(|block| {
603 self.event_block(
604 block,
605 &events[block.event_index],
606 day.date,
607 send_response,
608 )
609 }))
610 .when(day.date == today, |column| {
611 let now_top = now_minute as f32 / 60. * HOUR_HEIGHT;
612 column
613 .child(
614 div()
615 .absolute()
616 .top(px(now_top - 1.))
617 .left_0()
618 .right_0()
619 .h(px(2.))
620 .bg(theme::accent()),
621 )
622 .child(
623 div()
624 .absolute()
625 .top(px(now_top - NOW_DOT_SIZE / 2.))
626 .left_0()
627 .size(px(NOW_DOT_SIZE))
628 .rounded_full()
629 .bg(theme::accent()),
630 )
631 })
632 })),
633 )
634 }
635}
636
637fn event_menu(
638 menu: PopupMenu,
639 state: &Entity<AppState>,
640 event: &CalendarEvent,
641 send_response: bool,
642) -> PopupMenu {
643 let mut menu = menu;
644 if let Some(join_url) = event
645 .join_url
646 .clone()
647 .filter(|_| event.online && !event.cancelled)
648 {
649 let (join_state, subject) = (state.clone(), event.subject.clone());
650 menu = menu.item(PopupMenuItem::new("Join").icon(IconName::Video).on_click(
651 move |_, _, cx| {
652 join_state.update(cx, |state, cx| {
653 state.join_calendar_meeting(Some(&join_url), &subject, cx)
654 })
655 },
656 ));
657 }
658 if let Some(join_url) = event.join_url.as_deref().filter(|_| event.online) {
659 let info = join_info_text(join_url, event.dial_in.as_ref());
660 menu = menu.item(
661 PopupMenuItem::new(COPY_JOIN_INFO)
662 .icon(IconName::Copy)
663 .on_click(move |_, _, cx| {
664 cx.write_to_clipboard(ClipboardItem::new_string(info.clone()))
665 }),
666 );
667 }
668 if let Some(thread_id) = event.thread_id.clone() {
669 let chat_state = state.clone();
670 menu = menu.item(
671 PopupMenuItem::new("Chat with participants")
672 .icon(IconName::MessageSquare)
673 .on_click(move |_, _, cx| {
674 chat_state.update(cx, |state, cx| {
675 state.open_meeting_chat(Some(&thread_id), cx)
676 })
677 }),
678 );
679 }
680 if event.response == ResponseType::Organizer || event.organizer_name.is_none() {
681 return menu;
682 }
683 rsvp_menu(
684 menu.separator(),
685 state,
686 &event.object_id,
687 event.response,
688 send_response,
689 )
690}
691
692fn event_fill(look: EventLook) -> Hsla {
693 match look {
694 EventLook::Busy => theme::accent().opacity(BUSY_FILL_OPACITY),
695 EventLook::Free | EventLook::Tentative => theme::accent().opacity(FREE_FILL_OPACITY),
696 }
697}
698
699fn status_bar(look: EventLook) -> Option<Div> {
700 let bar = div().flex_none().w(px(STATUS_BAR_WIDTH)).h_full();
701 match look {
702 EventLook::Busy => Some(bar.bg(theme::accent())),
703 EventLook::Tentative => Some(
704 bar.bg(theme::accent().opacity(BUSY_FILL_OPACITY)).child(
705 div()
706 .size_full()
707 .bg(pattern_slash(theme::accent(), HATCH_STRIPE, HATCH_GAP)),
708 ),
709 ),
710 EventLook::Free => None,
711 }
712}
713
714fn event_title(event: &CalendarEvent) -> String {
715 let subject = if event.cancelled {
716 format!("{CANCELED_PREFIX}{}", event.subject)
717 } else {
718 event.subject.clone()
719 };
720 let label = source_label(event);
721 if label.is_empty() {
722 subject
723 } else {
724 format!("{subject} · {label}")
725 }
726}
727
728fn source_label(event: &CalendarEvent) -> String {
729 let mut sources = event.sources.clone();
730 if sources.is_empty() {
731 sources.push(event.source);
732 }
733 sources.sort_by_key(|source| source.label());
734 sources.dedup();
735 if sources.len() == 1 && sources[0] == chatsvc::CalendarSource::Outlook {
736 return String::new();
737 }
738 sources
739 .iter()
740 .map(|source| source.label())
741 .collect::<Vec<_>>()
742 .join("+")
743}
744
745impl Render for CalendarView {
746 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
747 let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;
748 self.sync_follow_from_state(window, cx);
749 let state = self.state.read(cx);
750 let start = state.calendar_start();
751 let events = state.calendar_week.events.clone();
752 let send_response = state.rsvp_send_response;
753 let offset = Local::now().offset().fix();
754 let span = state.calendar_week.span;
755 let days = week_days(&events, start, span.days(), offset);
756 let today = Local::now().date_naive();
757 let now = Utc::now();
758 let show_picker = !compact;
759 h_flex()
760 .debug_selector(|| "shell/islands/calendar".into())
761 .flex_1()
762 .w_full()
763 .min_w_0()
764 .h_full()
765 .rounded(px(10.))
766 .bg(theme::surface())
767 .overflow_hidden()
768 .when(show_picker, |row| {
769 row.child(calendar_picker::render(&self.state, cx))
770 })
771 .child(
772 v_flex()
773 .flex_1()
774 .min_w_0()
775 .h_full()
776 .child(self.header(start, span, compact))
777 .children(meeting_proposal_cards(cx))
778 .map(|calendar| {
779 if span == CalendarSpan::Month {
780 calendar.child(month_grid(
781 &self.state,
782 start,
783 &days,
784 &events,
785 today,
786 offset,
787 ))
788 } else {
789 calendar
790 .child(self.day_headers(&days, today))
791 .children(self.all_day_row(&days, &events, send_response))
792 .child(self.grid(&days, &events, today, now, send_response, cx))
793 }
794 }),
795 )
796 }
797}