update nav item
This commit is contained in:
@@ -10,9 +10,8 @@ use dock::{
|
||||
};
|
||||
use gpui::prelude::*;
|
||||
use gpui::{
|
||||
AnyElement, App, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, Hsla, ObjectFit,
|
||||
Render, SharedString, Subscription, WeakEntity, Window, div, img, px, relative, uniform_list,
|
||||
white,
|
||||
AnyElement, App, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, ObjectFit, Render,
|
||||
SharedString, Subscription, WeakEntity, Window, div, img, px, relative, uniform_list, white,
|
||||
};
|
||||
use gpui_base::Button as BaseButton;
|
||||
use gpui_component::button::{Button, ButtonVariants};
|
||||
@@ -37,8 +36,8 @@ mod settings_dialog;
|
||||
|
||||
use self::onboarding_dialog::OnboardingState;
|
||||
|
||||
/// The tool that bound a repository, `"nak"` or `"ngit"`.
|
||||
fn local_tool(binding: &Nip34Binding) -> Option<&'static str> {
|
||||
/// The platform that bound a repository, `"nak"` or `"ngit"`.
|
||||
fn local_platform(binding: &Nip34Binding) -> Option<&'static str> {
|
||||
let signals = &binding.signals;
|
||||
|
||||
if signals.nip34_json || signals.nip34_grasp_remote || signals.nip34_state_refs {
|
||||
@@ -485,34 +484,43 @@ impl SidebarPanel {
|
||||
entry: &ResolvedLocalRepo,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let name = entry
|
||||
.path
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy().into_owned())
|
||||
.unwrap_or("Untitled".into());
|
||||
let avatar = PixelAvatar::new(entry.path.to_string_lossy());
|
||||
|
||||
let suffix: AnyElement = match entry.nip34.as_ref().map(|binding| binding.kind) {
|
||||
Some(Nip34Kind::Initialized) => {
|
||||
let label = match entry.nip34.as_ref().and_then(local_tool) {
|
||||
Some(tool) => format!("NIP-34 · {tool}"),
|
||||
None => "NIP-34".to_owned(),
|
||||
};
|
||||
local_badge(&label, cx.theme().muted_foreground)
|
||||
}
|
||||
Some(Nip34Kind::Cloned) => local_badge("NIP-34 clone", cx.theme().muted_foreground),
|
||||
Some(Nip34Kind::ToolingOnly) => {
|
||||
local_badge("Nostr tooling", cx.theme().muted_foreground)
|
||||
}
|
||||
None => Icon::new(IconName::TriangleAlert)
|
||||
.small()
|
||||
.text_color(cx.theme().warning)
|
||||
.into_any_element(),
|
||||
};
|
||||
let name = entry.name();
|
||||
let avatar = local_avatar(entry, cx);
|
||||
|
||||
let id = format!("local-repo:{}", entry.path.display());
|
||||
let entry = entry.clone();
|
||||
|
||||
let suffix: AnyElement = match entry.nip34.as_ref() {
|
||||
Some(binding) => {
|
||||
let (label, tooltip) = match binding.kind {
|
||||
Nip34Kind::Initialized => {
|
||||
let platform = local_platform(binding).unwrap_or("Grasp");
|
||||
let tooltip = match platform {
|
||||
"nak" => "Initialized with nak",
|
||||
"ngit" => "Initialized with ngit",
|
||||
_ => "Initialized for NIP-34",
|
||||
};
|
||||
(platform, tooltip)
|
||||
}
|
||||
Nip34Kind::Cloned => ("Cloned", "Cloned buts not initialized"),
|
||||
Nip34Kind::ToolingOnly => ("Tooling", "Grasp tooling only"),
|
||||
};
|
||||
|
||||
Button::new(id.clone())
|
||||
.xsmall()
|
||||
.child(div().text_size(px(10.)).child(label))
|
||||
.tooltip(tooltip)
|
||||
.secondary()
|
||||
.into_any_element()
|
||||
}
|
||||
None => Button::new(id.clone())
|
||||
.xsmall()
|
||||
.icon(IconName::TriangleAlert)
|
||||
.tooltip("Not published yet")
|
||||
.ghost()
|
||||
.into_any_element(),
|
||||
};
|
||||
|
||||
NavItem::new(id, name, avatar)
|
||||
.suffix(suffix)
|
||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||
@@ -644,12 +652,27 @@ pub(super) fn server_host(relay: &RelayUrl) -> SharedString {
|
||||
.unwrap_or_else(|| SharedString::from(relay.to_string()))
|
||||
}
|
||||
|
||||
fn local_badge(label: &str, color: Hsla) -> AnyElement {
|
||||
/// The repository's pixel avatar, with the bound owner's avatar at its bottom right.
|
||||
fn local_avatar(entry: &ResolvedLocalRepo, cx: &App) -> AnyElement {
|
||||
let avatar = PixelAvatar::new(entry.path.to_string_lossy());
|
||||
|
||||
let Some(owner) = entry.nip34.as_ref().and_then(|binding| binding.owner) else {
|
||||
return avatar.into_any_element();
|
||||
};
|
||||
|
||||
let store = ProfileStore::global(cx);
|
||||
let profile = store.read(cx).get(&owner);
|
||||
|
||||
div()
|
||||
.flex_shrink_0()
|
||||
.text_xs()
|
||||
.text_color(color)
|
||||
.child(SharedString::from(label.to_owned()))
|
||||
.relative()
|
||||
.child(avatar)
|
||||
.child(
|
||||
div().absolute().bottom_neg_0p5().right_neg_0p5().child(
|
||||
UserAvatar::new(profile.name())
|
||||
.picture(profile.picture())
|
||||
.size(px(14.)),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user