fix: restore upstream linux/calendar bits after rebase
@@ -1,3 +1,5 @@
1
use std::time::Duration;
2
1
3
use app_base::format::{self, clock_format};
2
4
use chatsvc::{CalendarEvent, ResponseType, join_info_text};
3
5
use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};
@@ -12,9 +14,15 @@ use gpui_kit::*;
12
14
use super::calendar_date_picker::date_picker_button;
13
15
use super::calendar_month::month_grid;
14
16
use super::join_dialog::open_join_with_id;
17
use super::meeting_proposal_card::meeting_proposal_cards;
15
18
use super::new_meeting_dialog::open_new_meeting;
16
19
use super::rsvp_menu::rsvp_menu;
20
use super::scroll_edge::scroll_offset;
17
21
use crate::app_state::AppState;
22
use crate::call::calendar_now::{
23
DEFAULT_GRID_VIEWPORT, FollowNow, MANUAL_SCROLL_EPSILON, NOW_BIAS_FRACTION,
24
now_scroll_offset_y, offset_differs, shows_hour_grid,
25
};
18
26
use crate::call::join_available;
19
27
use crate::call::week_grid::{
20
28
CalendarSpan, EventLook, WeekBlock, WeekDay, event_look, hour_label, month_shown, week_days,
@@ -29,7 +37,6 @@ const HEADER_HEIGHT: f32 = 52.;
29
37
const DAY_HEADER_HEIGHT: f32 = 56.;
30
38
const ALL_DAY_HEIGHT: f32 = 26.;
31
39
const BLOCK_GAP: f32 = 2.;
32
const FIRST_VISIBLE_HOUR: f32 = 8.;
33
40
const CANCELED_PREFIX: &str = "Canceled: ";
34
41
const COPY_JOIN_INFO: &str = "Copy join info";
35
42
const COMPACT_HEADER_WIDTH: f32 = 960.;
@@ -41,25 +48,135 @@ const HATCH_GAP: f32 = 2.5;
41
48
const SMALL_TITLE_HEIGHT: f32 = 20.;
42
49
const TODAY_MARK_HEIGHT: f32 = 3.;
43
50
const NOW_DOT_SIZE: f32 = 8.;
51
const CLOCK_TICK: Duration = Duration::from_secs(30);
52
const CHROME_HEIGHT: f32 = HEADER_HEIGHT + DAY_HEADER_HEIGHT + ALL_DAY_HEIGHT;
44
53
45
54
pub struct CalendarView {
46
55
state: Entity<AppState>,
47
56
scroll: ScrollHandle,
48
scrolled_to_morning: bool,
57
follow_now: FollowNow,
58
seen_scroll_to_now: u64,
59
last_programmatic_offset: f32,
60
skip_manual_check: bool,
61
clock_running: bool,
49
62
_observation: Subscription,
63
_agent_observation: Option<Subscription>,
50
64
}
51
65
52
66
impl CalendarView {
53
67
pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {
54
68
let observation = cx.observe(&state, |_, _, cx| cx.notify());
69
let agent_observation = crate::agent_api::handle(cx).map(|api| cx.observe(&api, |_, _, cx| cx.notify()));
55
70
CalendarView {
56
71
state,
57
72
scroll: ScrollHandle::new(),
58
scrolled_to_morning: false,
73
follow_now: FollowNow { active: true },
74
seen_scroll_to_now: 0,
75
last_programmatic_offset: 0.,
76
skip_manual_check: false,
77
clock_running: false,
59
78
_observation: observation,
79
_agent_observation: agent_observation,
80
}
81
}
82
83
fn grid_viewport_height(window: &Window) -> f32 {
84
(f32::from(window.viewport_size().height) - CHROME_HEIGHT).max(DEFAULT_GRID_VIEWPORT * 0.5)
85
}
86
87
fn align_scroll_to_now(&mut self, window: &Window) {
88
let local = Local::now();
89
let offset = now_scroll_offset_y(
90
local.hour(),
91
local.minute(),
92
HOUR_HEIGHT,
93
Self::grid_viewport_height(window),
94
NOW_BIAS_FRACTION,
95
);
96
self.scroll.set_offset(point(px(0.), px(offset)));
97
self.last_programmatic_offset = offset;
98
self.skip_manual_check = true;
99
}
100
101
fn sync_follow_from_state(&mut self, window: &Window, cx: &mut Context<Self>) {
102
let (scroll_to_now, span, today_visible) = {
103
let state = self.state.read(cx);
104
let start = state.calendar_start();
105
let today = Local::now().date_naive();
106
let today_visible = start <= today
107
&& today < start + chrono::Duration::days(state.calendar_week.span.days());
108
(
109
state.calendar_scroll_to_now,
110
state.calendar_week.span,
111
today_visible,
112
)
113
};
114
if !shows_hour_grid(span) {
115
self.stop_clock();
116
return;
117
}
118
self.ensure_clock(cx);
119
if scroll_to_now != self.seen_scroll_to_now {
120
self.seen_scroll_to_now = scroll_to_now;
121
self.follow_now.request_align();
122
}
123
if self.skip_manual_check {
124
self.skip_manual_check = false;
125
} else if self.follow_now.active
126
&& offset_differs(
127
f32::from(scroll_offset(&self.scroll).y),
128
self.last_programmatic_offset,
129
MANUAL_SCROLL_EPSILON,
130
)
131
{
132
self.follow_now.note_manual_scroll();
133
}
134
if self.follow_now.should_follow(today_visible) {
135
self.align_scroll_to_now(window);
60
136
}
61
137
}
62
138
139
fn ensure_clock(&mut self, cx: &mut Context<Self>) {
140
if self.clock_running {
141
return;
142
}
143
self.clock_running = true;
144
cx.spawn(async move |this, cx| {
145
loop {
146
cx.background_executor().timer(CLOCK_TICK).await;
147
let keep = this
148
.update(cx, |view, cx| {
149
let span = view.state.read(cx).calendar_week.span;
150
if !shows_hour_grid(span) {
151
view.clock_running = false;
152
return false;
153
}
154
cx.notify();
155
true
156
})
157
.unwrap_or(false);
158
if !keep {
159
break;
160
}
161
}
162
})
163
.detach();
164
}
165
166
fn stop_clock(&mut self) {
167
self.clock_running = false;
168
}
169
170
fn on_grid_scroll_wheel(
171
&mut self,
172
_event: &ScrollWheelEvent,
173
_window: &mut Window,
174
cx: &mut Context<Self>,
175
) {
176
self.follow_now.note_manual_scroll();
177
cx.notify();
178
}
179
63
180
fn header(&self, start: NaiveDate, span: CalendarSpan, compact: bool) -> impl IntoElement {
64
181
let span_state = self.state.clone();
65
182
let label = |text: &'static str| (!compact).then_some(text);
@@ -390,6 +507,7 @@ impl CalendarView {
390
507
today: NaiveDate,
391
508
now: DateTime<Utc>,
392
509
send_response: bool,
510
cx: &mut Context<Self>,
393
511
) -> impl IntoElement {
394
512
let total_height = 24. * HOUR_HEIGHT;
395
513
let twelve_hour = clock_format().contains("%p") || clock_format().contains("%P");
@@ -403,6 +521,7 @@ impl CalendarView {
403
521
.min_h_0()
404
522
.overflow_y_scroll()
405
523
.track_scroll(&self.scroll)
524
.on_scroll_wheel(cx.listener(Self::on_grid_scroll_wheel))
406
525
.child(
407
526
h_flex()
408
527
.h(px(total_height))
@@ -570,11 +689,7 @@ fn event_title(event: &CalendarEvent) -> String {
570
689
impl Render for CalendarView {
571
690
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
572
691
let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;
573
if !self.scrolled_to_morning {
574
self.scrolled_to_morning = true;
575
self.scroll
576
.set_offset(point(px(0.), px(-FIRST_VISIBLE_HOUR * HOUR_HEIGHT)));
577
}
692
self.sync_follow_from_state(window, cx);
578
693
let state = self.state.read(cx);
579
694
let start = state.calendar_start();
580
695
let events = state.calendar_week.events.clone();
@@ -594,6 +709,7 @@ impl Render for CalendarView {
594
709
.bg(theme::surface())
595
710
.overflow_hidden()
596
711
.child(self.header(start, span, compact))
712
.children(meeting_proposal_cards(cx))
597
713
.map(|calendar| {
598
714
if span == CalendarSpan::Month {
599
715
calendar.child(month_grid(
@@ -608,7 +724,7 @@ impl Render for CalendarView {
608
724
calendar
609
725
.child(self.day_headers(&days, today))
610
726
.children(self.all_day_row(&days, &events))
611
.child(self.grid(&days, &events, today, now, send_response))
727
.child(self.grid(&days, &events, today, now, send_response, cx))
612
728
}
613
729
})
614
730
}
@@ -1,3 +1,5 @@1
use std::time::Duration;2
1
use app_base::format::{self, clock_format};3
use app_base::format::{self, clock_format};2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};4
use chatsvc::{CalendarEvent, ResponseType, join_info_text};3
use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};5
use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};@@ -12,9 +14,15 @@ use gpui_kit::*;12
use super::calendar_date_picker::date_picker_button;14
use super::calendar_date_picker::date_picker_button;13
use super::calendar_month::month_grid;15
use super::calendar_month::month_grid;14
use super::join_dialog::open_join_with_id;16
use super::join_dialog::open_join_with_id;17
use super::meeting_proposal_card::meeting_proposal_cards;15
use super::new_meeting_dialog::open_new_meeting;18
use super::new_meeting_dialog::open_new_meeting;16
use super::rsvp_menu::rsvp_menu;19
use super::rsvp_menu::rsvp_menu;20
use super::scroll_edge::scroll_offset;17
use crate::app_state::AppState;21
use crate::app_state::AppState;22
use crate::call::calendar_now::{23
DEFAULT_GRID_VIEWPORT, FollowNow, MANUAL_SCROLL_EPSILON, NOW_BIAS_FRACTION,24
now_scroll_offset_y, offset_differs, shows_hour_grid,25
};18
use crate::call::join_available;26
use crate::call::join_available;19
use crate::call::week_grid::{27
use crate::call::week_grid::{20
CalendarSpan, EventLook, WeekBlock, WeekDay, event_look, hour_label, month_shown, week_days,28
CalendarSpan, EventLook, WeekBlock, WeekDay, event_look, hour_label, month_shown, week_days,@@ -29,7 +37,6 @@ const HEADER_HEIGHT: f32 = 52.;29
const DAY_HEADER_HEIGHT: f32 = 56.;37
const DAY_HEADER_HEIGHT: f32 = 56.;30
const ALL_DAY_HEIGHT: f32 = 26.;38
const ALL_DAY_HEIGHT: f32 = 26.;31
const BLOCK_GAP: f32 = 2.;39
const BLOCK_GAP: f32 = 2.;32
const FIRST_VISIBLE_HOUR: f32 = 8.;33
const CANCELED_PREFIX: &str = "Canceled: ";40
const CANCELED_PREFIX: &str = "Canceled: ";34
const COPY_JOIN_INFO: &str = "Copy join info";41
const COPY_JOIN_INFO: &str = "Copy join info";35
const COMPACT_HEADER_WIDTH: f32 = 960.;42
const COMPACT_HEADER_WIDTH: f32 = 960.;@@ -41,25 +48,135 @@ const HATCH_GAP: f32 = 2.5;41
const SMALL_TITLE_HEIGHT: f32 = 20.;48
const SMALL_TITLE_HEIGHT: f32 = 20.;42
const TODAY_MARK_HEIGHT: f32 = 3.;49
const TODAY_MARK_HEIGHT: f32 = 3.;43
const NOW_DOT_SIZE: f32 = 8.;50
const NOW_DOT_SIZE: f32 = 8.;51
const CLOCK_TICK: Duration = Duration::from_secs(30);52
const CHROME_HEIGHT: f32 = HEADER_HEIGHT + DAY_HEADER_HEIGHT + ALL_DAY_HEIGHT;44
53
45
pub struct CalendarView {54
pub struct CalendarView {46
state: Entity<AppState>,55
state: Entity<AppState>,47
scroll: ScrollHandle,56
scroll: ScrollHandle,48
scrolled_to_morning: bool,57
follow_now: FollowNow,58
seen_scroll_to_now: u64,59
last_programmatic_offset: f32,60
skip_manual_check: bool,61
clock_running: bool,49
_observation: Subscription,62
_observation: Subscription,63
_agent_observation: Option<Subscription>,50
}64
}51
65
52
impl CalendarView {66
impl CalendarView {53
pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {67
pub fn new(state: Entity<AppState>, cx: &mut Context<Self>) -> Self {54
let observation = cx.observe(&state, |_, _, cx| cx.notify());68
let observation = cx.observe(&state, |_, _, cx| cx.notify());69
let agent_observation = crate::agent_api::handle(cx).map(|api| cx.observe(&api, |_, _, cx| cx.notify()));55
CalendarView {70
CalendarView {56
state,71
state,57
scroll: ScrollHandle::new(),72
scroll: ScrollHandle::new(),58
scrolled_to_morning: false,73
follow_now: FollowNow { active: true },74
seen_scroll_to_now: 0,75
last_programmatic_offset: 0.,76
skip_manual_check: false,77
clock_running: false,59
_observation: observation,78
_observation: observation,79
_agent_observation: agent_observation,80
}81
}82
83
fn grid_viewport_height(window: &Window) -> f32 {84
(f32::from(window.viewport_size().height) - CHROME_HEIGHT).max(DEFAULT_GRID_VIEWPORT * 0.5)85
}86
87
fn align_scroll_to_now(&mut self, window: &Window) {88
let local = Local::now();89
let offset = now_scroll_offset_y(90
local.hour(),91
local.minute(),92
HOUR_HEIGHT,93
Self::grid_viewport_height(window),94
NOW_BIAS_FRACTION,95
);96
self.scroll.set_offset(point(px(0.), px(offset)));97
self.last_programmatic_offset = offset;98
self.skip_manual_check = true;99
}100
101
fn sync_follow_from_state(&mut self, window: &Window, cx: &mut Context<Self>) {102
let (scroll_to_now, span, today_visible) = {103
let state = self.state.read(cx);104
let start = state.calendar_start();105
let today = Local::now().date_naive();106
let today_visible = start <= today107
&& today < start + chrono::Duration::days(state.calendar_week.span.days());108
(109
state.calendar_scroll_to_now,110
state.calendar_week.span,111
today_visible,112
)113
};114
if !shows_hour_grid(span) {115
self.stop_clock();116
return;117
}118
self.ensure_clock(cx);119
if scroll_to_now != self.seen_scroll_to_now {120
self.seen_scroll_to_now = scroll_to_now;121
self.follow_now.request_align();122
}123
if self.skip_manual_check {124
self.skip_manual_check = false;125
} else if self.follow_now.active126
&& offset_differs(127
f32::from(scroll_offset(&self.scroll).y),128
self.last_programmatic_offset,129
MANUAL_SCROLL_EPSILON,130
)131
{132
self.follow_now.note_manual_scroll();133
}134
if self.follow_now.should_follow(today_visible) {135
self.align_scroll_to_now(window);60
}136
}61
}137
}62
138
139
fn ensure_clock(&mut self, cx: &mut Context<Self>) {140
if self.clock_running {141
return;142
}143
self.clock_running = true;144
cx.spawn(async move |this, cx| {145
loop {146
cx.background_executor().timer(CLOCK_TICK).await;147
let keep = this148
.update(cx, |view, cx| {149
let span = view.state.read(cx).calendar_week.span;150
if !shows_hour_grid(span) {151
view.clock_running = false;152
return false;153
}154
cx.notify();155
true156
})157
.unwrap_or(false);158
if !keep {159
break;160
}161
}162
})163
.detach();164
}165
166
fn stop_clock(&mut self) {167
self.clock_running = false;168
}169
170
fn on_grid_scroll_wheel(171
&mut self,172
_event: &ScrollWheelEvent,173
_window: &mut Window,174
cx: &mut Context<Self>,175
) {176
self.follow_now.note_manual_scroll();177
cx.notify();178
}179
63
fn header(&self, start: NaiveDate, span: CalendarSpan, compact: bool) -> impl IntoElement {180
fn header(&self, start: NaiveDate, span: CalendarSpan, compact: bool) -> impl IntoElement {64
let span_state = self.state.clone();181
let span_state = self.state.clone();65
let label = |text: &'static str| (!compact).then_some(text);182
let label = |text: &'static str| (!compact).then_some(text);@@ -390,6 +507,7 @@ impl CalendarView {390
today: NaiveDate,507
today: NaiveDate,391
now: DateTime<Utc>,508
now: DateTime<Utc>,392
send_response: bool,509
send_response: bool,510
cx: &mut Context<Self>,393
) -> impl IntoElement {511
) -> impl IntoElement {394
let total_height = 24. * HOUR_HEIGHT;512
let total_height = 24. * HOUR_HEIGHT;395
let twelve_hour = clock_format().contains("%p") || clock_format().contains("%P");513
let twelve_hour = clock_format().contains("%p") || clock_format().contains("%P");@@ -403,6 +521,7 @@ impl CalendarView {403
.min_h_0()521
.min_h_0()404
.overflow_y_scroll()522
.overflow_y_scroll()405
.track_scroll(&self.scroll)523
.track_scroll(&self.scroll)524
.on_scroll_wheel(cx.listener(Self::on_grid_scroll_wheel))406
.child(525
.child(407
h_flex()526
h_flex()408
.h(px(total_height))527
.h(px(total_height))@@ -570,11 +689,7 @@ fn event_title(event: &CalendarEvent) -> String {570
impl Render for CalendarView {689
impl Render for CalendarView {571
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {690
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {572
let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;691
let compact = f32::from(window.viewport_size().width) < COMPACT_HEADER_WIDTH;573
if !self.scrolled_to_morning {692
self.sync_follow_from_state(window, cx);574
self.scrolled_to_morning = true;575
self.scroll576
.set_offset(point(px(0.), px(-FIRST_VISIBLE_HOUR * HOUR_HEIGHT)));577
}578
let state = self.state.read(cx);693
let state = self.state.read(cx);579
let start = state.calendar_start();694
let start = state.calendar_start();580
let events = state.calendar_week.events.clone();695
let events = state.calendar_week.events.clone();@@ -594,6 +709,7 @@ impl Render for CalendarView {594
.bg(theme::surface())709
.bg(theme::surface())595
.overflow_hidden()710
.overflow_hidden()596
.child(self.header(start, span, compact))711
.child(self.header(start, span, compact))712
.children(meeting_proposal_cards(cx))597
.map(|calendar| {713
.map(|calendar| {598
if span == CalendarSpan::Month {714
if span == CalendarSpan::Month {599
calendar.child(month_grid(715
calendar.child(month_grid(@@ -608,7 +724,7 @@ impl Render for CalendarView {608
calendar724
calendar609
.child(self.day_headers(&days, today))725
.child(self.day_headers(&days, today))610
.children(self.all_day_row(&days, &events))726
.children(self.all_day_row(&days, &events))611
.child(self.grid(&days, &events, today, now, send_response))727
.child(self.grid(&days, &events, today, now, send_response, cx))612
}728
}613
})729
})614
}730
}