chore: refactor avatar component
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-10-15 10:53:28 +07:00
parent e2edb9dd12
commit cd61a09320
15 changed files with 275 additions and 279 deletions
+6 -2
View File
@@ -71,7 +71,7 @@ pub(crate) fn sidebar_section(
h_flex()
.gap_1()
.items_center()
.child(Avatar::new(name.clone()).picture(picture))
.child(Avatar::new(*pubkey).name(name.clone()).picture(picture))
.child(div().text_sm().truncate().text_ellipsis().child(name))
.into_any_element()
})),
@@ -137,7 +137,11 @@ pub(crate) fn comments_section(store: &Entity<RepoStore>, root: EventId, cx: &Ap
.child(
h_flex()
.gap_1()
.child(Avatar::new(author.clone()).picture(picture))
.child(
Avatar::new(comment.pubkey)
.name(author.clone())
.picture(picture),
)
.child(author),
)
.child(
+2 -1
View File
@@ -544,7 +544,8 @@ fn sub_activity(event: &Event, me: Option<PublicKey>, cx: &App) -> AnyElement {
.items_center()
.text_xs()
.child(
Avatar::new(name.clone())
Avatar::new(event.pubkey)
.name(name.clone())
.picture(profile.picture())
.xsmall(),
)
+3 -2
View File
@@ -93,7 +93,7 @@ impl Render for IssueDetailView {
};
};
let (title, author, picture, status, age, issue_id, content) = {
let (title, author, picture, status, age, issue_id, content, pubkey) = {
let profile_store = ProfileStore::global(cx);
let profile = profile_store.read(cx).get(&issue.pubkey);
let content = if issue.content.is_empty() {
@@ -110,6 +110,7 @@ impl Render for IssueDetailView {
relative_time(issue.created_at),
issue.id,
content,
issue.pubkey,
)
};
@@ -153,7 +154,7 @@ impl Render for IssueDetailView {
.child(
h_flex()
.gap_1()
.child(Avatar::new(&author).picture(picture))
.child(Avatar::new(pubkey).name(author.clone()).picture(picture))
.child(author),
)
.child(
+5 -1
View File
@@ -189,7 +189,11 @@ impl IssuesView {
.child(
h_flex()
.gap_1()
.child(Avatar::new(author.clone()).picture(picture))
.child(
Avatar::new(issue.pubkey)
.name(author.clone())
.picture(picture),
)
.child(div().child(author)),
)
.child(SharedString::from("opened"))
+14 -10
View File
@@ -12,6 +12,8 @@ pub(crate) mod sidebar;
mod status_list;
pub(crate) mod tree;
use std::fmt::Display;
use gpui::prelude::*;
use gpui::{AnyElement, App, div};
use gpui_component::{Sizable as _, h_flex};
@@ -22,7 +24,7 @@ pub(crate) use repo::{RepoItem, open_repo_item, open_repo_panel};
pub use repo_list::RepoListView;
pub use sidebar::SidebarPanel;
use signed_state::{ProfileStore, RepoStore};
use signed_ui::{Avatar, PixelAvatar};
use signed_ui::Avatar;
pub(crate) fn tab_title(avatar: AnyElement, label: impl IntoElement) -> impl IntoElement {
h_flex()
@@ -32,8 +34,8 @@ pub(crate) fn tab_title(avatar: AnyElement, label: impl IntoElement) -> impl Int
.child(label)
}
pub(crate) fn panel_avatar(seed: impl AsRef<str>) -> AnyElement {
PixelAvatar::new(seed).xsmall().into_any_element()
pub(crate) fn panel_avatar(seed: impl Display) -> AnyElement {
Avatar::new(seed).xsmall().into_any_element()
}
pub(crate) fn repo_tab_avatar(store: &RepoStore, cx: &App) -> AnyElement {
@@ -55,11 +57,13 @@ pub(crate) fn repo_tab_avatar(store: &RepoStore, cx: &App) -> AnyElement {
.as_ref()
.map(|announcement| ProfileStore::global(cx).read(cx).get(&announcement.owner));
match owner.and_then(|profile| profile.picture().map(|picture| (profile.name(), picture))) {
Some((name, picture)) => Avatar::new(name)
.picture(Some(picture))
.xsmall()
.into_any_element(),
None => PixelAvatar::new(seed).xsmall().into_any_element(),
}
let (name, picture) = owner
.map(|profile| (Some(profile.name()), profile.picture()))
.unwrap_or((None, None));
Avatar::new(seed)
.name(name)
.picture(picture)
.xsmall()
.into_any_element()
}
@@ -407,7 +407,7 @@ impl PullRequestDetailView {
return placeholder(&error, cx);
}
let (author, picture, age, root_id) = {
let (author, picture, age, root_id, pubkey) = {
let store = self.store.read(cx);
let Some(root) = store
.pull_requests
@@ -422,6 +422,7 @@ impl PullRequestDetailView {
profile.picture(),
relative_time(root.created_at),
root.id,
root.pubkey,
)
};
@@ -451,7 +452,8 @@ impl PullRequestDetailView {
h_flex()
.gap_1()
.child(
Avatar::new(author.clone())
Avatar::new(pubkey)
.name(author.clone())
.picture(picture),
)
.child(author),
@@ -203,7 +203,11 @@ impl PullRequestsView {
.child(
h_flex()
.gap_1()
.child(Avatar::new(author.clone()).picture(picture))
.child(
Avatar::new(pr.pubkey)
.name(author.clone())
.picture(picture),
)
.child(div().child(author)),
)
.child(SharedString::from("opened"))
+1 -1
View File
@@ -174,7 +174,7 @@ fn maintainers(maintainers: &[PublicKey], cx: &App) -> AnyElement {
.gap_2()
.items_center()
.min_w_0()
.child(Avatar::new(name.clone()).picture(picture))
.child(Avatar::new(*pubkey).name(name.clone()).picture(picture))
.child(
div()
.flex_1()
+13 -6
View File
@@ -30,7 +30,7 @@ use signed_state::{
SyncStatusStore,
};
use signed_ui::{
Avatar, CountBadge, DropdownButton, PixelAvatar, copy_row, menu_copy_row, ref_selector_trigger,
Avatar, CountBadge, DropdownButton, copy_row, menu_copy_row, ref_selector_trigger,
};
use utils::middle_truncate;
@@ -896,7 +896,7 @@ impl RepoDetailView {
let name = repo_display_name(self.store.read(cx));
let description = announcement.description();
let avatar = PixelAvatar::new(format!("{}:{}", announcement.owner, announcement.id));
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
v_flex()
.on_action(
@@ -1253,7 +1253,7 @@ impl RepoDetailView {
.as_ref()
.map(|path| path.display().to_string())
.unwrap_or_default();
let avatar = PixelAvatar::new(path.clone());
let avatar = Avatar::new(path.clone());
// A repository already bound to a coordinate is not offered for publishing again.
let bound = self.store.read(cx).nip34.clone();
@@ -1481,7 +1481,9 @@ impl RepoDetailView {
.child(
h_flex()
.gap_1()
.child(Avatar::new(owner_name.clone()).picture(owner_picture))
.child(Avatar::new(announcement.owner)
.name(owner_name.clone())
.picture(owner_picture))
.child(div().text_xs().whitespace_nowrap().child(owner_name)),
)
.when(!rest.is_empty(), |this| {
@@ -2180,12 +2182,17 @@ fn bound_repo_label(binding: &Nip34Binding, cx: &App) -> AnyElement {
.child("Initialized by")
.text_color(cx.theme().muted_foreground)
.when_some(profile, |this, profile| {
let name = profile.name();
this.child(
h_flex()
.gap_1()
.text_color(cx.theme().foreground)
.child(Avatar::new(profile.name()).picture(profile.picture()))
.child(profile.name()),
.child(
Avatar::new(profile.public_key())
.name(name.clone())
.picture(profile.picture()),
)
.child(name),
)
})
.when_some(binding.identifier.as_deref(), |this, ident| {
+5 -1
View File
@@ -274,7 +274,11 @@ impl RepoListView {
h_flex()
.gap_2()
.items_center()
.child(Avatar::new(owner.name()).picture(owner.picture()))
.child(
Avatar::new(announcement.owner)
.name(owner.name())
.picture(owner.picture()),
)
.child(
div()
.text_xs()
+10 -6
View File
@@ -26,7 +26,7 @@ use signed_state::{
Backend, BackendEvent, CheckoutsStore, LocalReposStore, Nip34Binding, Nip34Kind, Profile,
ProfileStore, RepoListStore, ResolvedLocalRepo, SyncStatusStore,
};
use signed_ui::{Avatar, NavItem, PixelAvatar, title_bar_drag_handlers};
use signed_ui::{Avatar, NavItem, title_bar_drag_handlers};
use super::{InboxView, PlaceholderPanel, RepoDetailView, RepoListView, open_repo_panel};
@@ -510,8 +510,7 @@ impl SidebarPanel {
) -> impl IntoElement {
let name = announcement.name().map(SharedString::from);
// The sidebar rows are compact, so the avatar matches the 16px nav icons.
let avatar =
PixelAvatar::new(format!("{}:{}", announcement.owner, announcement.id)).xsmall();
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id)).xsmall();
let announcement = announcement.clone();
let addr = announcement.addr();
@@ -636,7 +635,11 @@ impl SidebarPanel {
.child(
h_flex()
.gap_1()
.child(Avatar::new(name.clone()).picture(picture))
.child(
Avatar::new(profile.public_key())
.name(name.clone())
.picture(picture),
)
.child(div().text_xs().font_semibold().child(name)),
)
.dropdown_menu(move |menu, _, _| {
@@ -768,7 +771,7 @@ pub(super) fn server_host(relay: &RelayUrl) -> SharedString {
/// The repository's pixel avatar, with the bound owner's avatar at its bottom right.
fn local_avatar(entry: &ResolvedLocalRepo, cx: &App) -> AnyElement {
// Matches the other sidebar rows, and the badge below sits at its corner.
let avatar = PixelAvatar::new(entry.path.to_string_lossy()).xsmall();
let avatar = Avatar::new(entry.path.to_string_lossy()).xsmall();
let Some(owner) = entry.nip34.as_ref().and_then(|binding| binding.owner) else {
return avatar.into_any_element();
@@ -782,7 +785,8 @@ fn local_avatar(entry: &ResolvedLocalRepo, cx: &App) -> AnyElement {
.child(avatar)
.child(
div().absolute().bottom_neg_0p5().right_neg_0p5().child(
Avatar::new(profile.name())
Avatar::new(owner)
.name(profile.name())
.picture(profile.picture())
.size(px(14.)),
),