From 5cbe8deb50faeee5376a1174baea021333586759 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:33:44 +0100 Subject: [PATCH] Fix up tests --- crates/collab_ui2/src/collab_panel.rs | 2 +- crates/collab_ui2/src/collab_titlebar_item.rs | 6 +++--- .../src/notifications/incoming_call_notification.rs | 2 +- crates/ui2/src/components/avatar.rs | 12 ++++++++++-- crates/ui2/src/components/list.rs | 4 ++-- crates/ui2/src/components/stories/avatar.rs | 8 ++++---- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/collab_ui2/src/collab_panel.rs b/crates/collab_ui2/src/collab_panel.rs index abeb481d53..22a8a2cbba 100644 --- a/crates/collab_ui2/src/collab_panel.rs +++ b/crates/collab_ui2/src/collab_panel.rs @@ -3318,7 +3318,7 @@ impl Render for CollabPanel { .user .avatar .as_ref() - .map(|avatar| Avatar::new(avatar.clone())), + .map(|avatar| Avatar::data(avatar.clone())), ) .child(Label::new(contact.user.github_login.clone())) .on_mouse_down(gpui::MouseButton::Left, { diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index aad908531a..9386d3ff35 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/crates/collab_ui2/src/collab_titlebar_item.rs @@ -182,12 +182,12 @@ impl Render for CollabTitlebarItem { current_user .avatar .clone() - .map(|avatar| div().child(Avatar::new(avatar.clone()))) + .map(|avatar| div().child(Avatar::data(avatar.clone()))) .into_iter() .chain(remote_participants.into_iter().flat_map(|(user, peer_id)| { user.avatar.as_ref().map(|avatar| { div() - .child(Avatar::new(avatar.clone()).into_element()) + .child(Avatar::data(avatar.clone()).into_element()) .on_mouse_down(MouseButton::Left, { let workspace = workspace.clone(); let id = peer_id.clone(); @@ -235,7 +235,7 @@ impl Render for CollabTitlebarItem { .map(|this| { if let Some(user) = current_user { this.when_some(user.avatar.clone(), |this, avatar| { - this.child(ui::Avatar::new(avatar)) + this.child(ui::Avatar::data(avatar)) }) } else { this.child(Button::new("Sign in").on_click(move |_, cx| { diff --git a/crates/collab_ui2/src/notifications/incoming_call_notification.rs b/crates/collab_ui2/src/notifications/incoming_call_notification.rs index d400b14f5f..f47fcf0751 100644 --- a/crates/collab_ui2/src/notifications/incoming_call_notification.rs +++ b/crates/collab_ui2/src/notifications/incoming_call_notification.rs @@ -129,7 +129,7 @@ impl IncomingCallNotification { .calling_user .avatar .as_ref() - .map(|avatar| Avatar::new(avatar.clone())), + .map(|avatar| Avatar::data(avatar.clone())), ) .child( v_stack() diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index 0ea7702f52..d358b221da 100644 --- a/crates/ui2/src/components/avatar.rs +++ b/crates/ui2/src/components/avatar.rs @@ -1,5 +1,7 @@ +use std::sync::Arc; + use crate::prelude::*; -use gpui::{img, ImageSource, Img, IntoElement}; +use gpui::{img, ImageData, ImageSource, Img, IntoElement}; #[derive(Debug, Default, PartialEq, Clone)] pub enum Shape { @@ -34,7 +36,13 @@ impl RenderOnce for Avatar { } impl Avatar { - pub fn new(src: impl Into) -> Self { + pub fn uri(src: impl Into) -> Self { + Self { + src: src.into().into(), + shape: Shape::Circle, + } + } + pub fn data(src: Arc) -> Self { Self { src: src.into(), shape: Shape::Circle, diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index a994583666..875ab6d97e 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -323,8 +323,8 @@ impl RenderOnce for ListItem { .color(Color::Muted), ), ), - Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::new(src))), - Some(GraphicSlot::PublicActor(src)) => Some(h_stack().child(Avatar::new(src))), + Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::uri(src))), + Some(GraphicSlot::PublicActor(src)) => Some(h_stack().child(Avatar::uri(src))), None => None, }; diff --git a/crates/ui2/src/components/stories/avatar.rs b/crates/ui2/src/components/stories/avatar.rs index 177065cfcb..505ede4ecc 100644 --- a/crates/ui2/src/components/stories/avatar.rs +++ b/crates/ui2/src/components/stories/avatar.rs @@ -13,11 +13,11 @@ impl Render for AvatarStory { Story::container() .child(Story::title_for::()) .child(Story::label("Default")) - .child(Avatar::new( - "https://avatars.githubusercontent.com/u/1714999?v=4".into(), + .child(Avatar::uri( + "https://avatars.githubusercontent.com/u/1714999?v=4", )) - .child(Avatar::new( - "https://avatars.githubusercontent.com/u/326587?v=4".into(), + .child(Avatar::uri( + "https://avatars.githubusercontent.com/u/326587?v=4", )) } }