refactor dialogs

This commit is contained in:
2026-09-29 10:46:16 +07:00
parent 828986cd5c
commit 0a9301f131
16 changed files with 202 additions and 200 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ use ui::{Disableable, StyledExt, WindowExtension, divider, v_flex};
pub fn open(window: &mut Window, cx: &mut App) {
let import = cx.new(|cx| ImportIdentity::new(window, cx));
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
this.width(px(450.))
.show_close(false)
.overlay_closable(false)
@@ -138,7 +138,7 @@ impl ImportIdentity {
Ok(keys) => {
nostr.update_in(cx, |this, window, cx| {
this.set_signer(keys, cx);
window.close_modal(cx);
window.close_dialog(cx);
})?;
}
Err(e) => {
+3 -3
View File
@@ -13,9 +13,9 @@ use person::PersonRegistry;
use state::NostrRegistry;
use theme::ActiveTheme;
use ui::button::{Button, ButtonVariants};
use ui::dialog::DialogButtonProps;
use ui::dock::{DockArea, DockPlacement, PanelHandle};
use ui::input::{Input, InputEvent, InputState};
use ui::modal::ModalButtonProps;
use ui::nav::Nav;
use ui::{Disableable, IconName, Selectable, Sizable, WindowExtension, h_flex, v_flex};
@@ -27,14 +27,14 @@ const MAX_MEMBERS: usize = 3;
pub fn open(dock: WeakEntity<DockArea>, window: &mut Window, cx: &mut App) {
let view = cx.new(|cx| NewChat::new(dock, window, cx));
window.open_modal(cx, {
window.open_dialog(cx, {
let view = view.clone();
move |this, _window, _cx| {
this.width(px(420.))
.title("New chat")
.confirm()
.button_props(
ModalButtonProps::default()
DialogButtonProps::default()
.cancel_text("Cancel")
.ok_text("Start"),
)
@@ -6,7 +6,7 @@ use ui::input::{Input, InputState};
pub fn open(window: &mut Window, cx: &mut App) {
let name_input = cx.new(|cx| InputState::new(window, cx).placeholder("Community name"));
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
let name_input = name_input.clone();
this.width(px(380.))
@@ -14,6 +14,7 @@ pub fn open(window: &mut Window, cx: &mut App) {
.title("New community")
.child(Input::new(&name_input))
.on_ok(move |_event, _window, cx| {
let community = CommunityRegistry::global(cx);
let name = name_input.read(cx).value().trim().to_owned();
if name.is_empty() {
@@ -25,8 +26,9 @@ pub fn open(window: &mut Window, cx: &mut App) {
..CommunityMetadata::default()
};
CommunityRegistry::global(cx)
.update(cx, |registry, cx| registry.create(metadata, cx));
community.update(cx, |registry, cx| {
registry.create(metadata, cx);
});
true
})
+2 -2
View File
@@ -65,8 +65,8 @@ impl RestoreEncryption {
this.set_announcement(Keys::new(secret), cx);
});
// Close the current modal
window.close_modal(cx);
// Close the current dialog
window.close_dialog(cx);
}
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
+3 -3
View File
@@ -52,7 +52,7 @@ impl Screening {
subscriptions.push(cx.on_release_in(window, move |this, window, cx| {
this.tasks.clear();
window.close_all_modals(cx);
window.close_all_dialogs(cx);
}));
cx.defer_in(window, |this, _window, cx| {
@@ -259,7 +259,7 @@ impl Screening {
self.tasks.push(cx.spawn_in(window, async move |_, cx| {
if task.await.is_ok() {
cx.update(|window, cx| {
window.close_modal(cx);
window.close_dialog(cx);
window.push_notification("Report submitted successfully", cx);
})
.ok();
@@ -270,7 +270,7 @@ impl Screening {
fn mutual_contacts(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let contacts = self.mutual_contacts.clone();
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
let contacts = contacts.clone();
let total = contacts.len();
+9 -9
View File
@@ -93,7 +93,7 @@ impl Workspace {
// Subscribe to the nostr events
cx.subscribe_in(&nostr, window, move |_this, _state, event, window, cx| {
if let StateEvent::SignerChanged = event {
window.close_all_modals(cx);
window.close_all_dialogs(cx);
}
}),
);
@@ -242,7 +242,7 @@ impl Workspace {
Command::ShowSettings => {
let view = settings::init(window, cx);
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
this.width(px(520.))
.show_close(true)
.pb_2()
@@ -387,7 +387,7 @@ impl Workspace {
let device = DeviceRegistry::global(cx);
let ent = device.downgrade();
window.open_modal(cx, move |this, _window, cx| {
window.open_dialog(cx, move |this, _window, cx| {
let ent = ent.clone();
this.confirm()
@@ -410,7 +410,7 @@ impl Workspace {
this.set_announcement(Keys::generate(), cx);
})
.ok();
// true to close modal
// true to close dialog
true
})
});
@@ -418,7 +418,7 @@ impl Workspace {
fn import_encryption(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let restore = cx.new(|cx| RestoreEncryption::new(window, cx));
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
this.width(px(420.))
.title("Restore Encryption")
.child(restore.clone())
@@ -426,7 +426,7 @@ impl Workspace {
}
fn theme_selector(&mut self, window: &mut Window, cx: &mut Context<Self>) {
window.open_modal(cx, move |this, _window, cx| {
window.open_dialog(cx, move |this, _window, cx| {
let registry = ThemeRegistry::global(cx);
let themes = registry.read(cx).themes();
@@ -508,7 +508,7 @@ impl Workspace {
impl Render for Workspace {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let modal_layer = Root::render_modal_layer(window, cx);
let dialog_layer = Root::render_dialog_layer(window, cx);
let notification_layer = Root::render_notification_layer(window, cx);
div()
@@ -519,7 +519,7 @@ impl Render for Workspace {
.child(self.dock.clone())
// Notifications
.children(notification_layer)
// Modals
.children(modal_layer)
// Dialogs
.children(dialog_layer)
}
}
+3 -3
View File
@@ -22,10 +22,10 @@ use state::{NostrRegistry, StateEvent};
use theme::{ActiveTheme, TABBAR_HEIGHT};
use ui::avatar::Avatar;
use ui::button::{Button, ButtonCustomVariant, ButtonVariants};
use ui::dialog::DialogButtonProps;
use ui::dock::{ClosePanel, DockArea, DockPlacement, Panel, PanelEvent, PanelHandle};
use ui::indicator::Indicator;
use ui::menu::{DropdownMenu, PopupMenuItem};
use ui::modal::ModalButtonProps;
use ui::nav::Nav;
use ui::nav_item::NavItem;
use ui::notification::Notification;
@@ -876,11 +876,11 @@ impl Sidebar {
if kind != RoomKind::Ongoing && AppSettings::get_screening(cx) {
let screening = screening::init(peer, window, cx);
window.open_modal(cx, move |this, _window, _cx| {
window.open_dialog(cx, move |this, _window, _cx| {
this.confirm()
.child(screening.clone())
.button_props(
ModalButtonProps::default()
DialogButtonProps::default()
.cancel_text("Ignore")
.ok_text("Response"),
)