Render "Sign in" label only for current user

This commit is contained in:
Antonio Scandurra 2022-02-15 09:17:32 +01:00
parent 4e748b188e
commit 809b843ceb

View file

@ -17,9 +17,9 @@ use gpui::{
json::{self, to_string_pretty, ToJson}, json::{self, to_string_pretty, ToJson},
keymap::Binding, keymap::Binding,
platform::{CursorStyle, WindowOptions}, platform::{CursorStyle, WindowOptions},
AnyModelHandle, AnyViewHandle, AppContext, ClipboardItem, Entity, ModelContext, ModelHandle, AnyModelHandle, AnyViewHandle, AppContext, ClipboardItem, Entity, ImageData, ModelContext,
MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View, ViewContext, ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View,
ViewHandle, WeakModelHandle, WeakViewHandle, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
}; };
use language::LanguageRegistry; use language::LanguageRegistry;
use log::error; use log::error;
@ -1139,7 +1139,7 @@ impl Workspace {
Flex::row() Flex::row()
.with_children(self.render_share_icon(theme, cx)) .with_children(self.render_share_icon(theme, cx))
.with_children(self.render_collaborators(theme, cx)) .with_children(self.render_collaborators(theme, cx))
.with_child(self.render_avatar( .with_child(self.render_current_user(
self.user_store.read(cx).current_user().as_ref(), self.user_store.read(cx).current_user().as_ref(),
self.project.read(cx).replica_id(), self.project.read(cx).replica_id(),
theme, theme,
@ -1171,13 +1171,17 @@ impl Workspace {
collaborators.sort_unstable_by_key(|collaborator| collaborator.replica_id); collaborators.sort_unstable_by_key(|collaborator| collaborator.replica_id);
collaborators collaborators
.into_iter() .into_iter()
.map(|collaborator| { .filter_map(|collaborator| {
self.render_avatar(Some(&collaborator.user), collaborator.replica_id, theme, cx) Some(self.render_avatar(
collaborator.user.avatar.clone()?,
collaborator.replica_id,
theme,
))
}) })
.collect() .collect()
} }
fn render_avatar( fn render_current_user(
&self, &self,
user: Option<&Arc<User>>, user: Option<&Arc<User>>,
replica_id: ReplicaId, replica_id: ReplicaId,
@ -1185,33 +1189,9 @@ impl Workspace {
cx: &mut RenderContext<Self>, cx: &mut RenderContext<Self>,
) -> ElementBox { ) -> ElementBox {
if let Some(avatar) = user.and_then(|user| user.avatar.clone()) { if let Some(avatar) = user.and_then(|user| user.avatar.clone()) {
ConstrainedBox::new( self.render_avatar(avatar, replica_id, theme)
Stack::new()
.with_child(
ConstrainedBox::new(
Image::new(avatar)
.with_style(theme.workspace.titlebar.avatar)
.boxed(),
)
.with_width(theme.workspace.titlebar.avatar_width)
.aligned()
.boxed(),
)
.with_child(
AvatarRibbon::new(theme.editor.replica_selection_style(replica_id).cursor)
.constrained()
.with_width(theme.workspace.titlebar.avatar_ribbon.width)
.with_height(theme.workspace.titlebar.avatar_ribbon.height)
.aligned()
.bottom()
.boxed(),
)
.boxed(),
)
.with_width(theme.workspace.right_sidebar.width)
.boxed()
} else { } else {
MouseEventHandler::new::<Authenticate, _, _, _>(0, cx, |state, _| { MouseEventHandler::new::<Authenticate, _, _, _>(cx.view_id(), cx, |state, _| {
let style = if state.hovered { let style = if state.hovered {
&theme.workspace.titlebar.hovered_sign_in_prompt &theme.workspace.titlebar.hovered_sign_in_prompt
} else { } else {
@ -1229,6 +1209,39 @@ impl Workspace {
} }
} }
fn render_avatar(
&self,
avatar: Arc<ImageData>,
replica_id: ReplicaId,
theme: &Theme,
) -> ElementBox {
ConstrainedBox::new(
Stack::new()
.with_child(
ConstrainedBox::new(
Image::new(avatar)
.with_style(theme.workspace.titlebar.avatar)
.boxed(),
)
.with_width(theme.workspace.titlebar.avatar_width)
.aligned()
.boxed(),
)
.with_child(
AvatarRibbon::new(theme.editor.replica_selection_style(replica_id).cursor)
.constrained()
.with_width(theme.workspace.titlebar.avatar_ribbon.width)
.with_height(theme.workspace.titlebar.avatar_ribbon.height)
.aligned()
.bottom()
.boxed(),
)
.boxed(),
)
.with_width(theme.workspace.right_sidebar.width)
.boxed()
}
fn render_share_icon(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> Option<ElementBox> { fn render_share_icon(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> Option<ElementBox> {
if self.project().read(cx).is_local() && self.client.user_id().is_some() { if self.project().read(cx).is_local() && self.client.user_id().is_some() {
enum Share {} enum Share {}