From d6a2e748d07d636427119c91b81ae28d4c86451b Mon Sep 17 00:00:00 2001 From: reya Date: Sat, 28 Feb 2026 12:59:53 +0700 Subject: [PATCH] improve button dropdown menus --- crates/coop/src/workspace.rs | 134 ++++++++++++----------------------- 1 file changed, 47 insertions(+), 87 deletions(-) diff --git a/crates/coop/src/workspace.rs b/crates/coop/src/workspace.rs index 07662c8..b423604 100644 --- a/crates/coop/src/workspace.rs +++ b/crates/coop/src/workspace.rs @@ -503,54 +503,35 @@ impl Workspace { .small() .ghost() .when(inbox_state.subscribing(), |this| this.indicator()) - .dropdown_menu(move |this, _window, _cx| { - this.min_w(px(260.)) - .label("Messaging Relays") - .menu_element_with_disabled( - Box::new(Command::ShowRelayList), - true, - move |_window, cx| { - let persons = PersonRegistry::global(cx); - let profile = persons.read(cx).get(&pkey, cx); - let urls = profile.messaging_relays(); + .dropdown_menu(move |this, _window, cx| { + let persons = PersonRegistry::global(cx); + let profile = persons.read(cx).get(&pkey, cx); + let urls: Vec = profile + .messaging_relays() + .iter() + .map(|url| SharedString::from(url.to_string())) + .collect(); - v_flex() - .gap_1() - .w_full() - .items_start() - .justify_start() - .children({ - let mut items = vec![]; + // Header + let menu = this.min_w(px(260.)).label("Messaging Relays"); - for url in urls.iter() { - items.push( - h_flex() - .h_6() - .w_full() - .gap_2() - .px_2() - .text_xs() - .bg(cx - .theme() - .elevated_surface_background) - .rounded(cx.theme().radius) - .child( - div() - .size_1() - .rounded_full() - .bg(gpui::green()), - ) - .child(SharedString::from( - url.to_string(), - )), - ); - } + // Content + let menu = urls.into_iter().fold(menu, |this, url| { + this.item(PopupMenuItem::element(move |_window, _cx| { + h_flex() + .px_1() + .w_full() + .gap_2() + .text_sm() + .child( + div().size_1p5().rounded_full().bg(gpui::green()), + ) + .child(url.clone()) + })) + }); - items - }) - }, - ) - .separator() + // Footer + menu.separator() .menu_with_icon( "Reload", IconName::Refresh, @@ -591,51 +572,30 @@ impl Workspace { .small() .ghost() .when(relay_list.configured(), |this| this.indicator()) - .dropdown_menu(move |this, _window, _cx| { - this.min_w(px(260.)) - .label("Relays") - .menu_element_with_disabled( - Box::new(Command::ShowRelayList), - true, - move |_window, cx| { - let nostr = NostrRegistry::global(cx); - let urls = nostr.read(cx).read_only_relays(&pkey, cx); + .dropdown_menu(move |this, _window, cx| { + let nostr = NostrRegistry::global(cx); + let urls = nostr.read(cx).read_only_relays(&pkey, cx); - v_flex() - .gap_1() - .w_full() - .items_start() - .justify_start() - .children({ - let mut items = vec![]; + // Header + let menu = this.min_w(px(260.)).label("Relays"); - for url in urls.into_iter() { - items.push( - h_flex() - .h_6() - .w_full() - .gap_2() - .px_2() - .text_xs() - .bg(cx - .theme() - .elevated_surface_background) - .rounded(cx.theme().radius) - .child( - div() - .size_1() - .rounded_full() - .bg(gpui::green()), - ) - .child(url), - ); - } + // Content + let menu = urls.into_iter().fold(menu, |this, url| { + this.item(PopupMenuItem::element(move |_window, _cx| { + h_flex() + .px_1() + .w_full() + .gap_2() + .text_sm() + .child( + div().size_1p5().rounded_full().bg(gpui::green()), + ) + .child(url.clone()) + })) + }); - items - }) - }, - ) - .separator() + // Footer + menu.separator() .menu_with_icon( "Reload", IconName::Refresh,