chore: refactor dialogs to render custom footer buttons

This commit is contained in:
2026-10-08 16:27:39 +07:00
parent fff0f6a753
commit 09fb58c5a4
9 changed files with 170 additions and 141 deletions
+42 -8
View File
@@ -1,24 +1,33 @@
use gpui::{App, AppContext, Div, Entity, ParentElement, Styled, Window, px};
use std::rc::Rc;
use gpui::{App, AppContext, ClickEvent, Div, Entity, ParentElement, Styled, Window, px};
use nip29::{GroupId, GroupKey, GroupMetadata, GroupsRegistry};
use nostr_sdk::prelude::*;
use theme::ActiveTheme;
use ui::button::{Button, ButtonVariants};
use ui::input::{Input, InputState};
use ui::notification::Notification;
use ui::{WindowExtension, v_flex};
use ui::{IconName, StyledExt, WindowExtension, h_flex, v_flex};
type SubmitFn = Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) -> bool>;
pub fn open(window: &mut Window, cx: &mut App) {
let name = cx.new(|cx| InputState::new(window, cx).placeholder("Group name"));
let id = cx.new(|cx| InputState::new(window, cx).placeholder("Group id"));
let relay = cx.new(|cx| InputState::new(window, cx).placeholder("wss://relay.example.com"));
window.open_dialog(cx, move |this, _window, cx| {
let name = name.clone();
let id = id.clone();
let relay = relay.clone();
let submit: SubmitFn = {
let (name, id, relay) = (name.clone(), id.clone(), relay.clone());
Rc::new(move |_, window, cx| create(&name, &id, &relay, window, cx))
};
window.open_dialog(cx, move |this, _window, cx| {
this.width(px(380.))
.confirm()
.title("New group")
.on_ok({
let submit = submit.clone();
move |event, window, cx| submit(event, window, cx)
})
.child(
v_flex()
.gap_3()
@@ -26,7 +35,32 @@ pub fn open(window: &mut Window, cx: &mut App) {
.child(field("Group id", &id, cx))
.child(field("Relay", &relay, cx)),
)
.on_ok(move |_event, window, cx| create(&name, &id, &relay, window, cx))
.child(
h_flex()
.gap_1()
.justify_end()
.child(
Button::new("cancel")
.label("Cancel")
.ghost()
.on_click(|_, window, cx| window.close_dialog(cx)),
)
.child(
Button::new("create")
.icon(IconName::CheckCircle)
.label("Create")
.primary()
.font_semibold()
.on_click({
let submit = submit.clone();
move |event, window, cx| {
if submit(event, window, cx) {
window.close_dialog(cx);
}
}
}),
),
)
});
}