redesign repo header and drop share menu
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
This commit is contained in:
@@ -10,7 +10,7 @@ use gpui::{
|
||||
use gpui_native_kit::avatar::Avatar;
|
||||
use gpui_native_kit::button::{Button, ButtonVariant};
|
||||
use gpui_native_kit::clipboard::ClipboardButton;
|
||||
use gpui_native_kit::common::{h_flex, v_flex};
|
||||
use gpui_native_kit::common::{Sizable, h_flex, v_flex};
|
||||
use gpui_native_kit::dropdown_menu::DropdownMenu;
|
||||
use gpui_native_kit::icons::{Icon, IconRole};
|
||||
use gpui_native_kit::menu::MenuItem;
|
||||
@@ -108,7 +108,7 @@ impl RepoDetailView {
|
||||
|
||||
pub(super) fn render_about(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
||||
if self.store.read(cx).addr().is_none() {
|
||||
return self.render_local_header(cx);
|
||||
return self.render_init_banner(cx);
|
||||
}
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
@@ -148,7 +148,7 @@ impl RepoDetailView {
|
||||
let git_for_popover = git_commands.clone();
|
||||
|
||||
h_flex()
|
||||
.p_2()
|
||||
.p_6()
|
||||
.w_full()
|
||||
.gap_6()
|
||||
.items_start()
|
||||
@@ -257,7 +257,7 @@ impl RepoDetailView {
|
||||
this.child(button)
|
||||
})
|
||||
.child(
|
||||
Popover::new("clone")
|
||||
Popover::new("code-popover")
|
||||
.open(self.clone_open)
|
||||
.on_change(move |open, _, cx| {
|
||||
if let Err(error) = weak_clone.update(cx, |this, cx| {
|
||||
@@ -268,8 +268,8 @@ impl RepoDetailView {
|
||||
}
|
||||
})
|
||||
.trigger(move |_, _| {
|
||||
Button::new("clone")
|
||||
.label("Clone")
|
||||
Button::new("code")
|
||||
.label("Code")
|
||||
.icon(Icon::named(CustomIconName::GitClone))
|
||||
.tooltip(Tooltip::text("Clone repository"))
|
||||
.loading(cloning)
|
||||
@@ -346,7 +346,14 @@ impl RepoDetailView {
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_local_header(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
fn render_init_banner(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
let binding = self
|
||||
.store
|
||||
.read(cx)
|
||||
.nip34
|
||||
.as_ref()
|
||||
.filter(|binding| binding.kind == Nip34Kind::Initialized);
|
||||
|
||||
let path = self
|
||||
.store
|
||||
.read(cx)
|
||||
@@ -355,60 +362,33 @@ impl RepoDetailView {
|
||||
.map(|path| path.display().to_string())
|
||||
.unwrap_or_default();
|
||||
|
||||
let name = repo_display_name(self.store.read(cx));
|
||||
let avatar = Avatar::new(path.clone());
|
||||
|
||||
let bound = self.store.read(cx).nip34.clone();
|
||||
let action = match bound
|
||||
.as_ref()
|
||||
.filter(|binding| binding.kind == Nip34Kind::Initialized)
|
||||
{
|
||||
Some(binding) => bound_repo_label(binding, &self.directory, cx),
|
||||
None => Button::new("init")
|
||||
v_flex()
|
||||
.flex_none()
|
||||
.p_6()
|
||||
.h_24()
|
||||
.w_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap_2()
|
||||
.map(|this| match binding {
|
||||
Some(binding) => this.child(bound_repo_label(binding, &self.directory, cx)),
|
||||
None => this.child(
|
||||
Button::new("init")
|
||||
.icon(Icon::named(CustomIconName::Init))
|
||||
.large()
|
||||
.label("Initialize on Nostr")
|
||||
.tooltip(Tooltip::text("Publish this repository to Nostr"))
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
this.open_init_dialog(window, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
};
|
||||
|
||||
v_flex()
|
||||
.flex_none()
|
||||
.px_4()
|
||||
.pb_4()
|
||||
.w_full()
|
||||
.gap_6()
|
||||
.border_b_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.child(
|
||||
h_flex()
|
||||
.w_full()
|
||||
.gap_4()
|
||||
.items_start()
|
||||
.justify_between()
|
||||
.child(
|
||||
v_flex()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.gap_1()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.typeset(TextRole::Headline, cx)
|
||||
.child(avatar)
|
||||
.child(name),
|
||||
)
|
||||
})),
|
||||
),
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.typeset(TextRole::Body, cx)
|
||||
.typeset(TextRole::Caption, cx)
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(path),
|
||||
),
|
||||
)
|
||||
.child(action),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
@@ -507,7 +487,7 @@ impl RepoDetailView {
|
||||
|
||||
pub(super) fn render_metadata(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||
h_flex()
|
||||
.px_2()
|
||||
.px_6()
|
||||
.h_12()
|
||||
.w_full()
|
||||
.gap_4()
|
||||
|
||||
@@ -4,24 +4,21 @@ use anyhow::Error;
|
||||
use assets::CustomIconName;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, ClipboardItem, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, SharedString, StatefulInteractiveElement as _, Styled as _, Window, div,
|
||||
px,
|
||||
AnyElement, App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Window, div, px,
|
||||
};
|
||||
use gpui_native_kit::avatar::Avatar;
|
||||
use gpui_native_kit::clipboard::ClipboardButton;
|
||||
use gpui_native_kit::combobox::ComboboxState;
|
||||
use gpui_native_kit::common::{Sizable as _, h_flex, v_flex};
|
||||
use gpui_native_kit::icons::Icon;
|
||||
use gpui_native_kit::menu::MenuItem;
|
||||
use gpui_native_kit::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::nips::nip19::Nip19Coordinate;
|
||||
use nostr::prelude::{RelayUrl, ToBech32};
|
||||
use signed_core::Announcement;
|
||||
use signed_git::{DiffHunk, DiffLine, DiffLineKind, FileCommit, FileDiff, Repo};
|
||||
use signed_state::{Nip34Binding, RepoListStore, RepoStore};
|
||||
use utils::{middle_truncate, relative_time_secs};
|
||||
use utils::relative_time_secs;
|
||||
|
||||
use super::RepoDetailView;
|
||||
use crate::shared::tree::{TreeItemSeed, build_tree_items};
|
||||
@@ -56,67 +53,6 @@ pub(super) struct RepoData {
|
||||
pub(super) head_commit: Option<FileCommit>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct ShareTargets {
|
||||
/// NIP-19 `naddr1...` of the announcement, with its announced relays.
|
||||
pub(super) naddr: String,
|
||||
/// Hex ID of the announcement event itself.
|
||||
event_id: String,
|
||||
/// NIP-34 coordinate `30617:<pubkey>:<repo-id>`.
|
||||
coordinate: String,
|
||||
gitworkshop: String,
|
||||
ditto: String,
|
||||
}
|
||||
|
||||
impl ShareTargets {
|
||||
pub(super) fn from_announcement(announcement: &Announcement) -> Self {
|
||||
let addr = announcement.addr();
|
||||
let coordinate = addr.to_string();
|
||||
let naddr = Nip19Coordinate::new(addr.into(), announcement.relays.iter().cloned())
|
||||
.to_bech32()
|
||||
.unwrap_or_else(|_| coordinate.clone());
|
||||
|
||||
Self {
|
||||
naddr: naddr.clone(),
|
||||
event_id: announcement
|
||||
.event_id
|
||||
.to_bech32()
|
||||
.unwrap_or_else(|_| announcement.event_id.to_string()),
|
||||
coordinate,
|
||||
gitworkshop: format!("https://gitworkshop.dev/{naddr}"),
|
||||
ditto: format!("https://ditto.pub/{naddr}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn menu(&self) -> Vec<MenuItem> {
|
||||
let items = [
|
||||
("GitWorkshop", truncate_naddr_link(&self.gitworkshop, 4)),
|
||||
("Ditto", truncate_naddr_link(&self.ditto, 4)),
|
||||
("Event ID", middle_truncate(&self.event_id, 10, 10)),
|
||||
("Coordinate", middle_truncate(&self.coordinate, 10, 10)),
|
||||
];
|
||||
|
||||
let values = [
|
||||
self.gitworkshop.clone(),
|
||||
self.ditto.clone(),
|
||||
self.event_id.clone(),
|
||||
self.coordinate.clone(),
|
||||
];
|
||||
|
||||
items
|
||||
.into_iter()
|
||||
.zip(values)
|
||||
.map(|((label, detail), value)| {
|
||||
MenuItem::new(SharedString::from(format!("{label} {detail}"))).handler(
|
||||
move |_, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(value.clone()));
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn clone_group(
|
||||
label: &str,
|
||||
id: &'static str,
|
||||
@@ -194,16 +130,6 @@ pub(super) fn fork_row(
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn truncate_naddr_link(url: &str, tail: usize) -> String {
|
||||
let Some(end) = url.find("naddr1").map(|i| i + "naddr1".len()) else {
|
||||
return url.to_string();
|
||||
};
|
||||
if url.len() - end <= tail + 3 {
|
||||
return url.to_string();
|
||||
}
|
||||
format!("{}...{}", &url[..end], &url[url.len() - tail..])
|
||||
}
|
||||
|
||||
pub(super) fn load_repo_data(repo: &Repo) -> Result<RepoData, Error> {
|
||||
let snapshot = repo.snapshot()?;
|
||||
let worktree = repo.workdir().map(Path::to_path_buf);
|
||||
|
||||
@@ -87,7 +87,6 @@ pub struct RepoDetailView {
|
||||
pub(super) directory: Entity<ProfileDirectory>,
|
||||
/// Sync status feeding the sync-to-Nostr banner.
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
pub(super) share_open: bool,
|
||||
pub(super) repo_menu_open: bool,
|
||||
pub(super) clone_open: bool,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
@@ -183,7 +182,6 @@ impl RepoDetailView {
|
||||
tasks: Vec::new(),
|
||||
directory: ProfileDirectory::new(cx),
|
||||
sync_directory: SyncStatusDirectory::new(cx),
|
||||
share_open: false,
|
||||
repo_menu_open: false,
|
||||
clone_open: false,
|
||||
_subscriptions: subscriptions,
|
||||
@@ -884,24 +882,22 @@ impl RepoDetailView {
|
||||
}));
|
||||
})
|
||||
.entries(move |_, cx| {
|
||||
let color = cx.theme().colors.muted_foreground;
|
||||
|
||||
let mut entries = vec![
|
||||
SidebarEntry::row("repo-nav-commits", "Commits")
|
||||
.prefix(Icon::named(CustomIconName::GitCommit).color(color))
|
||||
.when_some(commit_count, |entry, count| entry.detail(count.to_string())),
|
||||
.prefix(Icon::named(CustomIconName::GitCommit))
|
||||
.when_some(commit_count, |entry, count| entry.suffix(count.to_string())),
|
||||
];
|
||||
|
||||
if include_issues {
|
||||
entries.push(
|
||||
SidebarEntry::row("repo-nav-issues", "Issues")
|
||||
.prefix(Icon::named(CustomIconName::GitIssueDone).color(color))
|
||||
.when_some(issue_count, |entry, count| entry.detail(count.to_string())),
|
||||
.prefix(Icon::named(CustomIconName::GitIssueDone))
|
||||
.when_some(issue_count, |entry, count| entry.suffix(count.to_string())),
|
||||
);
|
||||
entries.push(
|
||||
SidebarEntry::row("repo-nav-pulls", "Pull requests")
|
||||
.prefix(Icon::named(CustomIconName::GitPullRequest).color(color))
|
||||
.when_some(pull_count, |entry, count| entry.detail(count.to_string())),
|
||||
.prefix(Icon::named(CustomIconName::GitPullRequest))
|
||||
.when_some(pull_count, |entry, count| entry.suffix(count.to_string())),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user