zed2: Port ProjectSharedNotification

This commit is contained in:
Julia 2023-12-07 17:10:54 -05:00
parent 853daf953b
commit f3cbce7e86
3 changed files with 97 additions and 256 deletions

View file

@ -33,8 +33,8 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
height: px(64.),
};
for window in unique_screens {
let options = notification_window_options(window, window_size);
for screen in unique_screens {
let options = notification_window_options(screen, window_size);
let window = cx
.open_window(options, |cx| {
cx.build_view(|_| {
@ -47,15 +47,6 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
.unwrap();
notification_windows.push(window);
}
// for screen in cx.platform().screens() {
// let window = cx
// .add_window(notification_window_options(screen, window_size), |_| {
// IncomingCallNotification::new(incoming_call.clone(), app_state.clone())
// });
// notification_windows.push(window);
// }
}
}
})
@ -84,21 +75,22 @@ impl IncomingCallNotificationState {
let active_call = ActiveCall::global(cx);
if accept {
let join = active_call.update(cx, |active_call, cx| active_call.accept_incoming(cx));
let caller_user_id = self.call.calling_user.id;
let initial_project_id = self.call.initial_project.as_ref().map(|project| project.id);
let app_state = self.app_state.clone();
let cx: &mut AppContext = cx;
cx.spawn(|cx| async move {
join.await?;
if let Some(_project_id) = initial_project_id {
cx.update(|_cx| {
if let Some(_app_state) = app_state.upgrade() {
// workspace::join_remote_project(
// project_id,
// caller_user_id,
// app_state,
// cx,
// )
// .detach_and_log_err(cx);
if let Some(project_id) = initial_project_id {
cx.update(|cx| {
if let Some(app_state) = app_state.upgrade() {
workspace::join_remote_project(
project_id,
caller_user_id,
app_state,
cx,
)
.detach_and_log_err(cx);
}
})
.log_err();
@ -138,135 +130,25 @@ impl IncomingCallNotification {
)))
.child(self.render_buttons(cx)),
)
// let theme = &theme::current(cx).incoming_call_notification;
// let default_project = proto::ParticipantProject::default();
// let initial_project = self
// .call
// .initial_project
// .as_ref()
// .unwrap_or(&default_project);
// Flex::row()
// .with_children(self.call.calling_user.avatar.clone().map(|avatar| {
// Image::from_data(avatar)
// .with_style(theme.caller_avatar)
// .aligned()
// }))
// .with_child(
// Flex::column()
// .with_child(
// Label::new(
// self.call.calling_user.github_login.clone(),
// theme.caller_username.text.clone(),
// )
// .contained()
// .with_style(theme.caller_username.container),
// )
// .with_child(
// Label::new(
// format!(
// "is sharing a project in Zed{}",
// if initial_project.worktree_root_names.is_empty() {
// ""
// } else {
// ":"
// }
// ),
// theme.caller_message.text.clone(),
// )
// .contained()
// .with_style(theme.caller_message.container),
// )
// .with_children(if initial_project.worktree_root_names.is_empty() {
// None
// } else {
// Some(
// Label::new(
// initial_project.worktree_root_names.join(", "),
// theme.worktree_roots.text.clone(),
// )
// .contained()
// .with_style(theme.worktree_roots.container),
// )
// })
// .contained()
// .with_style(theme.caller_metadata)
// .aligned(),
// )
// .contained()
// .with_style(theme.caller_container)
// .flex(1., true)
// .into_any()
}
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> impl Element {
h_stack()
.child(
Button::new("accept", "Accept")
.render(cx)
// .bg(green())
.on_click({
let state = self.state.clone();
move |_, cx| state.respond(true, cx)
}),
)
.child(
Button::new("decline", "Decline")
.render(cx)
// .bg(red())
.on_click({
let state = self.state.clone();
move |_, cx| state.respond(false, cx)
}),
)
// enum Accept {}
// enum Decline {}
// let theme = theme::current(cx);
// Flex::column()
// .with_child(
// MouseEventHandler::new::<Accept, _>(0, cx, |_, _| {
// let theme = &theme.incoming_call_notification;
// Label::new("Accept", theme.accept_button.text.clone())
// .aligned()
// .contained()
// .with_style(theme.accept_button.container)
// })
// .with_cursor_style(CursorStyle::PointingHand)
// .on_click(MouseButton::Left, |_, this, cx| {
// this.respond(true, cx);
// })
// .flex(1., true),
// )
// .with_child(
// MouseEventHandler::new::<Decline, _>(0, cx, |_, _| {
// let theme = &theme.incoming_call_notification;
// Label::new("Decline", theme.decline_button.text.clone())
// .aligned()
// .contained()
// .with_style(theme.decline_button.container)
// })
// .with_cursor_style(CursorStyle::PointingHand)
// .on_click(MouseButton::Left, |_, this, cx| {
// this.respond(false, cx);
// })
// .flex(1., true),
// )
// .constrained()
// .with_width(theme.incoming_call_notification.button_width)
// .into_any()
.child(Button::new("accept", "Accept").render(cx).on_click({
let state = self.state.clone();
move |_, cx| state.respond(true, cx)
}))
.child(Button::new("decline", "Decline").render(cx).on_click({
let state = self.state.clone();
move |_, cx| state.respond(false, cx)
}))
}
}
impl Render for IncomingCallNotification {
type Element = Div;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
div().bg(red()).flex_none().child(self.render_caller(cx))
// Flex::row()
// .with_child()
// .with_child(self.render_buttons(cx))
// .contained()
// .with_background_color(background)
// .expanded()
// .into_any()
}
}