Show sign in button directly in titlebar when not signed in

Max Brunsfeld and Antonio Scandurra created

Co-authored-by: Antonio Scandurra <antonio@zed.dev>

Change summary

crates/collab_ui/src/collab_titlebar_item.rs | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

Detailed changes

crates/collab_ui/src/collab_titlebar_item.rs 🔗

@@ -119,12 +119,12 @@ impl View for CollabTitlebarItem {
         let status = &*status.borrow();
         if matches!(status, client::Status::Connected { .. }) {
             right_container.add_child(self.render_toggle_contacts_button(&theme, cx));
+            right_container.add_child(self.render_user_menu_button(&theme, cx));
         } else {
             right_container.add_children(self.render_connection_status(status, cx));
+            right_container.add_child(self.render_sign_in_button(&theme, cx));
         }
 
-        right_container.add_child(self.render_user_menu_button(&theme, cx));
-
         Stack::new()
             .with_child(left_container.boxed())
             .with_child(right_container.aligned().right().boxed())
@@ -554,6 +554,22 @@ impl CollabTitlebarItem {
             .boxed()
     }
 
+    fn render_sign_in_button(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
+        let titlebar = &theme.workspace.titlebar;
+        MouseEventHandler::<Authenticate>::new(0, cx, |state, _| {
+            let style = titlebar.sign_in_prompt.style_for(state, false);
+            Label::new("Sign In", style.text.clone())
+                .contained()
+                .with_style(style.container)
+                .boxed()
+        })
+        .with_cursor_style(CursorStyle::PointingHand)
+        .on_click(MouseButton::Left, move |_, cx| {
+            cx.dispatch_action(Authenticate);
+        })
+        .boxed()
+    }
+
     fn render_contacts_popover_host<'a>(
         &'a self,
         theme: &'a theme::Titlebar,