| 1 | use std::collections::HashMap; |
| 2 | |
| 3 | use app_base::format::{WeekdayWidth, Zone, weekday_name}; |
| 4 | use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, SIDEBAR_WIDTH}; |
| 5 | use app_ui_kit::render::hooks::open_link; |
| 6 | use app_ui_kit::render::{Block, layout_blocks, render_blocks, strip_image_placeholders}; |
| 7 | use chatsvc::{ |
| 8 | CalendarEvent, CalendarSource, DialIn, EventAttendee, Reply, ResponseType, join_info_text, |
| 9 | }; |
| 10 | use chrono::Datelike; |
| 11 | use gpui_kit::assets::IconName; |
| 12 | use gpui_kit::component::Sizable as _; |
| 13 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 14 | use gpui_kit::component::checkbox::Checkbox; |
| 15 | use gpui_kit::component::input::{Input, InputState}; |
| 16 | use gpui_kit::component::menu::{DropdownMenu as _, PopupMenuItem}; |
| 17 | use gpui_kit::component::scroll::ScrollableElement as _; |
| 18 | use gpui_kit::component::{Icon, h_flex, v_flex}; |
| 19 | use gpui_kit::prelude::FluentBuilder as _; |
| 20 | use gpui_kit::*; |
| 21 | |
| 22 | use crate::app_state::AppState; |
| 23 | use crate::call::week_grid::is_effective_all_day; |
| 24 | use crate::i18n::{tr, tr_args}; |
| 25 | use crate::theme::{self, ElevatedSurface as _}; |
| 26 | |
| 27 | const CARD_WIDTH: f32 = 440.; |
| 28 | const CARD_RADIUS: f32 = 10.; |
| 29 | const CARD_PADDING: f32 = 16.; |
| 30 | const CARD_MARGIN: f32 = 32.; |
| 31 | const SECTION_GAP: f32 = 12.; |
| 32 | const ROW_GAP: f32 = 8.; |
| 33 | const ICON_SIZE: f32 = 16.; |
| 34 | const AVATAR_SIZE: f32 = 28.; |
| 35 | const BACKDROP_OPACITY: f32 = 0.55; |
| 36 | /// Shrink-only agenda cap (Forward-dialog preview pattern — no flex_1). |
| 37 | const AGENDA_MAX_HEIGHT: f32 = 280.; |
| 38 | const EXPANDED_WIDTH: f32 = 0.92; |
| 39 | const EXPANDED_HEIGHT: f32 = 0.88; |
| 40 | const TRACKING_GROUPS: [ResponseType; 4] = [ |
| 41 | ResponseType::Accepted, |
| 42 | ResponseType::Tentative, |
| 43 | ResponseType::Declined, |
| 44 | ResponseType::NotResponded, |
| 45 | ]; |
| 46 | const COPY_JOIN_INFO: &str = "Copy join info"; |
| 47 | |
| 48 | pub enum EventPeekEvent { |
| 49 | Close, |
| 50 | } |
| 51 | |
| 52 | pub struct EventPeek { |
| 53 | state: Entity<AppState>, |
| 54 | event: CalendarEvent, |
| 55 | expanded: bool, |
| 56 | /// Parsed `body_html`, keyed by the HTML it came from. |
| 57 | agenda: Option<(String, Vec<Block>)>, |
| 58 | collapsed: Vec<ResponseType>, |
| 59 | message: Entity<InputState>, |
| 60 | _observation: Subscription, |
| 61 | } |
| 62 | |
| 63 | impl EventEmitter<EventPeekEvent> for EventPeek {} |
| 64 | |
| 65 | impl EventPeek { |
| 66 | pub fn new( |
| 67 | state: Entity<AppState>, |
| 68 | event: CalendarEvent, |
| 69 | window: &mut Window, |
| 70 | cx: &mut Context<Self>, |
| 71 | ) -> Self { |
| 72 | let event_key = event.object_id.clone(); |
| 73 | let opening_preview = event |
| 74 | .body_preview |
| 75 | .as_ref() |
| 76 | .map(|value| value.chars().count()) |
| 77 | .unwrap_or(0); |
| 78 | app_base::diagnostics::record(format!( |
| 79 | "calendar peek: open {event_key} preview_chars={opening_preview}" |
| 80 | )); |
| 81 | state.update(cx, |app, cx| app.enrich_calendar_event(&event_key, cx)); |
| 82 | let message = cx.new(|cx| { |
| 83 | InputState::new(window, cx).placeholder(tr("calendar.peek.message_placeholder")) |
| 84 | }); |
| 85 | let watched = state.clone(); |
| 86 | // observe (not subscribe): detail enrichment only notifies AppState, it does not emit. |
| 87 | let observation = cx.observe(&watched, |this, _, cx| { |
| 88 | this.pull_event(cx); |
| 89 | cx.notify(); |
| 90 | }); |
| 91 | let mut peek = EventPeek { |
| 92 | state, |
| 93 | event, |
| 94 | expanded: false, |
| 95 | agenda: None, |
| 96 | collapsed: Vec::new(), |
| 97 | message, |
| 98 | _observation: observation, |
| 99 | }; |
| 100 | // The clicked calendar block can be a stale clone. If details are already |
| 101 | // cached, enrich_calendar_event() emits no notify, so pull once now. |
| 102 | peek.pull_event(cx); |
| 103 | let pulled = peek |
| 104 | .event |
| 105 | .body_preview |
| 106 | .as_ref() |
| 107 | .map(|value| value.chars().count()) |
| 108 | .unwrap_or(0); |
| 109 | if pulled != opening_preview { |
| 110 | app_base::diagnostics::record(format!( |
| 111 | "calendar peek: pulled preview_chars={pulled} for {event_key}" |
| 112 | )); |
| 113 | } |
| 114 | peek |
| 115 | } |
| 116 | |
| 117 | fn pull_event(&mut self, cx: &mut Context<Self>) { |
| 118 | let key = self.event.object_id.clone(); |
| 119 | let app = self.state.read(cx); |
| 120 | let best = app |
| 121 | .calendar_week |
| 122 | .events |
| 123 | .iter() |
| 124 | .chain(app.calendar_events.iter()) |
| 125 | .filter(|event| event.object_id == key) |
| 126 | .cloned() |
| 127 | .reduce(|best, candidate| { |
| 128 | if event_detail_score(&candidate) > event_detail_score(&best) { |
| 129 | candidate |
| 130 | } else { |
| 131 | best |
| 132 | } |
| 133 | }); |
| 134 | if let Some(event) = best { |
| 135 | self.event = event; |
| 136 | } |
| 137 | self.refresh_agenda(); |
| 138 | } |
| 139 | |
| 140 | fn refresh_agenda(&mut self) { |
| 141 | let Some(html) = self.event.body_html.as_ref() else { |
| 142 | self.agenda = None; |
| 143 | return; |
| 144 | }; |
| 145 | if self |
| 146 | .agenda |
| 147 | .as_ref() |
| 148 | .is_some_and(|(source, _)| source == html) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | let blocks = strip_image_placeholders(layout_blocks(&teams_core::html_to_spans(html))); |
| 153 | self.agenda = Some((html.clone(), blocks)); |
| 154 | } |
| 155 | |
| 156 | fn agenda_element(&self, cx: &App) -> Option<AnyElement> { |
| 157 | if let Some((_, blocks)) = self |
| 158 | .agenda |
| 159 | .as_ref() |
| 160 | .filter(|(_, blocks)| !blocks.is_empty()) |
| 161 | { |
| 162 | return Some( |
| 163 | div() |
| 164 | .w_full() |
| 165 | .min_w(px(0.)) |
| 166 | .text_size(px(14.)) |
| 167 | .text_color(theme::text()) |
| 168 | .child(render_blocks(blocks, "calendar-peek-agenda", false, cx)) |
| 169 | .into_any_element(), |
| 170 | ); |
| 171 | } |
| 172 | let preview = self |
| 173 | .event |
| 174 | .body_preview |
| 175 | .clone() |
| 176 | .filter(|value| !value.is_empty())?; |
| 177 | Some( |
| 178 | div() |
| 179 | .w_full() |
| 180 | .min_w(px(0.)) |
| 181 | .whitespace_normal() |
| 182 | .text_size(px(13.)) |
| 183 | .text_color(theme::text_soft()) |
| 184 | .child(preview) |
| 185 | .into_any_element(), |
| 186 | ) |
| 187 | } |
| 188 | |
| 189 | fn toggle_expand(&mut self, cx: &mut Context<Self>) { |
| 190 | self.expanded = !self.expanded; |
| 191 | cx.notify(); |
| 192 | } |
| 193 | |
| 194 | fn toggle_group(&mut self, group: ResponseType, cx: &mut Context<Self>) { |
| 195 | if let Some(index) = self.collapsed.iter().position(|kind| *kind == group) { |
| 196 | self.collapsed.remove(index); |
| 197 | } else { |
| 198 | self.collapsed.push(group); |
| 199 | } |
| 200 | cx.notify(); |
| 201 | } |
| 202 | |
| 203 | fn toggle_email_organizer(&mut self, cx: &mut Context<Self>) { |
| 204 | self.state |
| 205 | .update(cx, |state, cx| state.toggle_rsvp_send_response(cx)); |
| 206 | cx.notify(); |
| 207 | } |
| 208 | |
| 209 | fn close(&mut self, cx: &mut Context<Self>) { |
| 210 | cx.emit(EventPeekEvent::Close); |
| 211 | } |
| 212 | |
| 213 | fn respond(&mut self, reply: Reply, cx: &mut Context<Self>) { |
| 214 | let key = self.event.object_id.clone(); |
| 215 | let send = self.state.read(cx).rsvp_send_response; |
| 216 | let comment = if send && self.event.source == CalendarSource::Outlook { |
| 217 | self.message.read(cx).value().to_string() |
| 218 | } else { |
| 219 | String::new() |
| 220 | }; |
| 221 | self.state.update(cx, |state, cx| { |
| 222 | state.respond_to_event(&key, reply, &comment, cx) |
| 223 | }); |
| 224 | self.close(cx); |
| 225 | } |
| 226 | |
| 227 | fn respond_series_master(&mut self, reply: Reply, cx: &mut Context<Self>) { |
| 228 | let Some(master) = self.event.series_master_id.clone() else { |
| 229 | self.respond(reply, cx); |
| 230 | return; |
| 231 | }; |
| 232 | let send = self.state.read(cx).rsvp_send_response; |
| 233 | let comment = if send && self.event.source == CalendarSource::Outlook { |
| 234 | self.message.read(cx).value().to_string() |
| 235 | } else { |
| 236 | String::new() |
| 237 | }; |
| 238 | self.state.update(cx, |state, cx| { |
| 239 | state.respond_to_event(&master, reply, &comment, cx) |
| 240 | }); |
| 241 | self.close(cx); |
| 242 | } |
| 243 | |
| 244 | fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) { |
| 245 | if event.keystroke.key.as_str() == "escape" { |
| 246 | self.close(cx); |
| 247 | cx.stop_propagation(); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | fn has_scroll_content(&self) -> bool { |
| 252 | self.agenda |
| 253 | .as_ref() |
| 254 | .is_some_and(|(_, blocks)| !blocks.is_empty()) |
| 255 | || self |
| 256 | .event |
| 257 | .body_preview |
| 258 | .as_ref() |
| 259 | .is_some_and(|value| !value.is_empty()) |
| 260 | } |
| 261 | |
| 262 | fn subject_label(&self) -> String { |
| 263 | let event = &self.event; |
| 264 | if event.cancelled { |
| 265 | format!("{}{}", tr("calendar.peek.canceled_prefix"), event.subject) |
| 266 | } else if event.subject.is_empty() { |
| 267 | tr("calendar.peek.no_title") |
| 268 | } else { |
| 269 | event.subject.clone() |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | fn organizer_label(&self) -> String { |
| 274 | self.event |
| 275 | .organizer_name |
| 276 | .clone() |
| 277 | .or_else(|| self.event.organizer_address.clone()) |
| 278 | .unwrap_or_default() |
| 279 | } |
| 280 | |
| 281 | fn expand_button(&self, cx: &mut Context<Self>) -> Button { |
| 282 | Button::new("calendar-peek-expand") |
| 283 | .ghost() |
| 284 | .small() |
| 285 | .icon(if self.expanded { |
| 286 | IconName::Minimize2 |
| 287 | } else { |
| 288 | IconName::Expand |
| 289 | }) |
| 290 | .on_click(cx.listener(|this, _, _, cx| this.toggle_expand(cx))) |
| 291 | } |
| 292 | |
| 293 | fn when_row(&self) -> Div { |
| 294 | h_flex() |
| 295 | .gap(px(ROW_GAP)) |
| 296 | .items_start() |
| 297 | .child(icon(IconName::Clock, theme::text_muted())) |
| 298 | .child( |
| 299 | h_flex() |
| 300 | .flex_1() |
| 301 | .min_w_0() |
| 302 | .gap(px(8.)) |
| 303 | .items_center() |
| 304 | .child( |
| 305 | div() |
| 306 | .text_size(px(14.)) |
| 307 | .text_color(theme::text()) |
| 308 | .child(peek_when_label(&self.event)), |
| 309 | ) |
| 310 | .when(self.event.series, |row| { |
| 311 | row.child( |
| 312 | h_flex() |
| 313 | .gap(px(4.)) |
| 314 | .items_center() |
| 315 | .child(icon(IconName::Repeat, theme::text_muted())) |
| 316 | .child( |
| 317 | div() |
| 318 | .text_size(px(13.)) |
| 319 | .text_color(theme::text_soft()) |
| 320 | .child(tr("calendar.peek.series")), |
| 321 | ), |
| 322 | ) |
| 323 | }), |
| 324 | ) |
| 325 | } |
| 326 | |
| 327 | fn location_row(&self) -> Option<Div> { |
| 328 | let location = location_label(&self.event); |
| 329 | (!location.is_empty()).then(|| { |
| 330 | h_flex() |
| 331 | .gap(px(ROW_GAP)) |
| 332 | .items_start() |
| 333 | .child(icon(IconName::MapPin, theme::text_muted())) |
| 334 | .child( |
| 335 | div() |
| 336 | .text_size(px(14.)) |
| 337 | .text_color(theme::text()) |
| 338 | .child(location), |
| 339 | ) |
| 340 | }) |
| 341 | } |
| 342 | |
| 343 | /// Google-only: which calendar owns the event. |
| 344 | fn calendar_row(&self) -> Option<Div> { |
| 345 | if self.event.source != CalendarSource::Google { |
| 346 | return None; |
| 347 | } |
| 348 | let name = self |
| 349 | .event |
| 350 | .calendar_name |
| 351 | .clone() |
| 352 | .filter(|value| !value.is_empty())?; |
| 353 | Some( |
| 354 | h_flex() |
| 355 | .gap(px(ROW_GAP)) |
| 356 | .items_center() |
| 357 | .child(icon(IconName::Calendar, theme::text_muted())) |
| 358 | .child( |
| 359 | div() |
| 360 | .text_size(px(14.)) |
| 361 | .text_color(theme::text()) |
| 362 | .child(name), |
| 363 | ), |
| 364 | ) |
| 365 | } |
| 366 | |
| 367 | fn reminder_row(&self) -> Option<Div> { |
| 368 | if self.event.reminders.is_empty() { |
| 369 | return None; |
| 370 | } |
| 371 | Some( |
| 372 | h_flex() |
| 373 | .gap(px(ROW_GAP)) |
| 374 | .items_start() |
| 375 | .child(icon(IconName::Bell, theme::text_muted())) |
| 376 | .child( |
| 377 | v_flex() |
| 378 | .gap(px(2.)) |
| 379 | .children(self.event.reminders.iter().map(|minutes| { |
| 380 | div() |
| 381 | .text_size(px(14.)) |
| 382 | .text_color(theme::text()) |
| 383 | .child(reminder_label(*minutes)) |
| 384 | })), |
| 385 | ), |
| 386 | ) |
| 387 | } |
| 388 | |
| 389 | fn source_row(&self, _cx: &mut Context<Self>) -> Option<AnyElement> { |
| 390 | let (title, url) = self.event.source_link.clone()?; |
| 391 | let open = url.clone(); |
| 392 | Some( |
| 393 | h_flex() |
| 394 | .gap(px(ROW_GAP)) |
| 395 | .items_start() |
| 396 | .child(icon(IconName::Link, theme::text_muted())) |
| 397 | .child( |
| 398 | v_flex() |
| 399 | .gap(px(2.)) |
| 400 | .min_w(px(0.)) |
| 401 | .child( |
| 402 | div() |
| 403 | .text_size(px(14.)) |
| 404 | .text_color(theme::text()) |
| 405 | .whitespace_normal() |
| 406 | .child(title), |
| 407 | ) |
| 408 | .child( |
| 409 | div() |
| 410 | .id("calendar-peek-view-source") |
| 411 | .text_size(px(12.)) |
| 412 | .text_color(theme::accent_text()) |
| 413 | .cursor_pointer() |
| 414 | .child(tr("calendar.peek.view_source")) |
| 415 | .on_click(move |_, _, cx| open_link(&open, cx)), |
| 416 | ), |
| 417 | ) |
| 418 | .into_any_element(), |
| 419 | ) |
| 420 | } |
| 421 | |
| 422 | fn google_meta_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> { |
| 423 | let mut rows = Vec::new(); |
| 424 | if let Some(row) = self.calendar_row() { |
| 425 | rows.push(row.into_any_element()); |
| 426 | } |
| 427 | if let Some(row) = self.reminder_row() { |
| 428 | rows.push(row.into_any_element()); |
| 429 | } |
| 430 | if let Some(row) = self.source_row(cx) { |
| 431 | rows.push(row); |
| 432 | } |
| 433 | rows |
| 434 | } |
| 435 | |
| 436 | fn render_header(&self, cx: &mut Context<Self>) -> Stateful<Div> { |
| 437 | let event = &self.event; |
| 438 | let subject = self.subject_label(); |
| 439 | let can_rsvp = event.response != ResponseType::Organizer && event.organizer_name.is_some(); |
| 440 | let organizer = self.organizer_label(); |
| 441 | let initials = app_base::format::initials(&organizer); |
| 442 | let summary = response_summary(event); |
| 443 | |
| 444 | let header_actions = h_flex() |
| 445 | .gap(px(8.)) |
| 446 | .children(self.google_action_buttons()) |
| 447 | .children(self.join_chat_buttons(cx)); |
| 448 | |
| 449 | let title_row = h_flex() |
| 450 | .w_full() |
| 451 | .items_start() |
| 452 | .justify_between() |
| 453 | .gap(px(8.)) |
| 454 | .child( |
| 455 | div() |
| 456 | .flex_1() |
| 457 | .min_w_0() |
| 458 | .text_size(px(18.)) |
| 459 | .font_weight(FontWeight::SEMIBOLD) |
| 460 | .text_color(theme::text()) |
| 461 | .child(subject), |
| 462 | ) |
| 463 | .child(self.expand_button(cx)); |
| 464 | |
| 465 | let mut header = v_flex() |
| 466 | .id("calendar-peek-header") |
| 467 | .w_full() |
| 468 | .flex_none() |
| 469 | .gap(px(SECTION_GAP)) |
| 470 | .child(title_row) |
| 471 | .child(header_actions) |
| 472 | .child(self.when_row()) |
| 473 | .children(self.location_row()) |
| 474 | .children(self.google_meta_rows(cx)); |
| 475 | |
| 476 | if !organizer.is_empty() { |
| 477 | let invite_line = if can_rsvp { |
| 478 | let mut args = HashMap::new(); |
| 479 | args.insert("name".to_owned(), organizer.clone()); |
| 480 | tr_args("calendar.peek.invited_you", &args) |
| 481 | } else { |
| 482 | organizer.clone() |
| 483 | }; |
| 484 | header = header.child( |
| 485 | h_flex() |
| 486 | .gap(px(ROW_GAP)) |
| 487 | .items_start() |
| 488 | .child(avatar(initials)) |
| 489 | .child( |
| 490 | v_flex() |
| 491 | .gap(px(2.)) |
| 492 | .child( |
| 493 | div() |
| 494 | .text_size(px(14.)) |
| 495 | .text_color(theme::text()) |
| 496 | .child(invite_line), |
| 497 | ) |
| 498 | .children(summary.map(|text| { |
| 499 | div() |
| 500 | .text_size(px(12.)) |
| 501 | .text_color(theme::text_muted()) |
| 502 | .child(text) |
| 503 | })), |
| 504 | ), |
| 505 | ); |
| 506 | } |
| 507 | |
| 508 | header |
| 509 | } |
| 510 | |
| 511 | /// Google-only: Open in Google Calendar + Email guests. |
| 512 | fn google_action_buttons(&self) -> Vec<AnyElement> { |
| 513 | if self.event.source != CalendarSource::Google { |
| 514 | return Vec::new(); |
| 515 | } |
| 516 | let mut buttons = Vec::new(); |
| 517 | if let Some(url) = self.event.web_link.clone() { |
| 518 | buttons.push( |
| 519 | Button::new("calendar-peek-open-google") |
| 520 | .outline() |
| 521 | .icon(IconName::ExternalLink) |
| 522 | .label(tr("calendar.peek.open_in_google")) |
| 523 | .on_click(move |_, _, cx| open_link(&url, cx)) |
| 524 | .into_any_element(), |
| 525 | ); |
| 526 | } |
| 527 | let addresses: Vec<String> = self |
| 528 | .event |
| 529 | .attendees |
| 530 | .iter() |
| 531 | .filter_map(|attendee| attendee.address.clone()) |
| 532 | .filter(|address| !address.is_empty()) |
| 533 | .collect(); |
| 534 | if !addresses.is_empty() { |
| 535 | let mut mailto = format!("mailto:{}", addresses.join(",")); |
| 536 | if !self.event.subject.is_empty() { |
| 537 | mailto = format!( |
| 538 | "{mailto}?subject={}", |
| 539 | percent_encode_query(&self.event.subject) |
| 540 | ); |
| 541 | } |
| 542 | buttons.push( |
| 543 | Button::new("calendar-peek-email-guests") |
| 544 | .outline() |
| 545 | .icon(IconName::Mail) |
| 546 | .label(tr("calendar.peek.email_guests")) |
| 547 | .on_click(move |_, _, cx| open_link(&mailto, cx)) |
| 548 | .into_any_element(), |
| 549 | ); |
| 550 | } |
| 551 | buttons |
| 552 | } |
| 553 | |
| 554 | fn join_chat_buttons(&self, cx: &mut Context<Self>) -> Vec<AnyElement> { |
| 555 | let event = &self.event; |
| 556 | let can_join = event.online && !event.cancelled && event.join_url.is_some(); |
| 557 | let join_url = event.join_url.clone(); |
| 558 | let dial_in = event.dial_in.clone(); |
| 559 | let thread_id = event.thread_id.clone(); |
| 560 | let meeting_title = event.subject.clone(); |
| 561 | let mut buttons = Vec::new(); |
| 562 | if can_join { |
| 563 | let join_state = self.state.clone(); |
| 564 | let url = join_url.clone(); |
| 565 | let title = meeting_title.clone(); |
| 566 | let clipboard = join_url |
| 567 | .as_deref() |
| 568 | .map(|url| copy_join_clipboard(url, dial_in.as_ref())); |
| 569 | buttons.push( |
| 570 | Button::new("calendar-peek-join") |
| 571 | .outline() |
| 572 | .label(tr("common.join")) |
| 573 | .icon(IconName::Video) |
| 574 | .on_click(cx.listener(move |this, _, _, cx| { |
| 575 | join_state.update(cx, |state, cx| { |
| 576 | state.join_calendar_meeting(url.as_deref(), &title, cx) |
| 577 | }); |
| 578 | this.close(cx); |
| 579 | })) |
| 580 | .into_any_element(), |
| 581 | ); |
| 582 | if let Some(info) = clipboard { |
| 583 | buttons.push( |
| 584 | Button::new("calendar-peek-join-menu") |
| 585 | .outline() |
| 586 | .icon(IconName::ChevronDown) |
| 587 | .dropdown_menu(move |menu, _, _| { |
| 588 | let info = info.clone(); |
| 589 | menu.item( |
| 590 | PopupMenuItem::new(COPY_JOIN_INFO) |
| 591 | .icon(IconName::Copy) |
| 592 | .on_click(move |_, _, cx| { |
| 593 | cx.write_to_clipboard(ClipboardItem::new_string( |
| 594 | info.clone(), |
| 595 | )) |
| 596 | }), |
| 597 | ) |
| 598 | }) |
| 599 | .into_any_element(), |
| 600 | ); |
| 601 | } |
| 602 | } |
| 603 | if thread_id.is_some() { |
| 604 | let chat_state = self.state.clone(); |
| 605 | let chat_thread = thread_id.clone(); |
| 606 | buttons.push( |
| 607 | Button::new("calendar-peek-chat") |
| 608 | .outline() |
| 609 | .label(tr("common.chat")) |
| 610 | .icon(IconName::MessageSquare) |
| 611 | .on_click(cx.listener(move |this, _, _, cx| { |
| 612 | chat_state.update(cx, |state, cx| { |
| 613 | state.open_meeting_chat(chat_thread.as_deref(), cx) |
| 614 | }); |
| 615 | this.close(cx); |
| 616 | })) |
| 617 | .into_any_element(), |
| 618 | ); |
| 619 | } |
| 620 | buttons |
| 621 | } |
| 622 | |
| 623 | /// Compact agenda: max_h + scrollbar on the content root (Forward-preview pattern). |
| 624 | /// A nested scroll wrapper with min_h(0) collapses to 0 height in GPUI. |
| 625 | fn render_scroll_body(agenda: AnyElement) -> impl IntoElement { |
| 626 | h_flex() |
| 627 | .id("calendar-peek-scroll-content") |
| 628 | .w_full() |
| 629 | .gap(px(ROW_GAP)) |
| 630 | .items_start() |
| 631 | .child(icon(IconName::List, theme::text_muted())) |
| 632 | .child(div().flex_1().min_w(px(0.)).child(agenda)) |
| 633 | .flex_shrink_0() |
| 634 | .max_h(px(AGENDA_MAX_HEIGHT)) |
| 635 | .overflow_y_scrollbar() |
| 636 | } |
| 637 | |
| 638 | fn render_expanded(&self, cx: &mut Context<Self>) -> impl IntoElement + use<> { |
| 639 | let toolbar = h_flex() |
| 640 | .w_full() |
| 641 | .flex_none() |
| 642 | .gap(px(8.)) |
| 643 | .items_center() |
| 644 | .children(self.action_buttons(cx)) |
| 645 | .child(div().flex_1()) |
| 646 | .children(self.google_action_buttons()) |
| 647 | .children(self.join_chat_buttons(cx)) |
| 648 | .child(self.expand_button(cx)) |
| 649 | .child( |
| 650 | Button::new("calendar-peek-close") |
| 651 | .ghost() |
| 652 | .small() |
| 653 | .icon(IconName::X) |
| 654 | .on_click(cx.listener(|this, _, _, cx| this.close(cx))), |
| 655 | ); |
| 656 | |
| 657 | let names = self.attendee_names_line(); |
| 658 | let mut details = v_flex() |
| 659 | .id("calendar-peek-expanded-details") |
| 660 | .flex_1() |
| 661 | .min_w(px(0.)) |
| 662 | .h_full() |
| 663 | .gap(px(SECTION_GAP)) |
| 664 | .pr(px(CARD_PADDING)) |
| 665 | .child( |
| 666 | div() |
| 667 | .text_size(px(20.)) |
| 668 | .font_weight(FontWeight::SEMIBOLD) |
| 669 | .text_color(theme::text()) |
| 670 | .child(self.subject_label()), |
| 671 | ) |
| 672 | .children(names.map(|names| { |
| 673 | h_flex() |
| 674 | .gap(px(ROW_GAP)) |
| 675 | .items_start() |
| 676 | .child(icon(IconName::Users, theme::text_muted())) |
| 677 | .child( |
| 678 | div() |
| 679 | .flex_1() |
| 680 | .min_w(px(0.)) |
| 681 | .whitespace_normal() |
| 682 | .text_size(px(13.)) |
| 683 | .text_color(theme::text_soft()) |
| 684 | .child(names), |
| 685 | ) |
| 686 | })) |
| 687 | .child(self.when_row()) |
| 688 | .children(self.location_row()) |
| 689 | .children(self.google_meta_rows(cx)) |
| 690 | .children(self.rsvp_message_controls(cx)); |
| 691 | if let Some(agenda) = self.agenda_element(cx) { |
| 692 | details = details.child( |
| 693 | div() |
| 694 | .w_full() |
| 695 | .pt(px(SECTION_GAP)) |
| 696 | .border_t_1() |
| 697 | .border_color(theme::border()) |
| 698 | .child(agenda), |
| 699 | ); |
| 700 | } |
| 701 | |
| 702 | let body = h_flex() |
| 703 | .w_full() |
| 704 | .flex_1() |
| 705 | .min_h(px(0.)) |
| 706 | .items_start() |
| 707 | .child(details.overflow_y_scrollbar()) |
| 708 | .child(self.render_tracking(cx)); |
| 709 | |
| 710 | v_flex() |
| 711 | .size_full() |
| 712 | .gap(px(SECTION_GAP)) |
| 713 | .child(toolbar) |
| 714 | .child(body) |
| 715 | } |
| 716 | |
| 717 | fn attendee_names_line(&self) -> Option<String> { |
| 718 | let organizer = self.organizer_label(); |
| 719 | let mut names: Vec<String> = Vec::new(); |
| 720 | if !organizer.is_empty() { |
| 721 | names.push(organizer); |
| 722 | } |
| 723 | for attendee in &self.event.attendees { |
| 724 | if !names.contains(&attendee.name) { |
| 725 | names.push(attendee.name.clone()); |
| 726 | } |
| 727 | } |
| 728 | (names.len() > 1).then(|| names.join(", ")) |
| 729 | } |
| 730 | |
| 731 | fn render_tracking(&self, cx: &mut Context<Self>) -> impl IntoElement + use<> { |
| 732 | let organizer = self.organizer_label(); |
| 733 | let mut panel = v_flex() |
| 734 | .id("calendar-peek-tracking") |
| 735 | .w(px(SIDEBAR_WIDTH)) |
| 736 | .flex_none() |
| 737 | .h_full() |
| 738 | .pl(px(CARD_PADDING)) |
| 739 | .gap(px(SECTION_GAP)) |
| 740 | .border_l_1() |
| 741 | .border_color(theme::border()) |
| 742 | .child( |
| 743 | div() |
| 744 | .text_size(px(16.)) |
| 745 | .font_weight(FontWeight::SEMIBOLD) |
| 746 | .text_color(theme::text()) |
| 747 | .child(tr("calendar.peek.tracking")), |
| 748 | ); |
| 749 | if !organizer.is_empty() { |
| 750 | panel = panel.child(person_row(&organizer, tr("calendar.peek.organizer"))); |
| 751 | } |
| 752 | |
| 753 | let roster: Vec<&EventAttendee> = self |
| 754 | .event |
| 755 | .attendees |
| 756 | .iter() |
| 757 | .filter(|attendee| attendee.response != ResponseType::Organizer) |
| 758 | .collect(); |
| 759 | if roster.is_empty() { |
| 760 | let note = response_summary(&self.event) |
| 761 | .unwrap_or_else(|| tr("calendar.peek.attendees_unknown")); |
| 762 | return panel |
| 763 | .child( |
| 764 | div() |
| 765 | .text_size(px(13.)) |
| 766 | .text_color(theme::text_muted()) |
| 767 | .child(note), |
| 768 | ) |
| 769 | .overflow_y_scrollbar(); |
| 770 | } |
| 771 | |
| 772 | for (index, group) in TRACKING_GROUPS.into_iter().enumerate() { |
| 773 | let members: Vec<&&EventAttendee> = roster |
| 774 | .iter() |
| 775 | .filter(|attendee| attendee.response == group) |
| 776 | .collect(); |
| 777 | if members.is_empty() { |
| 778 | continue; |
| 779 | } |
| 780 | let collapsed = self.collapsed.contains(&group); |
| 781 | let mut section = v_flex().gap(px(ROW_GAP)).child( |
| 782 | h_flex() |
| 783 | .id(SharedString::from(format!("calendar-peek-group-{index}"))) |
| 784 | .gap(px(4.)) |
| 785 | .items_center() |
| 786 | .cursor_pointer() |
| 787 | .on_click(cx.listener(move |this, _, _, cx| this.toggle_group(group, cx))) |
| 788 | .child(icon( |
| 789 | if collapsed { |
| 790 | IconName::ChevronRight |
| 791 | } else { |
| 792 | IconName::ChevronDown |
| 793 | }, |
| 794 | theme::text_muted(), |
| 795 | )) |
| 796 | .child( |
| 797 | div() |
| 798 | .text_size(px(13.)) |
| 799 | .font_weight(FontWeight::SEMIBOLD) |
| 800 | .text_color(theme::text()) |
| 801 | .child(format!("{} {}", group_label(group), members.len())), |
| 802 | ), |
| 803 | ); |
| 804 | if !collapsed { |
| 805 | section = section.children(members.into_iter().map(|attendee| { |
| 806 | let role = if attendee.required { |
| 807 | tr("calendar.peek.required") |
| 808 | } else { |
| 809 | tr("calendar.peek.optional") |
| 810 | }; |
| 811 | person_row(&attendee.name, role) |
| 812 | })); |
| 813 | } |
| 814 | panel = panel.child(section); |
| 815 | } |
| 816 | panel.overflow_y_scrollbar() |
| 817 | } |
| 818 | |
| 819 | fn can_rsvp(&self) -> bool { |
| 820 | self.event.response != ResponseType::Organizer && self.event.organizer_name.is_some() |
| 821 | } |
| 822 | |
| 823 | /// Outlook-only: Graph RSVP supports sendResponse + comment. Google does not. |
| 824 | fn rsvp_message_controls(&self, cx: &mut Context<Self>) -> Vec<AnyElement> { |
| 825 | if !self.can_rsvp() || self.event.source != CalendarSource::Outlook { |
| 826 | return Vec::new(); |
| 827 | } |
| 828 | let send_response = self.state.read(cx).rsvp_send_response; |
| 829 | let mut controls = vec![ |
| 830 | Checkbox::new("calendar-peek-email-organizer") |
| 831 | .label(tr("calendar.peek.email_organizer")) |
| 832 | .checked(send_response) |
| 833 | .on_click(cx.listener(|this, _, _, cx| this.toggle_email_organizer(cx))) |
| 834 | .into_any_element(), |
| 835 | ]; |
| 836 | if send_response { |
| 837 | controls.push(Input::new(&self.message).into_any_element()); |
| 838 | } |
| 839 | controls |
| 840 | } |
| 841 | |
| 842 | /// Accept / Decline / Tentative (when invited) plus the overflow menu with Delete. |
| 843 | fn action_buttons(&self, cx: &mut Context<Self>) -> Vec<AnyElement> { |
| 844 | let response = self.event.response; |
| 845 | let series = self.event.series; |
| 846 | let has_master = self.event.series_master_id.is_some(); |
| 847 | let peek = cx.entity(); |
| 848 | let mut buttons = Vec::new(); |
| 849 | if self.can_rsvp() { |
| 850 | buttons.push(rsvp_button( |
| 851 | "calendar-peek-accept", |
| 852 | tr("calendar.peek.accept"), |
| 853 | Reply::Accept, |
| 854 | response == ResponseType::Accepted, |
| 855 | series, |
| 856 | has_master, |
| 857 | peek.clone(), |
| 858 | )); |
| 859 | buttons.push(rsvp_button( |
| 860 | "calendar-peek-decline", |
| 861 | tr("calendar.peek.decline"), |
| 862 | Reply::Decline, |
| 863 | response == ResponseType::Declined, |
| 864 | series, |
| 865 | has_master, |
| 866 | peek.clone(), |
| 867 | )); |
| 868 | buttons.push(rsvp_button( |
| 869 | "calendar-peek-tentative", |
| 870 | tr("calendar.peek.tentative_action"), |
| 871 | Reply::Tentative, |
| 872 | response == ResponseType::Tentative, |
| 873 | false, |
| 874 | false, |
| 875 | peek.clone(), |
| 876 | )); |
| 877 | } |
| 878 | let delete_state = self.state.clone(); |
| 879 | let delete_key = self.event.object_id.clone(); |
| 880 | buttons.push( |
| 881 | Button::new("calendar-peek-more") |
| 882 | .ghost() |
| 883 | .icon(IconName::Ellipsis) |
| 884 | .dropdown_menu(move |menu, _, _| { |
| 885 | let delete_state = delete_state.clone(); |
| 886 | let delete_key = delete_key.clone(); |
| 887 | let delete_peek = peek.clone(); |
| 888 | menu.item( |
| 889 | PopupMenuItem::new(tr("common.delete")) |
| 890 | .icon(IconName::Trash) |
| 891 | .on_click(move |_, _, cx| { |
| 892 | delete_state.update(cx, |state, cx| { |
| 893 | state.delete_calendar_event(&delete_key, cx) |
| 894 | }); |
| 895 | delete_peek.update(cx, |peek, cx| peek.close(cx)); |
| 896 | }), |
| 897 | ) |
| 898 | }) |
| 899 | .into_any_element(), |
| 900 | ); |
| 901 | buttons |
| 902 | } |
| 903 | |
| 904 | fn render_footer(&self, cx: &mut Context<Self>) -> Stateful<Div> { |
| 905 | let can_rsvp = self.can_rsvp(); |
| 906 | v_flex() |
| 907 | .id("calendar-peek-footer") |
| 908 | .w_full() |
| 909 | .flex_none() |
| 910 | .gap(px(8.)) |
| 911 | .children(self.rsvp_message_controls(cx)) |
| 912 | .child( |
| 913 | h_flex() |
| 914 | .w_full() |
| 915 | .gap(px(8.)) |
| 916 | .items_center() |
| 917 | .when(!can_rsvp, |row| row.justify_end()) |
| 918 | .children(self.action_buttons(cx)), |
| 919 | ) |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | fn avatar(initials: String) -> Div { |
| 924 | div() |
| 925 | .size(px(AVATAR_SIZE)) |
| 926 | .flex_none() |
| 927 | .rounded_full() |
| 928 | .bg(theme::accent_soft()) |
| 929 | .flex() |
| 930 | .items_center() |
| 931 | .justify_center() |
| 932 | .text_size(px(11.)) |
| 933 | .font_weight(FontWeight::SEMIBOLD) |
| 934 | .text_color(theme::accent_text()) |
| 935 | .child(initials) |
| 936 | } |
| 937 | |
| 938 | fn person_row(name: &str, role: String) -> Div { |
| 939 | h_flex() |
| 940 | .gap(px(ROW_GAP)) |
| 941 | .items_center() |
| 942 | .child(avatar(app_base::format::initials(name))) |
| 943 | .child( |
| 944 | v_flex() |
| 945 | .flex_1() |
| 946 | .min_w(px(0.)) |
| 947 | .child( |
| 948 | div() |
| 949 | .text_size(px(14.)) |
| 950 | .text_color(theme::text()) |
| 951 | .truncate() |
| 952 | .child(name.to_owned()), |
| 953 | ) |
| 954 | .child( |
| 955 | div() |
| 956 | .text_size(px(12.)) |
| 957 | .text_color(theme::text_muted()) |
| 958 | .child(role), |
| 959 | ), |
| 960 | ) |
| 961 | } |
| 962 | |
| 963 | fn group_label(group: ResponseType) -> String { |
| 964 | match group { |
| 965 | ResponseType::Accepted | ResponseType::Organizer => tr("calendar.peek.accepted"), |
| 966 | ResponseType::Tentative => tr("calendar.peek.tentative"), |
| 967 | ResponseType::Declined => tr("calendar.peek.declined"), |
| 968 | ResponseType::NotResponded => tr("calendar.peek.no_response"), |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | /// Percent-encode a mailto `subject` query value (UTF-8, RFC 3986). |
| 973 | fn percent_encode_query(value: &str) -> String { |
| 974 | let mut out = String::with_capacity(value.len() * 3); |
| 975 | for byte in value.as_bytes() { |
| 976 | match *byte { |
| 977 | b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => { |
| 978 | out.push(*byte as char); |
| 979 | } |
| 980 | b' ' => out.push_str("%20"), |
| 981 | _ => out.push_str(&format!("%{byte:02X}")), |
| 982 | } |
| 983 | } |
| 984 | out |
| 985 | } |
| 986 | |
| 987 | fn is_teams_url(url: &str) -> bool { |
| 988 | teams_core::parse_meeting_link(url).is_some() |
| 989 | } |
| 990 | |
| 991 | fn is_google_meet_url(url: &str) -> bool { |
| 992 | url.contains("meet.google.com") |
| 993 | } |
| 994 | |
| 995 | fn copy_join_clipboard(url: &str, dial_in: Option<&DialIn>) -> String { |
| 996 | if is_teams_url(url) { |
| 997 | join_info_text(url, dial_in) |
| 998 | } else { |
| 999 | url.to_owned() |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | fn event_detail_score(event: &CalendarEvent) -> u8 { |
| 1004 | u8::from(event.body_html.is_some()) * 32 |
| 1005 | + u8::from(!event.attendees.is_empty()) * 16 |
| 1006 | + u8::from( |
| 1007 | event |
| 1008 | .body_preview |
| 1009 | .as_ref() |
| 1010 | .is_some_and(|value| !value.is_empty()), |
| 1011 | ) * 8 |
| 1012 | + u8::from( |
| 1013 | event |
| 1014 | .location |
| 1015 | .as_ref() |
| 1016 | .is_some_and(|value| !value.is_empty()), |
| 1017 | ) * 4 |
| 1018 | + u8::from(event.response_counts.is_some()) * 2 |
| 1019 | + u8::from(event.series_master_id.is_some()) |
| 1020 | } |
| 1021 | |
| 1022 | fn peek_when_label(event: &CalendarEvent) -> String { |
| 1023 | let start = Zone::Local.at(event.start); |
| 1024 | let end = Zone::Local.at(event.end); |
| 1025 | if is_effective_all_day(event, *start.offset()) { |
| 1026 | let day_label = |date: chrono::NaiveDate| { |
| 1027 | format!( |
| 1028 | "{} {}", |
| 1029 | weekday_name(date.weekday(), WeekdayWidth::Short), |
| 1030 | app_base::format::date_label(date) |
| 1031 | ) |
| 1032 | }; |
| 1033 | let (start, end) = (start.date_naive(), end.date_naive()); |
| 1034 | if end > start + chrono::Duration::days(1) { |
| 1035 | return format!( |
| 1036 | "{} · {} - {}", |
| 1037 | tr("calendar.peek.all_day"), |
| 1038 | day_label(start), |
| 1039 | day_label(end - chrono::Duration::days(1)) |
| 1040 | ); |
| 1041 | } |
| 1042 | return format!("{} · {}", tr("calendar.peek.all_day"), day_label(start)); |
| 1043 | } |
| 1044 | let weekday = weekday_name(start.weekday(), WeekdayWidth::Short); |
| 1045 | let date = app_base::format::date_label(start.date_naive()); |
| 1046 | let clock = app_base::format::clock_format(); |
| 1047 | if start.date_naive() == end.date_naive() { |
| 1048 | format!( |
| 1049 | "{weekday} {date} {} - {}", |
| 1050 | start.format(clock), |
| 1051 | end.format(clock) |
| 1052 | ) |
| 1053 | } else { |
| 1054 | // Multi-day timed (Google-style): date + time on both sides. |
| 1055 | format!( |
| 1056 | "{weekday} {date}, {} – {}, {}", |
| 1057 | start.format(clock), |
| 1058 | app_base::format::date_label(end.date_naive()), |
| 1059 | end.format(clock) |
| 1060 | ) |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | fn reminder_label(minutes: u32) -> String { |
| 1065 | if minutes == 0 { |
| 1066 | return tr("calendar.peek.when_starts"); |
| 1067 | } |
| 1068 | let mut args = HashMap::new(); |
| 1069 | if minutes % 1440 == 0 { |
| 1070 | let days = minutes / 1440; |
| 1071 | args.insert("count".to_owned(), days.to_string()); |
| 1072 | return tr_args( |
| 1073 | if days == 1 { |
| 1074 | "calendar.peek.day_before" |
| 1075 | } else { |
| 1076 | "calendar.peek.days_before" |
| 1077 | }, |
| 1078 | &args, |
| 1079 | ); |
| 1080 | } |
| 1081 | if minutes % 60 == 0 { |
| 1082 | let hours = minutes / 60; |
| 1083 | args.insert("count".to_owned(), hours.to_string()); |
| 1084 | return tr_args( |
| 1085 | if hours == 1 { |
| 1086 | "calendar.peek.hour_before" |
| 1087 | } else { |
| 1088 | "calendar.peek.hours_before" |
| 1089 | }, |
| 1090 | &args, |
| 1091 | ); |
| 1092 | } |
| 1093 | args.insert("count".to_owned(), minutes.to_string()); |
| 1094 | tr_args( |
| 1095 | if minutes == 1 { |
| 1096 | "calendar.peek.minute_before" |
| 1097 | } else { |
| 1098 | "calendar.peek.minutes_before" |
| 1099 | }, |
| 1100 | &args, |
| 1101 | ) |
| 1102 | } |
| 1103 | |
| 1104 | fn location_label(event: &CalendarEvent) -> String { |
| 1105 | if let Some(location) = event.location.clone().filter(|value| !value.is_empty()) { |
| 1106 | return location; |
| 1107 | } |
| 1108 | if !event.online { |
| 1109 | return String::new(); |
| 1110 | } |
| 1111 | match event.join_url.as_deref() { |
| 1112 | Some(url) if is_google_meet_url(url) => tr("calendar.peek.google_meet"), |
| 1113 | Some(url) if is_teams_url(url) => tr("calendar.peek.teams_meeting"), |
| 1114 | _ if event.source == CalendarSource::Google => tr("calendar.peek.google_meet"), |
| 1115 | _ => tr("calendar.peek.teams_meeting"), |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | fn response_summary(event: &CalendarEvent) -> Option<String> { |
| 1120 | let counts = event.response_counts?; |
| 1121 | if counts.is_empty() { |
| 1122 | return None; |
| 1123 | } |
| 1124 | let mut parts = vec![ |
| 1125 | format!("{} {}", tr("calendar.peek.accepted"), counts.accepted), |
| 1126 | format!("{} {}", tr("calendar.peek.declined"), counts.declined), |
| 1127 | ]; |
| 1128 | if counts.tentative > 0 { |
| 1129 | parts.insert( |
| 1130 | 1, |
| 1131 | format!("{} {}", tr("calendar.peek.tentative"), counts.tentative), |
| 1132 | ); |
| 1133 | } |
| 1134 | parts.push(format!( |
| 1135 | "{} {}", |
| 1136 | tr("calendar.peek.no_response"), |
| 1137 | counts.not_responded |
| 1138 | )); |
| 1139 | Some(parts.join(", ")) |
| 1140 | } |
| 1141 | |
| 1142 | fn icon(name: IconName, color: Hsla) -> Icon { |
| 1143 | Icon::new(name).size(px(ICON_SIZE)).text_color(color) |
| 1144 | } |
| 1145 | |
| 1146 | fn rsvp_button( |
| 1147 | id: &'static str, |
| 1148 | label: String, |
| 1149 | reply: Reply, |
| 1150 | chosen: bool, |
| 1151 | series: bool, |
| 1152 | has_master: bool, |
| 1153 | peek: Entity<EventPeek>, |
| 1154 | ) -> AnyElement { |
| 1155 | let button = Button::new(id) |
| 1156 | .label(label) |
| 1157 | .when(chosen, |button| button.primary()); |
| 1158 | let button = match reply { |
| 1159 | Reply::Accept => button.icon(IconName::Check), |
| 1160 | Reply::Decline => button.icon(IconName::X), |
| 1161 | Reply::Tentative => button.icon(IconName::CalendarClock), |
| 1162 | }; |
| 1163 | if series { |
| 1164 | let occurrence = peek.clone(); |
| 1165 | let master = peek; |
| 1166 | button |
| 1167 | .dropdown_menu(move |menu, _, _| { |
| 1168 | let occurrence = occurrence.clone(); |
| 1169 | let master = master.clone(); |
| 1170 | let mut menu = menu.item( |
| 1171 | PopupMenuItem::new(tr("calendar.peek.this_occurrence")).on_click( |
| 1172 | move |_, _, cx| { |
| 1173 | occurrence.update(cx, |peek, cx| peek.respond(reply, cx)); |
| 1174 | }, |
| 1175 | ), |
| 1176 | ); |
| 1177 | if has_master { |
| 1178 | menu = menu.item( |
| 1179 | PopupMenuItem::new(tr("calendar.peek.entire_series")).on_click( |
| 1180 | move |_, _, cx| { |
| 1181 | master.update(cx, |peek, cx| peek.respond_series_master(reply, cx)); |
| 1182 | }, |
| 1183 | ), |
| 1184 | ); |
| 1185 | } |
| 1186 | menu |
| 1187 | }) |
| 1188 | .into_any_element() |
| 1189 | } else { |
| 1190 | button |
| 1191 | .on_click(move |_, _, cx| { |
| 1192 | peek.update(cx, |peek, cx| peek.respond(reply, cx)); |
| 1193 | }) |
| 1194 | .into_any_element() |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | impl Render for EventPeek { |
| 1199 | fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 1200 | let card = if self.expanded { |
| 1201 | v_flex() |
| 1202 | .id("calendar-peek-card") |
| 1203 | .w(relative(EXPANDED_WIDTH)) |
| 1204 | .max_w(px(COMFY_RUNWAY_WIDTH)) |
| 1205 | .h(relative(EXPANDED_HEIGHT)) |
| 1206 | .child(self.render_expanded(cx)) |
| 1207 | } else { |
| 1208 | let header = self.render_header(cx); |
| 1209 | let body = self |
| 1210 | .has_scroll_content() |
| 1211 | .then(|| self.agenda_element(cx)) |
| 1212 | .flatten() |
| 1213 | .map(Self::render_scroll_body); |
| 1214 | let footer = self.render_footer(cx); |
| 1215 | // Shrink-only agenda (Forward preview pattern): max_h + scrollbar, no flex_1. |
| 1216 | v_flex() |
| 1217 | .id("calendar-peek-card") |
| 1218 | .w(px(CARD_WIDTH)) |
| 1219 | .max_w(relative(1.)) |
| 1220 | .max_h(relative(1.)) |
| 1221 | .child(header) |
| 1222 | .children(body) |
| 1223 | .child(footer) |
| 1224 | }; |
| 1225 | |
| 1226 | div() |
| 1227 | .id("calendar-peek-layer") |
| 1228 | .absolute() |
| 1229 | .top_0() |
| 1230 | .left_0() |
| 1231 | .size_full() |
| 1232 | .flex() |
| 1233 | .items_center() |
| 1234 | .justify_center() |
| 1235 | .child( |
| 1236 | div() |
| 1237 | .id("calendar-peek-backdrop") |
| 1238 | .absolute() |
| 1239 | .top_0() |
| 1240 | .left_0() |
| 1241 | .size_full() |
| 1242 | .bg(black().opacity(BACKDROP_OPACITY)) |
| 1243 | .occlude() |
| 1244 | .on_click(cx.listener(|this, _, _, cx| this.close(cx))), |
| 1245 | ) |
| 1246 | .child( |
| 1247 | card.m(px(CARD_MARGIN)) |
| 1248 | .p(px(CARD_PADDING)) |
| 1249 | .gap(px(SECTION_GAP)) |
| 1250 | .rounded(px(CARD_RADIUS)) |
| 1251 | .dialog_surface() |
| 1252 | .text_color(theme::text()) |
| 1253 | .occlude() |
| 1254 | .overflow_hidden() |
| 1255 | .capture_key_down(cx.listener(Self::on_key_down)), |
| 1256 | ) |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | pub fn open_calendar_event( |
| 1261 | state: Entity<AppState>, |
| 1262 | event: CalendarEvent, |
| 1263 | _: &mut Window, |
| 1264 | cx: &mut App, |
| 1265 | ) { |
| 1266 | state.update(cx, |state, cx| state.request_calendar_event_peek(event, cx)); |
| 1267 | } |