clean up
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
Rust / build (macos-latest, stable) (pull_request) Canceled after 0s
Rust / build (ubuntu-latest, stable) (pull_request) Canceled after 0s
Rust / build (windows-latest, stable) (pull_request) Canceled after 0s

This commit is contained in:
2026-11-12 10:36:53 +07:00
parent 4a871e417a
commit a27eca45c8
26 changed files with 1566 additions and 1352 deletions
+7 -7
View File
@@ -7,6 +7,13 @@ use signed_state::RepoStore;
use crate::repo::RepoDetailView;
use crate::shared::panels;
/// An item of a repository to open from outside its detail panel.
pub enum RepoItem {
Issue(EventId),
PullRequest(EventId),
Patch,
}
/// Opens a repository as a dock panel, keyed by its address.
pub fn open_repo_panel(
dock: &WeakEntity<DockState>,
@@ -33,13 +40,6 @@ pub fn open_repo_panel(
);
}
/// An item of a repository to open from outside its detail panel.
pub enum RepoItem {
Issue(EventId),
PullRequest(EventId),
Patch,
}
/// Opens an issue or pull request using a store built here.
pub fn open_repo_item(
dock: &WeakEntity<DockState>,
+3 -1
View File
@@ -222,7 +222,9 @@ impl Render for CreateRepoDialog {
.loading(busy)
.disabled(busy)
.on_click(move |_, window, cx| {
let _ = this.update(cx, |this, cx| this.create(window, cx));
crate::shared::log_dropped(
this.update(cx, |this, cx| this.create(window, cx)),
);
})
.into_any_element();
+3 -1
View File
@@ -243,7 +243,9 @@ impl Render for InitRepoDialog {
.loading(busy)
.disabled(busy)
.on_click(move |_, window, cx| {
let _ = this.update(cx, |this, cx| this.init_repository(window, cx));
crate::shared::log_dropped(
this.update(cx, |this, cx| this.init_repository(window, cx)),
);
})
.into_any_element();
+5 -13
View File
@@ -69,8 +69,7 @@ pub struct RepoFilesView {
}
impl RepoFilesView {
pub fn new(cx: &mut Context<Self>) -> Self {
let _ = cx;
pub fn new(_cx: &mut Context<Self>) -> Self {
Self {
seeds: Vec::new(),
expanded: HashSet::new(),
@@ -448,13 +447,7 @@ impl RepoFilesView {
.into_any_element()
}
fn set_code(
&mut self,
path: SharedString,
text: &str,
window: &mut Window,
cx: &mut Context<Self>,
) {
fn set_code(&mut self, path: SharedString, text: &str, cx: &mut Context<Self>) {
let hash = source_hash(text);
let language = code_language(path.as_ref());
@@ -480,7 +473,6 @@ impl RepoFilesView {
}
let state = cx.new(|cx| CodeViewState::new("repo-code", text, language, cx));
let _ = window;
self.code = Some(CodeView {
path,
state,
@@ -514,7 +506,7 @@ impl RepoFilesView {
self.set_markdown(Some(path.into()), &text, cx);
}
} else if self.code.as_ref().map(|code| code.path.as_str()) != Some(path) {
self.set_code(path.into(), &text, window, cx);
self.set_code(path.into(), &text, cx);
}
}
cx.notify();
@@ -574,7 +566,7 @@ impl RepoFilesView {
})
.await;
this.update_in(cx, |this, window, cx| {
this.update_in(cx, |this, _window, cx| {
this.loading_files.remove(&path);
match content {
@@ -590,7 +582,7 @@ impl RepoFilesView {
let same = this.code.as_ref().map(|code| code.path.as_str())
== Some(path.as_str());
if !same {
this.set_code(path.clone().into(), text, window, cx);
this.set_code(path.clone().into(), text, cx);
}
}
this.preview_bytes += text.len();
+667
View File
@@ -0,0 +1,667 @@
use std::collections::HashSet;
use assets::CustomIconName;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, AppContext as _, ClipboardItem, Context, IntoElement, ParentElement as _,
SharedString, Styled as _, Window, div, px,
};
use gpui_native_kit::avatar::Avatar;
use gpui_native_kit::button::{Button, ButtonVariant};
use gpui_native_kit::clipboard::ClipboardButton;
use gpui_native_kit::common::{Sizable as _, h_flex, v_flex};
use gpui_native_kit::data::tabs::{Tab, Tabs};
use gpui_native_kit::dropdown_menu::DropdownMenu;
use gpui_native_kit::icons::{Icon, IconRole};
use gpui_native_kit::menu::MenuItem;
use gpui_native_kit::popover::Popover;
use gpui_native_kit::theme::ActiveTheme as _;
use gpui_native_kit::tooltip::Tooltip;
use signed_state::{Backend, Nip34Kind};
use super::RepoDetailView;
use super::actions;
use super::dialogs;
use super::helpers::{
ShareTargets, bound_repo_label, clone_group, fork_row, nostr_clone_url, repo_display_name,
};
use crate::issues::IssuesView;
use crate::pull_requests::{NewPullRequestView, PullRequestsView, SendPatchView};
impl RepoDetailView {
pub(super) fn open_upstream(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self
.announcement(cx)
.and_then(|announcement| announcement.upstream.as_ref())
.and_then(|upstream| upstream.addr.clone())
else {
return;
};
actions::open_repo_panel(&self.dock, &addr, None, window, cx);
}
/// Open the dialog that publishes the local repository to NIP-34.
fn open_init_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(local_path) = self.store.read(cx).path.clone() else {
return;
};
dialogs::init::open(local_path, cx.entity().downgrade(), window, cx);
}
fn open_pulls(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("pulls:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id,
move |_, cx| {
cx.new(|cx| PullRequestsView::new(dock_for_build.clone(), store.clone(), cx))
},
window,
cx,
);
}
pub(super) fn open_new_pull_request(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("new-pr:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id.clone(),
move |window, cx| {
cx.new(|cx| {
NewPullRequestView::new(
dock_for_build.clone(),
id.clone(),
store.clone(),
window,
cx,
)
})
},
window,
cx,
);
}
fn open_send_patch(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("send-patch:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id.clone(),
move |window, cx| {
cx.new(|cx| {
SendPatchView::new(
dock_for_build.clone(),
id.clone(),
store.clone(),
window,
cx,
)
})
},
window,
cx,
);
}
fn open_issues(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("issues:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id,
move |_, cx| cx.new(|cx| IssuesView::new(dock_for_build.clone(), store.clone(), cx)),
window,
cx,
);
}
pub(super) fn render_header(&mut self, cx: &mut Context<Self>) -> AnyElement {
if self.store.read(cx).addr().is_none() {
return self.render_local_header(cx);
}
let store = self.store.read(cx);
let pushing = store.pushing;
let cloning = store.cloning;
let Some(announcement) = store.announcement.clone() else {
return div().into_any_element();
};
let nip05 = self
.directory
.read(cx)
.profile(&announcement.owner, cx)
.metadata()
.nip05
.clone()
.filter(|nip05| !nip05.trim().is_empty());
let share = ShareTargets::from_announcement(&announcement);
let nostr_url = nostr_clone_url(&announcement, nip05.as_deref());
let ngit_command = SharedString::from(format!("git clone {nostr_url}"));
let nak_command = SharedString::from(format!("nak git clone {nostr_url}"));
let git_commands: Vec<String> = announcement.clone_urls();
let name = repo_display_name(self.store.read(cx));
let description = announcement.description();
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
let share_naddr = share.naddr.clone();
let share_for_menu = share.clone();
let announcement_for_menu = announcement.clone();
let weak_share = cx.entity().downgrade();
let weak_menu_open = cx.entity().downgrade();
let weak_menu_items = cx.entity().downgrade();
let weak_clone = cx.entity().downgrade();
let weak_download = cx.entity().downgrade();
let ngit_for_popover = ngit_command.clone();
let nak_for_popover = nak_command.clone();
let git_for_popover = git_commands.clone();
v_flex()
.flex_none()
.p_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()
.font_weight(gpui::FontWeight::SEMIBOLD)
.child(avatar)
.child(name),
)
.child(
div()
.min_w_0()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.line_clamp(2)
.child(description),
)
.when_some(fork_row(&announcement, cx), |this, row| this.child(row))
.child(
h_flex()
.mt_2()
.w_full()
.gap_1()
.child(
div()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.font_weight(gpui::FontWeight::SEMIBOLD)
.child("Maintainers:"),
)
.child(self.render_maintainers(cx)),
),
)
.child(
h_flex()
.flex_none()
.gap_2()
.justify_end()
.child({
let weak_pulls = cx.entity().downgrade();
let weak_pulls_open = cx.entity().downgrade();
let _store_for_pulls = self.store.clone();
let pulls_count = self.store.read(cx).pull_request_count();
DropdownMenu::new("pulls")
.label(format!("Pull requests {pulls_count}"))
.icon(Icon::named(CustomIconName::GitPullRequest))
.variant(ButtonVariant::Secondary)
.open(self.pulls_menu_open)
.on_click(move |_, window, cx| {
if let Err(error) = weak_pulls.update(cx, |this, cx| {
this.open_pulls(window, cx);
}) {
log::warn!("failed to open pull requests: {error}");
}
})
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_pulls_open.update(cx, |this, cx| {
this.pulls_menu_open = open;
cx.notify();
}) {
log::warn!("failed to update pulls menu: {error}");
}
})
.items({
let weak_new = cx.entity().downgrade();
let weak_patch = cx.entity().downgrade();
move |_, _| {
let weak_new = weak_new.clone();
let weak_patch = weak_patch.clone();
vec![
MenuItem::new("New pull request").handler(move |window, cx| {
crate::shared::log_dropped(weak_new.update(cx, |this, cx| {
this.open_new_pull_request(window, cx);
}));
}),
MenuItem::new("Send patch").handler(move |window, cx| {
crate::shared::log_dropped(weak_patch.update(cx, |this, cx| {
this.open_send_patch(window, cx);
}));
}),
]
}
})
})
.child({
let weak_issues = cx.entity().downgrade();
let weak_issues_open = cx.entity().downgrade();
let store_for_issues = self.store.clone();
let issues_count = self.store.read(cx).issue_count();
DropdownMenu::new("issues")
.label(format!("Issues {issues_count}"))
.icon(Icon::named(CustomIconName::GitIssueDone))
.variant(ButtonVariant::Secondary)
.open(self.issues_menu_open)
.on_click(move |_, window, cx| {
if let Err(error) = weak_issues.update(cx, |this, cx| {
this.open_issues(window, cx);
}) {
log::warn!("failed to open issues: {error}");
}
})
.on_open_change(move |open, _, cx| {
if let Err(error) =
weak_issues_open.update(cx, |this, cx| {
this.issues_menu_open = open;
cx.notify();
})
{
log::warn!("failed to update issues menu: {error}");
}
})
.items(move |_, _| {
vec![MenuItem::new("New issue").handler({
let store = store_for_issues.clone();
move |_, cx| {
crate::issues::new_issue::open(store.clone(), cx);
}
})]
})
})
.child(
DropdownMenu::new("share")
.icon(Icon::named(IconRole::Copy))
.variant(ButtonVariant::Secondary)
.open(self.share_open)
.on_click(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(
share_naddr.clone(),
));
})
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_share.update(cx, |this, cx| {
this.share_open = open;
cx.notify();
}) {
log::warn!("failed to update share menu: {error}");
}
})
.items(move |_, _| share_for_menu.menu()),
)
.child(
DropdownMenu::new("repo-menu")
.icon(Icon::named(CustomIconName::EllipsisVertical))
.variant(ButtonVariant::Secondary)
.loading(pushing)
.disabled(pushing)
.open(self.repo_menu_open)
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_menu_open.update(cx, |this, cx| {
this.repo_menu_open = open;
cx.notify();
}) {
log::warn!("failed to update repo menu: {error}");
}
})
.items(move |_, cx| {
let owner = Backend::global(cx)
.read(cx)
.current_user()
== Some(announcement_for_menu.owner);
let mut items = vec![MenuItem::new("About").handler({
let weak = weak_menu_items.clone();
let announcement = announcement_for_menu.clone();
move |_, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
dialogs::about::open(
announcement.clone(),
this.directory.clone(),
cx,
);
}) {
log::warn!("failed to open about: {error}");
}
}
})];
if owner {
items.push(MenuItem::new("Republish").handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.push_repository(window, cx);
}) {
log::warn!("failed to republish: {error}");
}
}
}));
items.push(MenuItem::new("Reset remote to local").handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.reset_remote(window, cx);
}) {
log::warn!("failed to reset remote: {error}");
}
}
}));
items.push(MenuItem::separator());
items.push(
MenuItem::new("Delete")
.destructive(true)
.handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) =
weak.update(cx, |this, cx| {
this.delete_repository(window, cx);
})
{
log::warn!(
"failed to delete repository: {error}"
);
}
}
}),
);
}
items
}),
)
.child(
Popover::new("clone")
.open(self.clone_open)
.on_change(move |open, _, cx| {
if let Err(error) = weak_clone.update(cx, |this, cx| {
this.clone_open = open;
cx.notify();
}) {
log::warn!("failed to update clone popover: {error}");
}
})
.trigger(move |_, _| {
Button::new("clone")
.icon(Icon::named(CustomIconName::GitClone))
.tooltip(Tooltip::text("Clone"))
.loading(cloning)
.disabled(cloning)
.into_any_element()
})
.content(move |_, cx| {
v_flex()
.w(px(440.))
.p_3()
.gap_4()
.child(clone_group(
"Clone with ngit",
"copy-ngit",
&ngit_for_popover,
))
.child(clone_group(
"Clone with nak",
"copy-nak",
&nak_for_popover,
))
.child(
v_flex()
.gap_1()
.child(
div()
.text_xs()
.text_color(
cx.theme().colors.muted_foreground,
)
.child("Grasp Servers"),
)
.when(git_for_popover.is_empty(), |this| {
this.child(
div()
.text_xs()
.child("No git clone urls."),
)
})
.children(git_for_popover.iter().enumerate().map(
|(ix, command)| {
ClipboardButton::new(
SharedString::from(format!(
"copy-git-{ix}"
)),
command.clone(),
)
},
)),
)
.child(
h_flex().justify_end().child(
Button::new("download")
.icon(Icon::named(CustomIconName::GitClone))
.label("Download")
.on_click({
let weak = weak_download.clone();
move |_, window, cx| {
if let Err(error) =
weak.update(cx, |this, cx| {
this.clone_to_folder(window, cx);
})
{
log::warn!(
"failed to clone: {error}"
);
}
}
}),
),
)
.into_any_element()
}),
),
),
)
.child(self.render_tabs(cx))
.into_any_element()
}
fn render_local_header(&self, cx: &mut Context<Self>) -> AnyElement {
let name = repo_display_name(self.store.read(cx));
let path = self
.store
.read(cx)
.path
.as_ref()
.map(|path| path.display().to_string())
.unwrap_or_default();
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")
.icon(Icon::named(CustomIconName::Init))
.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()
.font_weight(gpui::FontWeight::SEMIBOLD)
.child(avatar)
.child(name),
)
.child(
div()
.min_w_0()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child(path),
),
)
.child(action),
)
.child(self.render_tabs(cx))
.into_any_element()
}
fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement {
let count = self.history.read(cx).commit_count();
let muted = cx.theme().colors.muted_foreground;
let weak = cx.entity().downgrade();
let commits_label = match count {
Some(count) => SharedString::from(format!("Commits ({count})")),
None => SharedString::from("Commits"),
};
Tabs::new("repo-tabs")
.selected(self.active_tab)
.tabs(move |_, _| {
vec![
Tab::new("files", "Files")
.lead(Icon::named(CustomIconName::GitFile).color(muted)),
Tab::new("commits", commits_label.clone())
.lead(Icon::named(CustomIconName::GitCommit).color(muted)),
]
})
.on_change(move |index, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.active_tab = index;
cx.notify();
}) {
log::warn!("failed to switch repo tab: {error}");
}
})
.into_any_element()
}
fn render_maintainers(&self, cx: &mut Context<Self>) -> AnyElement {
let Some(announcement) = self.announcement(cx) else {
return div().into_any_element();
};
let mut seen = HashSet::new();
let rest: Vec<_> = announcement
.maintainers
.iter()
.copied()
.filter(|key| key != &announcement.owner && seen.insert(*key))
.collect();
let owner = self.directory.read(cx).profile(&announcement.owner, cx);
let owner_name = owner.name();
h_flex()
.w_full()
.gap_3()
.child(
h_flex()
.gap_2()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(announcement.owner)
.name(owner_name.clone())
.picture(owner.picture())
.small(),
)
.child(div().text_xs().whitespace_nowrap().child(owner_name)),
)
.when(!rest.is_empty(), |this| {
this.child(
div()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(format!("+{}", rest.len()))),
)
}),
)
.into_any_element()
}
}
+79 -79
View File
@@ -26,6 +26,24 @@ use utils::{middle_truncate, relative_time_secs};
use super::RepoDetailView;
use crate::shared::tree::{TreeItemSeed, build_tree_items};
const GUTTER_WIDTH: f32 = 44.;
pub const DIFF_ROW_HEIGHT: f32 = 20.;
pub const COMMIT_ROW_HEIGHT: f32 = 56.;
#[derive(Clone, Copy)]
pub(super) enum DiffRow {
Hunk {
old_start: u32,
old_lines: u32,
new_start: u32,
new_lines: u32,
},
Line {
hunk: usize,
line: usize,
},
}
pub(super) struct RepoData {
pub(super) tree: Vec<TreeItemSeed>,
pub(super) entries: Vec<PathBuf>,
@@ -38,6 +56,67 @@ 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, command: &SharedString) -> AnyElement {
v_flex()
.gap_1()
@@ -106,67 +185,6 @@ pub(super) fn fork_row(
})
}
#[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 truncate_naddr_link(url: &str, tail: usize) -> String {
let Some(end) = url.find("naddr1").map(|i| i + "naddr1".len()) else {
return url.to_string();
@@ -314,24 +332,6 @@ pub(super) fn is_markdown_path(path: &str) -> bool {
})
}
const GUTTER_WIDTH: f32 = 44.;
pub const DIFF_ROW_HEIGHT: f32 = 20.;
pub const COMMIT_ROW_HEIGHT: f32 = 56.;
#[derive(Clone, Copy)]
pub(super) enum DiffRow {
Hunk {
old_start: u32,
old_lines: u32,
new_start: u32,
new_lines: u32,
},
Line {
hunk: usize,
line: usize,
},
}
pub(super) fn diff_rows(file: &FileDiff) -> Vec<DiffRow> {
let mut rows = Vec::new();
for (hunk_ix, hunk) in file.hunks.iter().enumerate() {
+98 -657
View File
@@ -5,32 +5,25 @@ use anyhow::Error;
use assets::CustomIconName;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, ClipboardItem, Context, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _,
Subscription, Task, WeakEntity, Window, div, px,
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _, Subscription, Task,
WeakEntity, Window, div, px,
};
use gpui_native_kit::alert::{Alert, AlertSeverity};
use gpui_native_kit::avatar::Avatar;
use gpui_native_kit::badge::Badge;
use gpui_native_kit::button::{Button, ButtonVariant};
use gpui_native_kit::clipboard::ClipboardButton;
use gpui_native_kit::common::{Sizable as _, h_flex, v_flex};
use gpui_native_kit::data::tabs::{Tab, Tabs};
use gpui_native_kit::dropdown_menu::DropdownMenu;
use gpui_native_kit::icons::{Icon, IconRole};
use gpui_native_kit::layout::dock::{DockState, Panel};
use gpui_native_kit::menu::MenuItem;
use gpui_native_kit::popover::Popover;
use gpui_native_kit::spinner::Spinner;
use gpui_native_kit::theme::ActiveTheme as _;
use gpui_native_kit::tooltip::Tooltip;
use metadata::ProfileDirectory;
use nostr::prelude::{PublicKey, Url};
use signed_core::{Announcement, RepoAddr};
use signed_git::{FileCommit, GitCache, Repo};
use signed_state::{
Backend, CheckoutStatus, CheckoutSyncStatus, CheckoutsStore, LocalReposStore, Mirrors,
Nip34Binding, Nip34Kind, PushStepStatus, RepoStore, SyncStatusDirectory,
Nip34Binding, PushStepStatus, RepoStore, SyncStatusDirectory,
};
pub mod actions;
@@ -38,21 +31,17 @@ pub mod banners;
pub mod commit_diff;
pub mod dialogs;
pub mod files;
mod header;
pub mod helpers;
pub mod history;
pub mod refs;
use banners::Banners;
use files::RepoFilesView;
use helpers::{
RepoData, ShareTargets, bound_repo_label, clone_group, fork_row, load_repo_data,
nostr_clone_url, repo_display_name,
};
use helpers::{RepoData, load_repo_data, repo_display_name};
use history::RepoHistoryView;
use refs::RefSwitcher;
use crate::issues::IssuesView;
use crate::pull_requests::{NewPullRequestView, PullRequestsView, SendPatchView};
use crate::shared::tree::{build_tree_items, sorted_worktree_paths};
use crate::shared::widgets::repo_tab_avatar;
@@ -65,16 +54,16 @@ pub enum RefKind {
}
pub struct RepoDetailView {
dock: WeakEntity<DockState>,
store: Entity<RepoStore>,
pub(super) dock: WeakEntity<DockState>,
pub(super) store: Entity<RepoStore>,
/// A repository opened by address alone starts without an announcement.
repo_started: bool,
/// The Files tab, which owns the explorer, previews and the per-file commit map.
files: Entity<RepoFilesView>,
/// The Commits tab, which walks HEAD and opens commit diffs.
history: Entity<RepoHistoryView>,
pub(super) history: Entity<RepoHistoryView>,
/// The active tab: Files or Commits.
active_tab: usize,
pub(super) active_tab: usize,
/// The checked-out worktree path.
worktree: Option<PathBuf>,
loading: bool,
@@ -84,14 +73,14 @@ pub struct RepoDetailView {
banners: Banners,
tasks: Vec<Task<Result<(), Error>>>,
/// Profiles rendered by the header and maintainers.
directory: Entity<ProfileDirectory>,
pub(super) directory: Entity<ProfileDirectory>,
/// Sync status feeding the sync-to-Nostr banner.
sync_directory: Entity<SyncStatusDirectory>,
share_open: bool,
repo_menu_open: bool,
clone_open: bool,
issues_menu_open: bool,
pulls_menu_open: bool,
pub(super) share_open: bool,
pub(super) repo_menu_open: bool,
pub(super) clone_open: bool,
pub(super) issues_menu_open: bool,
pub(super) pulls_menu_open: bool,
_subscriptions: Vec<Subscription>,
}
@@ -151,10 +140,10 @@ impl RepoDetailView {
let store_for_attach = store.clone();
window.defer(cx, move |window, cx| {
let _ = weak.update(cx, |this, cx| {
crate::shared::log_dropped(weak.update(cx, |this, cx| {
this.attach_store(&store_for_attach, window, cx);
this.load_repo(window, cx);
});
}));
});
Self {
@@ -406,8 +395,16 @@ impl RepoDetailView {
return Ok::<_, Error>(None);
};
repo.fetch().ok();
let moved = repo.fast_forward_branches().unwrap_or(false);
if let Err(error) = repo.fetch() {
log::debug!("best-effort fetch failed: {error}");
}
let moved = match repo.fast_forward_branches() {
Ok(moved) => moved,
Err(error) => {
log::warn!("failed to fast-forward branches: {error}");
false
}
};
Ok::<_, Error>(Some((moved, repo.snapshot()?)))
})
.await
@@ -811,640 +808,83 @@ impl RepoDetailView {
}
/// Open the upstream repository, the `u` tag of this fork's announcement.
pub(super) fn open_upstream(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self
.announcement(cx)
.and_then(|announcement| announcement.upstream.as_ref())
.and_then(|upstream| upstream.addr.clone())
else {
return;
};
fn ready_suggestion(&self, cx: &App) -> Option<CheckoutStatus> {
let store = self.store.read(cx);
let addr = store.addr()?;
let user = Backend::global(cx).read(cx).current_user()?;
actions::open_repo_panel(&self.dock, &addr, None, window, cx);
}
/// Open the dialog that publishes the local repository to NIP-34.
fn open_init_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(local_path) = self.store.read(cx).path.clone() else {
return;
};
dialogs::init::open(local_path, cx.entity().downgrade(), window, cx);
}
fn open_pulls(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("pulls:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id,
move |_, cx| {
cx.new(|cx| PullRequestsView::new(dock_for_build.clone(), store.clone(), cx))
},
window,
cx,
);
}
fn open_new_pull_request(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("new-pr:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id.clone(),
move |window, cx| {
cx.new(|cx| {
NewPullRequestView::new(
dock_for_build.clone(),
id.clone(),
store.clone(),
window,
cx,
)
})
},
window,
cx,
);
}
fn open_send_patch(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("send-patch:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id.clone(),
move |window, cx| {
cx.new(|cx| {
SendPatchView::new(
dock_for_build.clone(),
id.clone(),
store.clone(),
window,
cx,
)
})
},
window,
cx,
);
}
fn open_issues(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
let id = SharedString::from(format!("issues:{addr}"));
let dock = self.dock.clone();
let dock_for_build = dock.clone();
let store = self.store.clone();
crate::shared::panels::open(
&dock,
id,
move |_, cx| cx.new(|cx| IssuesView::new(dock_for_build.clone(), store.clone(), cx)),
window,
cx,
);
}
fn render_header(&mut self, cx: &mut Context<Self>) -> AnyElement {
if self.store.read(cx).addr().is_none() {
return self.render_local_header(cx);
if store.is_author(&user) {
return None;
}
let store = self.store.read(cx);
let pushing = store.pushing;
let cloning = store.cloning;
let Some(announcement) = store.announcement.clone() else {
return div().into_any_element();
};
let nip05 = self
.directory
.read(cx)
.profile(&announcement.owner, cx)
.metadata()
.nip05
.clone()
.filter(|nip05| !nip05.trim().is_empty());
let share = ShareTargets::from_announcement(&announcement);
let nostr_url = nostr_clone_url(&announcement, nip05.as_deref());
let ngit_command = SharedString::from(format!("git clone {nostr_url}"));
let nak_command = SharedString::from(format!("nak git clone {nostr_url}"));
let git_commands: Vec<String> = announcement.clone_urls();
let name = repo_display_name(self.store.read(cx));
let description = announcement.description();
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
let share_naddr = share.naddr.clone();
let share_for_menu = share.clone();
let announcement_for_menu = announcement.clone();
let weak_share = cx.entity().downgrade();
let weak_menu_open = cx.entity().downgrade();
let weak_menu_items = cx.entity().downgrade();
let weak_clone = cx.entity().downgrade();
let weak_download = cx.entity().downgrade();
let ngit_for_popover = ngit_command.clone();
let nak_for_popover = nak_command.clone();
let git_for_popover = git_commands.clone();
v_flex()
.flex_none()
.p_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()
.font_weight(gpui::FontWeight::SEMIBOLD)
.child(avatar)
.child(name),
)
.child(
div()
.min_w_0()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.line_clamp(2)
.child(description),
)
.when_some(fork_row(&announcement, cx), |this, row| this.child(row))
.child(
h_flex()
.mt_2()
.w_full()
.gap_1()
.child(
div()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.font_weight(gpui::FontWeight::SEMIBOLD)
.child("Maintainers:"),
)
.child(self.render_maintainers(cx)),
),
)
.child(
h_flex()
.flex_none()
.gap_2()
.justify_end()
.child({
let weak_pulls = cx.entity().downgrade();
let weak_pulls_open = cx.entity().downgrade();
let _store_for_pulls = self.store.clone();
let pulls_count = self.store.read(cx).pull_request_count();
DropdownMenu::new("pulls")
.label(format!("Pull requests {pulls_count}"))
.icon(Icon::named(CustomIconName::GitPullRequest))
.variant(ButtonVariant::Secondary)
.open(self.pulls_menu_open)
.on_click(move |_, window, cx| {
if let Err(error) = weak_pulls.update(cx, |this, cx| {
this.open_pulls(window, cx);
}) {
log::warn!("failed to open pull requests: {error}");
}
})
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_pulls_open.update(cx, |this, cx| {
this.pulls_menu_open = open;
cx.notify();
}) {
log::warn!("failed to update pulls menu: {error}");
}
})
.items({
let weak_new = cx.entity().downgrade();
let weak_patch = cx.entity().downgrade();
move |_, _| {
let weak_new = weak_new.clone();
let weak_patch = weak_patch.clone();
vec![
MenuItem::new("New pull request").handler(move |window, cx| {
let _ = weak_new.update(cx, |this, cx| {
this.open_new_pull_request(window, cx);
});
}),
MenuItem::new("Send patch").handler(move |window, cx| {
let _ = weak_patch.update(cx, |this, cx| {
this.open_send_patch(window, cx);
});
}),
]
}
})
})
.child({
let weak_issues = cx.entity().downgrade();
let weak_issues_open = cx.entity().downgrade();
let store_for_issues = self.store.clone();
let issues_count = self.store.read(cx).issue_count();
DropdownMenu::new("issues")
.label(format!("Issues {issues_count}"))
.icon(Icon::named(CustomIconName::GitIssueDone))
.variant(ButtonVariant::Secondary)
.open(self.issues_menu_open)
.on_click(move |_, window, cx| {
if let Err(error) = weak_issues.update(cx, |this, cx| {
this.open_issues(window, cx);
}) {
log::warn!("failed to open issues: {error}");
}
})
.on_open_change(move |open, _, cx| {
if let Err(error) =
weak_issues_open.update(cx, |this, cx| {
this.issues_menu_open = open;
cx.notify();
})
{
log::warn!("failed to update issues menu: {error}");
}
})
.items(move |_, _| {
vec![MenuItem::new("New issue").handler({
let store = store_for_issues.clone();
move |_, cx| {
crate::issues::new_issue::open(store.clone(), cx);
}
})]
})
})
.child(
DropdownMenu::new("share")
.icon(Icon::named(IconRole::Copy))
.variant(ButtonVariant::Secondary)
.open(self.share_open)
.on_click(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(
share_naddr.clone(),
));
})
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_share.update(cx, |this, cx| {
this.share_open = open;
cx.notify();
}) {
log::warn!("failed to update share menu: {error}");
}
})
.items(move |_, _| share_for_menu.menu()),
)
.child(
DropdownMenu::new("repo-menu")
.icon(Icon::named(CustomIconName::EllipsisVertical))
.variant(ButtonVariant::Secondary)
.loading(pushing)
.disabled(pushing)
.open(self.repo_menu_open)
.on_open_change(move |open, _, cx| {
if let Err(error) = weak_menu_open.update(cx, |this, cx| {
this.repo_menu_open = open;
cx.notify();
}) {
log::warn!("failed to update repo menu: {error}");
}
})
.items(move |_, cx| {
let owner = Backend::global(cx)
.read(cx)
.current_user()
== Some(announcement_for_menu.owner);
let mut items = vec![MenuItem::new("About").handler({
let weak = weak_menu_items.clone();
let announcement = announcement_for_menu.clone();
move |_, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
dialogs::about::open(
announcement.clone(),
this.directory.clone(),
cx,
);
}) {
log::warn!("failed to open about: {error}");
}
}
})];
if owner {
items.push(MenuItem::new("Republish").handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.push_repository(window, cx);
}) {
log::warn!("failed to republish: {error}");
}
}
}));
items.push(MenuItem::new("Reset remote to local").handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.reset_remote(window, cx);
}) {
log::warn!("failed to reset remote: {error}");
}
}
}));
items.push(MenuItem::separator());
items.push(
MenuItem::new("Delete")
.destructive(true)
.handler({
let weak = weak_menu_items.clone();
move |window, cx| {
if let Err(error) =
weak.update(cx, |this, cx| {
this.delete_repository(window, cx);
})
{
log::warn!(
"failed to delete repository: {error}"
);
}
}
}),
);
}
items
}),
)
.child(
Popover::new("clone")
.open(self.clone_open)
.on_change(move |open, _, cx| {
if let Err(error) = weak_clone.update(cx, |this, cx| {
this.clone_open = open;
cx.notify();
}) {
log::warn!("failed to update clone popover: {error}");
}
})
.trigger(move |_, _| {
Button::new("clone")
.icon(Icon::named(CustomIconName::GitClone))
.tooltip(Tooltip::text("Clone"))
.loading(cloning)
.disabled(cloning)
.into_any_element()
})
.content(move |_, cx| {
v_flex()
.w(px(440.))
.p_3()
.gap_4()
.child(clone_group(
"Clone with ngit",
"copy-ngit",
&ngit_for_popover,
))
.child(clone_group(
"Clone with nak",
"copy-nak",
&nak_for_popover,
))
.child(
v_flex()
.gap_1()
.child(
div()
.text_xs()
.text_color(
cx.theme().colors.muted_foreground,
)
.child("Grasp Servers"),
)
.when(git_for_popover.is_empty(), |this| {
this.child(
div()
.text_xs()
.child("No git clone urls."),
)
})
.children(git_for_popover.iter().enumerate().map(
|(ix, command)| {
ClipboardButton::new(
SharedString::from(format!(
"copy-git-{ix}"
)),
command.clone(),
)
},
)),
)
.child(
h_flex().justify_end().child(
Button::new("download")
.icon(Icon::named(CustomIconName::GitClone))
.label("Download")
.on_click({
let weak = weak_download.clone();
move |_, window, cx| {
if let Err(error) =
weak.update(cx, |this, cx| {
this.clone_to_folder(window, cx);
})
{
log::warn!(
"failed to clone: {error}"
);
}
}
}),
),
)
.into_any_element()
}),
),
),
)
.child(self.render_tabs(cx))
.into_any_element()
}
fn render_local_header(&self, cx: &mut Context<Self>) -> AnyElement {
let name = repo_display_name(self.store.read(cx));
let path = self
.store
.read(cx)
.path
.as_ref()
.map(|path| path.display().to_string())
.unwrap_or_default();
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")
.icon(Icon::named(CustomIconName::Init))
.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()
.font_weight(gpui::FontWeight::SEMIBOLD)
.child(avatar)
.child(name),
)
.child(
div()
.min_w_0()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child(path),
),
)
.child(action),
)
.child(self.render_tabs(cx))
.into_any_element()
}
fn render_tabs(&self, cx: &mut Context<Self>) -> AnyElement {
let count = self.history.read(cx).commit_count();
let muted = cx.theme().colors.muted_foreground;
let weak = cx.entity().downgrade();
let commits_label = match count {
Some(count) => SharedString::from(format!("Commits ({count})")),
None => SharedString::from("Commits"),
};
Tabs::new("repo-tabs")
.selected(self.active_tab)
.tabs(move |_, _| {
vec![
Tab::new("files", "Files")
.lead(Icon::named(CustomIconName::GitFile).color(muted)),
Tab::new("commits", commits_label.clone())
.lead(Icon::named(CustomIconName::GitCommit).color(muted)),
]
})
.on_change(move |index, _, cx| {
if let Err(error) = weak.update(cx, |this, cx| {
this.active_tab = index;
cx.notify();
}) {
log::warn!("failed to switch repo tab: {error}");
let statuses = CheckoutsStore::global(cx).read(cx).ready_statuses_of(addr);
'status: for status in statuses {
if self.banners.dismissal(&status) {
continue;
}
for pr in &store.pull_requests {
if CheckoutsStore::pr_proposes_checkout(
pr,
store.status_of(pr) == signed_core::RepoStatus::Open,
user,
&status,
) {
continue 'status;
}
})
.into_any_element()
}
return Some(status);
}
None
}
fn render_maintainers(&self, cx: &mut Context<Self>) -> AnyElement {
let Some(announcement) = self.announcement(cx) else {
return div().into_any_element();
fn render_ready_banner(&self, cx: &Context<Self>) -> Option<AnyElement> {
let status = self.ready_suggestion(cx)?;
let commits = if status.ahead == 1 {
SharedString::from("1 commit")
} else {
SharedString::from(format!("{} commits", status.ahead))
};
let mut seen = HashSet::new();
let rest: Vec<_> = announcement
.maintainers
.iter()
.copied()
.filter(|key| key != &announcement.owner && seen.insert(*key))
.collect();
let owner = self.directory.read(cx).profile(&announcement.owner, cx);
let owner_name = owner.name();
h_flex()
.w_full()
.gap_3()
.child(
h_flex()
.gap_2()
.child(
h_flex()
.gap_1()
.child(
Avatar::new(announcement.owner)
.name(owner_name.clone())
.picture(owner.picture())
.small(),
)
.child(div().text_xs().whitespace_nowrap().child(owner_name)),
)
.when(!rest.is_empty(), |this| {
this.child(
div()
.text_xs()
.text_color(cx.theme().colors.muted_foreground)
.child(SharedString::from(format!("+{}", rest.len()))),
Some(
h_flex()
.p_4()
.w_full()
.justify_between()
.bg(cx.theme().colors.muted)
.child(
h_flex()
.gap_2()
.text_sm()
.text_color(cx.theme().colors.muted_foreground)
.child(Badge::new("ready-branch", status.branch.clone()))
.child(commits)
.child("ahead of")
.child(Badge::new("ready-base", status.base.clone())),
)
.child(
h_flex()
.gap_1()
.child(
Button::new("create-pr-from-banner")
.label("Create pull request")
.small()
.on_click(cx.listener(|this, _, window, cx| {
this.open_new_pull_request(window, cx);
})),
)
}),
)
.into_any_element()
.child(
Button::new("dismiss-ready-banner")
.icon(Icon::named(IconRole::Close))
.variant(ButtonVariant::Ghost)
.small()
.on_click(cx.listener(move |this, _, _, cx| {
this.banners.dismiss(&status);
cx.notify();
})),
),
)
.into_any_element(),
)
}
fn push_suggestion(&self, cx: &App) -> Option<CheckoutStatus> {
@@ -1758,7 +1198,8 @@ impl Panel for RepoDetailView {
impl Render for RepoDetailView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let banner = self
.render_push_banner(cx)
.render_ready_banner(cx)
.or_else(|| self.render_push_banner(cx))
.or_else(|| self.render_sync_banner(cx));
let error = self.error.clone().or_else(|| {