feat: add basic profile panel
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-11-29 15:24:16 +07:00
parent cf81443411
commit 6dfa3a2335
13 changed files with 906 additions and 296 deletions
+10 -1
View File
@@ -60,6 +60,16 @@ impl Profile {
.map(|p| SharedString::from(p.clone()))
}
/// The user's bio, when set and non-empty.
pub fn about(&self) -> Option<SharedString> {
self.metadata
.about
.as_ref()
.map(|about| about.trim().to_owned())
.filter(|about| !about.is_empty())
.map(SharedString::from)
}
/// The newest profile per author from metadata events.
fn latest_profiles(events: impl IntoIterator<Item = Event>) -> Vec<Self> {
let mut latest: HashMap<PublicKey, (Timestamp, Metadata)> = HashMap::new();
@@ -138,7 +148,6 @@ impl ProfileStore {
loop {
let now = Instant::now();
if now >= deadline {
break;
}
+12 -1
View File
@@ -5,7 +5,7 @@ use gpui::{
AnyView, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
};
use nostr::prelude::EventId;
use nostr::prelude::{EventId, PublicKey};
use settings::{AppearanceMode, SettingsStore};
use signed_core::{Announcement, RepoAddr};
use signed_state::{Backend, BackendEvent, RepoStore};
@@ -27,6 +27,7 @@ use crate::identity::passphrase::PassphraseDialog;
use crate::inbox::InboxView;
use crate::issues::IssuesView;
use crate::issues::detail::IssueDetailView;
use crate::profile::ProfileView;
use crate::pull_requests::{PullRequestDetailView, PullRequestsView};
use crate::repo::RepoDetailView;
use crate::shared::log_dropped;
@@ -245,6 +246,16 @@ impl AppRoot {
InboxView::open_panel(&self.panels, cx.weak_entity(), window, cx);
}
/// Opens a user's profile in the main stack, keyed by their public key.
pub(crate) fn open_profile(
&mut self,
public_key: PublicKey,
window: &mut Window,
cx: &mut Context<Self>,
) {
ProfileView::open(&self.panels, cx.weak_entity(), public_key, window, cx);
}
/// Opens the dialog that creates a repository.
fn open_create_repository(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.titlebar.update(cx, |titlebar, cx| {
+1
View File
@@ -3,6 +3,7 @@ mod explore;
mod identity;
mod inbox;
mod issues;
mod profile;
mod pull_requests;
mod repo;
mod settings;
+246
View File
@@ -0,0 +1,246 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce,
SharedString, StatefulInteractiveElement as _, Styled as _, WeakEntity, Window, div, px,
};
use nostr::prelude::{Event, Kind, PublicKey, Timestamp};
use signed_core::{Announcement, Deletions, GitEvent};
use signed_state::RepoListStore;
use ui::common::{StyledExt as _, h_flex, v_flex};
use ui::icons::{Icon, IconRole};
use ui::theme::ActiveTheme as _;
use utils::relative_time;
use crate::app::AppRoot;
use crate::shared::labels::AnnouncementExt as _;
use crate::shared::log_dropped;
/// One announced repository, prepared for its row.
#[derive(Clone)]
pub(super) struct RepositoryItem {
pub(super) announcement: Announcement,
pub(super) name: SharedString,
pub(super) description: Option<SharedString>,
pub(super) activity: Option<SharedString>,
}
/// The repositories `author` announced, with their last activity label.
pub(super) fn repository_items(store: &RepoListStore, author: &PublicKey) -> Vec<RepositoryItem> {
store
.announcements_of(author)
.into_iter()
.map(|announcement| {
let description = announcement
.description
.as_deref()
.map(str::trim)
.filter(|description| !description.is_empty())
.map(SharedString::from);
let activity = store
.last_activity
.get(&announcement.addr())
.copied()
.map(relative_time)
.map(|label| SharedString::from(format!("Updated {label}")));
RepositoryItem {
name: announcement.display_name(),
announcement,
description,
activity,
}
})
.collect()
}
/// One repository card in the profile's repository list.
#[derive(IntoElement)]
pub(super) struct RepositoryRow {
item: RepositoryItem,
workspace: WeakEntity<AppRoot>,
}
impl RepositoryRow {
pub(super) fn new(item: &RepositoryItem, workspace: &WeakEntity<AppRoot>) -> Self {
Self {
item: item.clone(),
workspace: workspace.clone(),
}
}
}
impl RenderOnce for RepositoryRow {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let Self { item, workspace } = self;
let announcement = item.announcement;
v_flex()
.id((
ElementId::from("profile-repo"),
SharedString::from(announcement.event_id.to_hex()),
))
.w_full()
.p_4()
.gap_1()
.rounded(cx.theme().radius.control)
.border_1()
.border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted_hover))
.child(
h_flex()
.w_full()
.items_center()
.gap_3()
.child(
div()
.flex_1()
.min_w_0()
.text_sm()
.font_semibold()
.whitespace_nowrap()
.text_ellipsis()
.child(item.name),
)
.when_some(item.activity, |this, activity| {
this.child(
div()
.flex_shrink_0()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(activity),
)
}),
)
.when_some(item.description, |this, description| {
this.child(
div()
.min_w_0()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.line_clamp(2)
.child(description),
)
})
.on_click(move |_, window, cx| {
let result = workspace.update(cx, |root, cx| {
root.open_repo_panel(&announcement.addr(), Some(&announcement), window, cx);
});
log_dropped(result);
})
}
}
/// One authored activity event, prepared for its row.
#[derive(Clone)]
pub(super) struct ActivityItem {
pub(super) id: SharedString,
pub(super) kind: Kind,
pub(super) subject: SharedString,
pub(super) created_at: Timestamp,
}
/// Keeps `author`'s live git activity, newest first.
pub(super) fn activity_items(
author: PublicKey,
events: impl IntoIterator<Item = Event>,
deletions: &Deletions,
) -> Vec<ActivityItem> {
let mut items: Vec<ActivityItem> = events
.into_iter()
.filter(|event| event.pubkey == author)
.filter(|event| !deletions.is_deleted(event))
.filter(GitEvent::is_git_activity)
.map(|event| ActivityItem {
id: SharedString::from(event.id.to_hex()),
kind: event.kind,
subject: SharedString::from(event.activity_subject()),
created_at: event.created_at,
})
.collect();
items.sort_by_key(|item| std::cmp::Reverse(item.created_at));
items
}
/// One activity line in the profile's activity list.
#[derive(IntoElement)]
pub(super) struct ActivityRow {
item: ActivityItem,
}
impl ActivityRow {
pub(super) fn new(item: ActivityItem) -> Self {
Self { item }
}
}
impl RenderOnce for ActivityRow {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let Self { item } = self;
h_flex()
.id((gpui::ElementId::from("profile-activity"), item.id))
.w_full()
.p_4()
.gap_3()
.items_center()
.rounded(cx.theme().radius.control)
.border_1()
.border_color(cx.theme().colors.border)
.child(
Icon::named(activity_icon(item.kind))
.size(px(12.))
.color(cx.theme().colors.muted_foreground),
)
.child(
v_flex()
.flex_1()
.min_w_0()
.gap_1()
.child(
div()
.text_sm()
.whitespace_nowrap()
.text_ellipsis()
.child(item.subject),
)
.child(
h_flex()
.gap_1()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(activity_phrase(item.kind)))
.child(SharedString::from("·"))
.child(SharedString::from(relative_time(item.created_at))),
),
)
}
}
fn activity_icon(kind: Kind) -> IconRole {
match kind {
Kind::GitIssue | Kind::GitStatusOpen | Kind::GitStatusDraft => IconRole::GitIssueOngoing,
Kind::GitPullRequest | Kind::GitPullRequestUpdate => IconRole::GitPullRequest,
Kind::GitPatch => IconRole::GitCommit,
Kind::Comment => IconRole::Message,
Kind::GitStatusApplied => IconRole::GitIssueDone,
Kind::GitStatusClosed => IconRole::GitIssueClosed,
_ => IconRole::Clock,
}
}
fn activity_phrase(kind: Kind) -> &'static str {
match kind {
Kind::GitIssue => "opened an issue",
Kind::GitPullRequest => "opened a PR",
Kind::GitPullRequestUpdate => "updated a PR",
Kind::GitPatch => "created a patch",
Kind::Comment => "commented",
Kind::GitStatusOpen => "opened a status",
Kind::GitStatusApplied => "applied a status",
Kind::GitStatusClosed => "closed a status",
Kind::GitStatusDraft => "drafted a status",
_ => "did something",
}
}
+274
View File
@@ -0,0 +1,274 @@
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Pixels,
Render, ScrollHandle, SharedString, Styled as _, Subscription, Task, WeakEntity, Window, div,
px,
};
use helpers::{
ActivityItem, ActivityRow, RepositoryItem, RepositoryRow, activity_items, repository_items,
};
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
use signed_core::{Deletions, Filters};
use signed_state::{Backend, BackendEvent, RepoListStore};
use ui::avatar::Avatar;
use ui::common::{Sizable as _, StyledExt as _, v_flex};
use ui::empty_state::EmptyState;
use ui::layout::panel::{Panel, PanelSlot, PanelStack};
use ui::scroll_area::ScrollArea;
use ui::theme::ActiveTheme as _;
use crate::app::AppRoot;
use crate::shared::log_dropped;
mod helpers;
const AVATAR_SIDE: Pixels = px(96.);
/// The centered content width, so the profile does not stretch across a wide window.
const CONTENT_WIDTH: Pixels = px(720.);
/// A user's identity, announced repositories, and recent activity.
pub struct ProfileView {
scroll_handle: ScrollHandle,
public_key: PublicKey,
workspace: WeakEntity<AppRoot>,
directory: Entity<ProfileDirectory>,
store: Entity<RepoListStore>,
repositories: Arc<Vec<RepositoryItem>>,
activities: Arc<Vec<ActivityItem>>,
activity_request: u64,
activity_task: Option<Task<()>>,
_subscriptions: Vec<Subscription>,
}
impl ProfileView {
/// Opens the profile of `public_key` in the main stack, keyed by that key.
pub(crate) fn open(
panels: &Entity<PanelStack>,
workspace: WeakEntity<AppRoot>,
public_key: PublicKey,
window: &mut Window,
cx: &mut App,
) {
let id = SharedString::from(format!("profile:{}", public_key.to_hex()));
panels.update(cx, |panels, cx| {
panels.open(
PanelSlot::Main,
id,
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), public_key, cx)),
window,
cx,
);
});
}
fn new(workspace: WeakEntity<AppRoot>, public_key: PublicKey, cx: &mut Context<Self>) -> Self {
let backend = Backend::global(cx);
let store = RepoListStore::global(cx);
let directory = ProfileDirectory::new(cx);
directory.update(cx, |directory, cx| {
directory.track([public_key], cx);
});
let repositories = Arc::new(repository_items(store.read(cx), &public_key));
let weak = cx.weak_entity();
let mut subscriptions = vec![];
subscriptions.push(cx.observe(&store, |this, _store, cx| {
this.sync_repositories(cx);
}));
subscriptions.push(
cx.subscribe(&backend, |this, _backend, event, cx| match event {
BackendEvent::Synced => {
this.reload_activity(cx);
}
BackendEvent::RepoUpdates(updates)
if updates.iter().any(|n| n.author == this.public_key) =>
{
this.reload_activity(cx);
}
_ => {}
}),
);
backend.update(cx, |backend, cx| {
backend.sync_bootstraps(vec![Filters::authored_activity(public_key)], cx);
});
cx.defer(move |cx| {
log_dropped(weak.update(cx, |this, cx| {
this.reload_activity(cx);
}));
});
Self {
public_key,
workspace,
directory,
store,
repositories,
activities: Arc::new(Vec::new()),
activity_request: 0,
activity_task: None,
scroll_handle: ScrollHandle::new(),
_subscriptions: subscriptions,
}
}
/// Queries the author's local activity, ignoring results a newer query replaced.
fn reload_activity(&mut self, cx: &mut Context<Self>) {
self.activity_request = self.activity_request.wrapping_add(1);
let request = self.activity_request;
let author = self.public_key;
let backend = Backend::global(cx);
let client = backend.read(cx).client();
let work = cx.background_spawn(async move {
let events = client
.database()
.query(Filters::authored_activity(author))
.await?;
let deletion_events = client.database().query(Filters::deletions()).await?;
let deletions = Deletions::from_events(deletion_events);
Ok::<_, anyhow::Error>(activity_items(author, events, &deletions))
});
let task = cx.spawn(async move |this, cx| {
let items = match work.await {
Ok(items) => items,
Err(error) => {
log::warn!("failed to load profile activity: {error}");
return;
}
};
log_dropped(this.update(cx, |this, cx| {
if this.activity_request != request {
return;
}
this.activities = Arc::new(items);
cx.notify();
}));
});
self.activity_task = Some(task);
}
fn sync_repositories(&mut self, cx: &mut Context<Self>) {
let repositories = repository_items(self.store.read(cx), &self.public_key);
self.repositories = Arc::new(repositories);
cx.notify();
}
fn render_identity(&self, cx: &App) -> impl IntoElement {
let profile = self.directory.read(cx).profile(&self.public_key, cx);
let name = profile.name();
let about = profile.about();
v_flex()
.w_full()
.items_center()
.text_center()
.gap_3()
.child(
Avatar::new(self.public_key)
.name(name.clone())
.picture(profile.picture())
.fully_rounded(true)
.size(AVATAR_SIDE),
)
.child(div().text_xl().font_semibold().child(name))
.when_some(about, |this, about| {
this.child(
div()
.max_w(px(480.))
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child(about),
)
})
}
fn render_repositories(&self, _cx: &App) -> impl IntoElement {
v_flex()
.w_full()
.gap_3()
.child(
div()
.w_full()
.text_center()
.text_sm()
.font_semibold()
.child("Repositories"),
)
.when(self.repositories.is_empty(), |this| {
this.child(EmptyState::new("No repositories yet"))
})
.children(
self.repositories
.iter()
.map(|item| RepositoryRow::new(item, &self.workspace)),
)
}
fn render_activity(&self, _cx: &App) -> impl IntoElement {
v_flex()
.w_full()
.gap_3()
.child(
div()
.w_full()
.text_center()
.text_sm()
.font_semibold()
.child("Recent activity"),
)
.when(self.activities.is_empty(), |this| {
this.child(EmptyState::new("No activity yet"))
})
.children(self.activities.iter().cloned().map(ActivityRow::new))
}
}
impl Panel for ProfileView {
fn title(&self, _cx: &App) -> SharedString {
SharedString::from("Profile")
}
fn prefix(&self, cx: &App) -> Option<AnyElement> {
let profile = self.directory.read(cx).profile(&self.public_key, cx);
Some(
Avatar::new(self.public_key)
.name(profile.name())
.picture(profile.picture())
.small()
.into_any_element(),
)
}
}
impl Render for ProfileView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
ScrollArea::new(format!("profile-scroll:{}", self.public_key.to_hex()))
.handle(self.scroll_handle.clone())
.size_full()
.child(
v_flex().w_full().py_12().items_center().child(
v_flex()
.w(CONTENT_WIDTH)
.px_6()
.gap_10()
.child(self.render_identity(cx))
.child(self.render_repositories(cx))
.child(self.render_activity(cx)),
),
)
}
}
+266
View File
@@ -0,0 +1,266 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, Context, Entity, IntoElement, ParentElement as _, Pixels, Render,
ScrollHandle, SharedString, Styled as _, Window, div, px,
};
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
use signed_core::Announcement;
use signed_state::RepoStore;
use ui::avatar::Avatar;
use ui::clipboard::ClipboardButton;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::empty_state::EmptyState;
use ui::layout::panel::Panel;
use ui::scroll_area::ScrollArea;
use ui::theme::ActiveTheme as _;
use utils::middle_truncate;
/// The repository's announcement, shown in the split pane.
pub struct RepoAboutView {
store: Entity<RepoStore>,
directory: Entity<ProfileDirectory>,
scroll_handle: ScrollHandle,
}
impl RepoAboutView {
/// The width the about pane opens at.
pub const WIDTH: Pixels = px(420.);
pub fn new(store: Entity<RepoStore>, directory: Entity<ProfileDirectory>) -> Self {
Self {
store,
directory,
scroll_handle: ScrollHandle::new(),
}
}
fn render_announcement(&self, announcement: &Announcement, cx: &App) -> AnyElement {
let mut rows: Vec<AnyElement> = Vec::new();
rows.push(row(
"Name",
text(
announcement
.name
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from("-")),
),
cx,
));
rows.push(row(
"Description",
text(
announcement
.description
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from("-")),
),
cx,
));
if !announcement.web.is_empty() {
rows.push(row(
"Web",
list(
"about-web",
announcement.web.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if let Some(euc) = &announcement.euc {
rows.push(row(
"Earliest Commit",
copy_value("about-euc", euc.clone(), cx),
cx,
));
}
if let Some(upstream) = &announcement.upstream {
rows.push(row("Upstream", text(upstream.display()), cx));
}
if !announcement.hashtags.is_empty() {
rows.push(row(
"Hashtags",
text(SharedString::from(announcement.hashtags.join(", "))),
cx,
));
}
if !announcement.clone.is_empty() {
rows.push(row(
"Clone URLs",
list(
"about-clone",
announcement.clone.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if !announcement.relays.is_empty() {
rows.push(row(
"Grasp Relays",
list(
"about-relays",
announcement.relays.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if !announcement.maintainers.is_empty() {
rows.push(row(
"Maintainers",
self.maintainers(&announcement.maintainers, cx),
cx,
));
}
v_flex().gap_3().w_full().children(rows).into_any_element()
}
fn maintainers(&self, maintainers: &[PublicKey], cx: &App) -> impl IntoElement {
v_flex()
.gap_2()
.min_w_0()
.children(maintainers.iter().map(|pubkey| {
let profile = self.directory.read(cx).profile(pubkey, cx);
let name = profile.name();
h_flex()
.gap_2()
.items_center()
.min_w_0()
.child(
Avatar::new(*pubkey)
.name(name.clone())
.picture(profile.picture())
.small(),
)
.child(
div()
.flex_1()
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.text_sm()
.child(name),
)
}))
}
}
impl Panel for RepoAboutView {
fn title(&self, _cx: &App) -> SharedString {
SharedString::from("About")
}
fn toolbar(&self, _cx: &App) -> bool {
true
}
}
impl Render for RepoAboutView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let announcement = self.store.read(cx).announcement.as_ref();
ScrollArea::new("repo-about-scroll")
.handle(self.scroll_handle.clone())
.size_full()
.child(
v_flex()
.w_full()
.p_4()
.when_some(announcement, |this, announcement| {
this.child(self.render_announcement(announcement, cx))
})
.when(announcement.is_none(), |this| {
this.child(EmptyState::centered("Repository announcement not found"))
}),
)
}
}
fn row(label: &'static str, value: impl IntoElement, cx: &App) -> AnyElement {
v_flex()
.gap_1()
.min_w_0()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child(label),
)
.child(value)
.into_any_element()
}
fn text<T>(value: T) -> AnyElement
where
T: Into<SharedString>,
{
div()
.text_sm()
.w_full()
.min_w_0()
.child(value.into())
.into_any_element()
}
fn copy_value(id: &'static str, value: String, cx: &App) -> AnyElement {
h_flex()
.gap_2()
.items_center()
.min_w_0()
.child(
div()
.font_family(cx.theme().mono_font)
.text_xs()
.min_w_0()
.child(SharedString::from(value.clone())),
)
.child(ClipboardButton::new(id, value))
.into_any_element()
}
fn list(id: &'static str, items: impl IntoIterator<Item = String>, cx: &App) -> AnyElement {
v_flex()
.gap_2()
.min_w_0()
.children(items.into_iter().enumerate().map(|(ix, item)| {
h_flex()
.h_8()
.px_2()
.gap_2()
.min_w_0()
.bg(cx.theme().colors.secondary)
.rounded(cx.theme().radius.control)
.text_color(cx.theme().colors.secondary_foreground)
.child(
div()
.flex_1()
.min_w_0()
.whitespace_nowrap()
.text_ellipsis()
.text_sm()
.child(SharedString::from(middle_truncate(&item, 28, 16))),
)
.child(ClipboardButton::new(
SharedString::from(format!("{id}-{ix}")),
item,
))
.into_any_element()
}))
.into_any_element()
}
-257
View File
@@ -1,257 +0,0 @@
use std::sync::Arc;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
SharedString, Styled as _, Window, div, px,
};
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
use signed_core::Announcement;
use ui::avatar::Avatar;
use ui::clipboard::ClipboardButton;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::dialog::{Dialog, DialogHandle};
use ui::theme::ActiveTheme as _;
use utils::middle_truncate;
pub struct AboutDialog {
handle: DialogHandle,
announcement: Arc<Announcement>,
directory: Entity<ProfileDirectory>,
}
impl AboutDialog {
pub fn new(
announcement: Arc<Announcement>,
directory: Entity<ProfileDirectory>,
cx: &mut App,
) -> Entity<Self> {
cx.new(|_| Self {
handle: DialogHandle::new(true),
announcement,
directory,
})
}
}
impl Render for AboutDialog {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let announcement = self.announcement.clone();
let directory = self.directory.clone();
Dialog::new("about-dialog")
.handle(self.handle.clone())
.min_width(px(500.))
.title("About")
.content(move |_, cx| announcement_rows(&announcement, &directory, cx))
.into_any_element()
}
}
fn announcement_rows(
announcement: &Announcement,
directory: &Entity<ProfileDirectory>,
cx: &App,
) -> AnyElement {
let mut rows: Vec<AnyElement> = Vec::new();
rows.push(row(
"Name",
text(
announcement
.name
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from("-")),
),
cx,
));
rows.push(row(
"Description",
text(
announcement
.description
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from("-")),
),
cx,
));
if !announcement.web.is_empty() {
rows.push(row(
"Web",
list(
"about-web",
announcement.web.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if let Some(euc) = &announcement.euc {
rows.push(row(
"Earliest Commit",
copy_value("about-euc", euc.clone(), cx),
cx,
));
}
if let Some(upstream) = &announcement.upstream {
rows.push(row("Upstream", text(upstream.display()), cx));
}
if !announcement.hashtags.is_empty() {
rows.push(row(
"Hashtags",
text(SharedString::from(announcement.hashtags.join(", "))),
cx,
));
}
if !announcement.clone.is_empty() {
rows.push(row(
"Clone URLs",
list(
"about-clone",
announcement.clone.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if !announcement.relays.is_empty() {
rows.push(row(
"Grasp Relays",
list(
"about-relays",
announcement.relays.iter().map(|url| url.to_string()),
cx,
),
cx,
));
}
if !announcement.maintainers.is_empty() {
rows.push(row(
"Maintainers",
maintainers(&announcement.maintainers, directory, cx),
cx,
));
}
v_flex().gap_3().w_full().children(rows).into_any_element()
}
fn row(label: &'static str, value: AnyElement, cx: &App) -> AnyElement {
v_flex()
.gap_1()
.min_w_0()
.child(
div()
.text_xs()
.font_medium()
.text_color(cx.theme().colors.muted_foreground)
.child(label),
)
.child(value)
.into_any_element()
}
fn text<T>(value: T) -> AnyElement
where
T: Into<SharedString>,
{
div()
.text_sm()
.w_full()
.min_w_0()
.child(value.into())
.into_any_element()
}
fn copy_value(id: &'static str, value: String, cx: &App) -> AnyElement {
h_flex()
.gap_2()
.items_center()
.min_w_0()
.child(
div()
.font_family(cx.theme().mono_font)
.text_xs()
.min_w_0()
.child(SharedString::from(value.clone())),
)
.child(ClipboardButton::new(id, value))
.into_any_element()
}
fn maintainers(
maintainers: &[PublicKey],
directory: &Entity<ProfileDirectory>,
cx: &App,
) -> AnyElement {
v_flex()
.gap_2()
.min_w_0()
.children(maintainers.iter().map(|pubkey| {
let profile = directory.read(cx).profile(pubkey, cx);
let name = profile.name();
h_flex()
.gap_2()
.items_center()
.min_w_0()
.child(
Avatar::new(*pubkey)
.name(name.clone())
.picture(profile.picture())
.small(),
)
.child(
div()
.flex_1()
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.text_sm()
.child(name),
)
.into_any_element()
}))
.into_any_element()
}
fn list(id: &'static str, items: impl IntoIterator<Item = String>, cx: &App) -> AnyElement {
v_flex()
.gap_2()
.min_w_0()
.children(items.into_iter().enumerate().map(|(ix, item)| {
h_flex()
.h_8()
.px_2()
.gap_2()
.min_w_0()
.bg(cx.theme().colors.secondary)
.rounded(cx.theme().radius.control)
.text_color(cx.theme().colors.secondary_foreground)
.child(
div()
.flex_1()
.min_w_0()
.whitespace_nowrap()
.text_ellipsis()
.text_sm()
.child(SharedString::from(middle_truncate(&item, 28, 16))),
)
.child(ClipboardButton::new(
SharedString::from(format!("{id}-{ix}")),
item,
))
.into_any_element()
}))
.into_any_element()
}
@@ -1,4 +1,3 @@
pub mod about;
pub mod create;
pub mod grasp_servers;
pub mod init;
+44 -10
View File
@@ -26,7 +26,7 @@ use ui::clipboard::CopyRow;
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
use ui::dropdown_menu::DropdownMenu;
use ui::icons::{Icon, IconRole};
use ui::layout::panel::Panel;
use ui::layout::panel::{Panel, SplitSide};
use ui::layout::root::RootContext as _;
use ui::menu::MenuItem;
use ui::popover::Popover;
@@ -35,12 +35,14 @@ use ui::spinner::Spinner;
use ui::theme::ActiveTheme as _;
use ui::tooltip::Tooltip;
mod about;
pub mod dialogs;
pub mod files;
pub mod helpers;
pub mod history;
pub mod refs;
use about::RepoAboutView;
use files::RepoFilesView;
use helpers::{CommitTree, RepoData, clone_group};
use history::RepoHistoryView;
@@ -1379,6 +1381,30 @@ impl RepoDetailView {
AboutModel::sync(&mut self.header, &self.store, nip05.as_deref(), cx);
}
/// Opens the repository's announcement in the split pane.
fn open_about(&mut self, cx: &mut Context<Self>) {
let Some(announcement) = self.store.read(cx).announcement.as_ref() else {
return;
};
let id = SharedString::from(format!("about:{}", announcement.panel_key()));
let store = self.store.clone();
let directory = self.directory.clone();
log_dropped(self.workspace.update(cx, |workspace, cx| {
workspace.panels().clone().update(cx, |panels, cx| {
let view = cx.new(|_| RepoAboutView::new(store, directory));
panels.insert_split_at(
id,
RepoAboutView::WIDTH,
SplitSide::Trailing,
Arc::new(view),
cx,
);
});
}));
}
pub(super) fn render_about(&mut self, cx: &mut Context<Self>) -> AnyElement {
if self.store.read(cx).addr().is_none() {
return self.render_init_banner(cx);
@@ -1557,16 +1583,10 @@ impl RepoDetailView {
let mut items = vec![MenuItem::new("About").handler({
let weak = weak_menu_items.clone();
let announcement = Arc::clone(&announcement_for_menu);
move |_, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
let dialog = dialogs::about::AboutDialog::new(
Arc::clone(&announcement),
this.directory.clone(),
cx,
);
cx.open_dialog(dialog);
this.open_about(cx);
}) {
log::warn!("failed to open about: {error}");
}
@@ -1766,21 +1786,35 @@ impl RepoDetailView {
let owner = self.directory.read(cx).profile(&announcement.owner, cx);
let owner_name = owner.name();
let owner_key = announcement.owner;
h_flex()
.min_w_0()
.gap_2()
.child(
Button::new(format!("repo-owner:{}", owner_key.to_hex()))
.variant(ButtonVariant::Ghost)
.small()
.fully_rounded(false)
.accessibility_label(owner_name.clone())
.on_click(cx.listener(move |this, _, window, cx| {
log_dropped(this.workspace.update(cx, |root, cx| {
root.open_profile(owner_key, window, cx);
}));
}))
.child(
h_flex()
.min_w_0()
.gap_2()
.gap_1p5()
.child(
Avatar::new(announcement.owner)
Avatar::new(owner_key)
.name(owner_name.clone())
.picture(owner.picture())
.fully_rounded(true)
.small(),
)
.child(div().min_w_0().text_xs().truncate().child(owner_name)),
),
)
.when(!rest.is_empty(), |this| {
this.child(
+9
View File
@@ -435,6 +435,7 @@ impl TitlebarView {
let picture = profile.picture();
let public_key = profile.public_key();
let weak = self.weak.clone();
let app = self.app.clone();
Menu::new("user-menu")
.open(self.user_menu_open)
@@ -467,6 +468,14 @@ impl TitlebarView {
})
.items(move |_, _| {
vec![
MenuItem::new("View profile").handler({
let app = app.clone();
move |window, cx| {
log_dropped(app.update(cx, |root, cx| {
root.open_profile(public_key, window, cx);
}));
}
}),
MenuItem::new("Settings").handler({
let weak = weak.clone();
move |_, cx| {
+24 -17
View File
@@ -113,10 +113,9 @@ impl Styled for Avatar {
}
impl RenderOnce for Avatar {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
let size = self.size;
let side = size.avatar_rems() * window.rem_size();
let radius = if self.fully_rounded {
theme.radius.full
@@ -143,7 +142,6 @@ impl RenderOnce for Avatar {
.when(!has_picture, |avatar| {
avatar.child(PixelAvatar {
seed,
side,
radius,
fully_rounded: self.fully_rounded,
})
@@ -155,7 +153,6 @@ impl RenderOnce for Avatar {
#[derive(IntoElement)]
struct PixelAvatar {
seed: u64,
side: Pixels,
radius: Pixels,
fully_rounded: bool,
}
@@ -207,16 +204,11 @@ impl RenderOnce for PixelAvatar {
.to_hsla()
};
let inset = if self.fully_rounded {
self.side / GRID_SIZE as f32
} else {
Pixels::ZERO
};
let fully_rounded = self.fully_rounded;
div()
.flex_none()
.size(self.side)
.p(inset)
.size_full()
.rounded(self.radius)
.bg(Hsla {
a: PIXEL_AVATAR_TINT_ALPHA,
@@ -224,18 +216,33 @@ impl RenderOnce for PixelAvatar {
})
.child(
canvas(
|bounds, _, _| bounds.size,
move |bounds, area, window, _| {
let cell = area.width / GRID_SIZE as f32;
move |bounds, _, _| {
// Rounded avatars keep one empty cell between art and edge.
let inset = if fully_rounded {
bounds.size.width / GRID_SIZE as f32
} else {
Pixels::ZERO
};
Bounds {
origin: bounds.origin + point(inset, inset),
size: size(
bounds.size.width - inset * 2.0,
bounds.size.height - inset * 2.0,
),
}
},
move |_bounds, area, window, _| {
let cell = area.size.width / GRID_SIZE as f32;
for (index, value) in pattern.iter().enumerate() {
if *value == 0 {
continue;
}
let color = if *value == 2 { shade } else { main };
let top_left = bounds.origin
let top_left = area.origin
+ point(
(index % GRID_SIZE) as f32 * cell,
(index / GRID_SIZE) as f32 * cell,
cell * (index % GRID_SIZE) as f32,
cell * (index / GRID_SIZE) as f32,
);
window.paint_quad(fill(
Bounds {
+8 -2
View File
@@ -236,8 +236,13 @@ impl RenderOnce for DropdownMenu {
})
};
let trigger_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
let chevron_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
// Keyed so the panel can anchor to bounds captured by the last paint.
let trigger_bounds: TriggerBoundsCell = window
.use_keyed_state((self.id.clone(), "trigger-bounds"), cx, |_, _| {
Rc::new(RefCell::new(None)) as TriggerBoundsCell
})
.read(cx)
.clone();
let items = if self.open {
self.items
@@ -247,6 +252,7 @@ impl RenderOnce for DropdownMenu {
Rc::from([])
};
let chevron_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
let on_close = Some(on_open.clone());
let spec = MenuPanelSpec {
+5
View File
@@ -295,6 +295,7 @@ impl Theme {
let window_variant = ThemeVariant::from_appearance(window.appearance());
let theme = cx.global::<Theme>();
let engine = cx.global::<ThemeEngine>();
if engine.mode_override.is_none()
&& engine
.preset
@@ -538,9 +539,11 @@ impl ThemeEngine {
let preset = engine.preset.as_ref().map(|(_, def)| def.clone());
let mode_override = engine.mode_override;
let custom = engine.custom.clone();
let variant = mode_override
.or(preset.as_ref().and_then(|def| def.mode()))
.unwrap_or(system_appearance);
(
preset,
mode_override,
@@ -552,8 +555,10 @@ impl ThemeEngine {
let resolved = ResolvedTheme::resolve(&system, preset.as_ref(), mode_override, custom);
cx.set_reduce_motion(resolved.accessibility.reduce_motion);
let theme = Theme::from_resolved(resolved);
let theme_changed = cx.try_global::<Theme>() != Some(&theme);
if theme_changed {
cx.set_global(theme);
cx.refresh_windows();