Add logged out collab panel
This commit is contained in:
parent
4f885252ab
commit
6f839a1b48
2 changed files with 65 additions and 38 deletions
|
@ -167,10 +167,11 @@ use gpui::{
|
||||||
use project::Fs;
|
use project::Fs;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use ui::{h_stack, Avatar, Label};
|
use ui::{h_stack, v_stack, Avatar, Button, Label};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
dock::{DockPosition, Panel, PanelEvent},
|
dock::{DockPosition, Panel, PanelEvent},
|
||||||
|
notifications::NotifyResultExt,
|
||||||
Workspace,
|
Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -302,7 +303,7 @@ pub struct CollabPanel {
|
||||||
// entries: Vec<ListEntry>,
|
// entries: Vec<ListEntry>,
|
||||||
// selection: Option<usize>,
|
// selection: Option<usize>,
|
||||||
user_store: Model<UserStore>,
|
user_store: Model<UserStore>,
|
||||||
_client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
// channel_store: ModelHandle<ChannelStore>,
|
// channel_store: ModelHandle<ChannelStore>,
|
||||||
// project: ModelHandle<Project>,
|
// project: ModelHandle<Project>,
|
||||||
// match_candidates: Vec<StringMatchCandidate>,
|
// match_candidates: Vec<StringMatchCandidate>,
|
||||||
|
@ -311,7 +312,7 @@ pub struct CollabPanel {
|
||||||
// collapsed_sections: Vec<Section>,
|
// collapsed_sections: Vec<Section>,
|
||||||
// collapsed_channels: Vec<ChannelId>,
|
// collapsed_channels: Vec<ChannelId>,
|
||||||
// drag_target_channel: ChannelDragTarget,
|
// drag_target_channel: ChannelDragTarget,
|
||||||
_workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
// context_menu_on_selected: bool,
|
// context_menu_on_selected: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,8 +605,8 @@ impl CollabPanel {
|
||||||
// match_candidates: Vec::default(),
|
// match_candidates: Vec::default(),
|
||||||
// collapsed_sections: vec![Section::Offline],
|
// collapsed_sections: vec![Section::Offline],
|
||||||
// collapsed_channels: Vec::default(),
|
// collapsed_channels: Vec::default(),
|
||||||
_workspace: workspace.weak_handle(),
|
workspace: workspace.weak_handle(),
|
||||||
_client: workspace.app_state().client.clone(),
|
client: workspace.app_state().client.clone(),
|
||||||
// context_menu_on_selected: true,
|
// context_menu_on_selected: true,
|
||||||
// drag_target_channel: ChannelDragTarget::None,
|
// drag_target_channel: ChannelDragTarget::None,
|
||||||
// list_state,
|
// list_state,
|
||||||
|
@ -3252,6 +3253,53 @@ impl CollabPanel {
|
||||||
// let item = ClipboardItem::new(channel.link());
|
// let item = ClipboardItem::new(channel.link());
|
||||||
// cx.write_to_clipboard(item)
|
// cx.write_to_clipboard(item)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
fn render_signed_out(&mut self, cx: &mut ViewContext<Self>) -> Div {
|
||||||
|
v_stack().child(Button::new("Sign in to collaborate").on_click(cx.listener(
|
||||||
|
|this, _, cx| {
|
||||||
|
let client = this.client.clone();
|
||||||
|
cx.spawn(|_, mut cx| async move {
|
||||||
|
client
|
||||||
|
.authenticate_and_connect(true, &cx)
|
||||||
|
.await
|
||||||
|
.notify_async_err(&mut cx);
|
||||||
|
})
|
||||||
|
.detach()
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> Div {
|
||||||
|
let contacts = self.contacts(cx).unwrap_or_default();
|
||||||
|
let workspace = self.workspace.clone();
|
||||||
|
|
||||||
|
v_stack().children(contacts.into_iter().map(|contact| {
|
||||||
|
let id = contact.user.id;
|
||||||
|
h_stack()
|
||||||
|
.p_2()
|
||||||
|
.gap_2()
|
||||||
|
.children(
|
||||||
|
contact
|
||||||
|
.user
|
||||||
|
.avatar
|
||||||
|
.as_ref()
|
||||||
|
.map(|avatar| Avatar::data(avatar.clone())),
|
||||||
|
)
|
||||||
|
.child(Label::new(contact.user.github_login.clone()))
|
||||||
|
.on_mouse_down(gpui::MouseButton::Left, {
|
||||||
|
let workspace = workspace.clone();
|
||||||
|
move |_, cx| {
|
||||||
|
workspace
|
||||||
|
.update(cx, |this, cx| {
|
||||||
|
this.call_state()
|
||||||
|
.invite(id, None, cx)
|
||||||
|
.detach_and_log_err(cx)
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn render_tree_branch(
|
// fn render_tree_branch(
|
||||||
|
@ -3303,37 +3351,14 @@ impl Render for CollabPanel {
|
||||||
type Element = Focusable<Div>;
|
type Element = Focusable<Div>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let contacts = self.contacts(cx).unwrap_or_default();
|
|
||||||
let workspace = self._workspace.clone();
|
|
||||||
div()
|
div()
|
||||||
.key_context("CollabPanel")
|
.key_context("CollabPanel")
|
||||||
.track_focus(&self.focus_handle)
|
.track_focus(&self.focus_handle)
|
||||||
.children(contacts.into_iter().map(|contact| {
|
.child(if self.user_store.read(cx).current_user().is_none() {
|
||||||
let id = contact.user.id;
|
self.render_signed_out(cx)
|
||||||
h_stack()
|
} else {
|
||||||
.p_2()
|
self.render_signed_in(cx)
|
||||||
.gap_2()
|
})
|
||||||
.children(
|
|
||||||
contact
|
|
||||||
.user
|
|
||||||
.avatar
|
|
||||||
.as_ref()
|
|
||||||
.map(|avatar| Avatar::data(avatar.clone())),
|
|
||||||
)
|
|
||||||
.child(Label::new(contact.user.github_login.clone()))
|
|
||||||
.on_mouse_down(gpui::MouseButton::Left, {
|
|
||||||
let workspace = workspace.clone();
|
|
||||||
move |_, cx| {
|
|
||||||
workspace
|
|
||||||
.update(cx, |this, cx| {
|
|
||||||
this.call_state()
|
|
||||||
.invite(id, None, cx)
|
|
||||||
.detach_and_log_err(cx)
|
|
||||||
})
|
|
||||||
.log_err();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ use project::Project;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::{h_stack, Avatar, Button, ButtonVariant, Color, IconButton, KeyBinding, Tooltip};
|
use ui::{h_stack, Avatar, Button, ButtonVariant, Color, IconButton, KeyBinding, Tooltip};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::Workspace;
|
use workspace::{notifications::NotifyResultExt, Workspace};
|
||||||
|
|
||||||
use crate::face_pile::FacePile;
|
use crate::face_pile::FacePile;
|
||||||
|
|
||||||
|
@ -290,11 +290,13 @@ impl Render for CollabTitlebarItem {
|
||||||
} else {
|
} else {
|
||||||
this.child(Button::new("Sign in").on_click(move |_, cx| {
|
this.child(Button::new("Sign in").on_click(move |_, cx| {
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
cx.spawn(move |cx| async move {
|
cx.spawn(move |mut cx| async move {
|
||||||
client.authenticate_and_connect(true, &cx).await?;
|
client
|
||||||
Ok::<(), anyhow::Error>(())
|
.authenticate_and_connect(true, &cx)
|
||||||
|
.await
|
||||||
|
.notify_async_err(&mut cx);
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
.detach();
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue