diff --git a/glot_core/src/components/file_modal.rs b/glot_core/src/components/file_modal.rs index 99e1ff7..6d75c6a 100644 --- a/glot_core/src/components/file_modal.rs +++ b/glot_core/src/components/file_modal.rs @@ -10,6 +10,11 @@ use poly::browser::subscription::Subscription; use poly::browser::value::Capture; use serde::{Deserialize, Serialize}; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::FileModalBackdrop, + close_button_id: Id::FileModalClose, +}; + #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum State { @@ -72,10 +77,7 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::FileModalBackdrop, - close_button_id: Id::FileModalClose, - }; + // fmt subscription::batch(vec![ event_listener::on_click(Id::AddFileButton, to_parent_msg(Msg::AddFileClicked)), @@ -92,7 +94,7 @@ where }), event_listener::on_submit(Id::NewFileForm, to_parent_msg(Msg::AddFileClicked)), event_listener::on_submit(Id::EditFileForm, to_parent_msg(Msg::UpdateFileClicked)), - modal::subscriptions(&modal_config, to_parent_msg(Msg::Close)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::Close)), ]) } @@ -214,13 +216,7 @@ pub fn open_for_add( pub fn view(state: &State) -> maud::Markup { match state { - State::Open(model) => modal::view( - view_modal(model), - &modal::Config { - backdrop_id: Id::FileModalBackdrop, - close_button_id: Id::FileModalClose, - }, - ), + State::Open(model) => modal::view(view_modal(model), &MODAL_CONFIG), State::Closed => html! {}, } } diff --git a/glot_core/src/components/search_modal.rs b/glot_core/src/components/search_modal.rs index 8b316c9..54c0992 100644 --- a/glot_core/src/components/search_modal.rs +++ b/glot_core/src/components/search_modal.rs @@ -17,6 +17,11 @@ use poly::browser::value::Capture; use serde::{Deserialize, Serialize}; use std::{fmt::Display, hash::Hash}; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::SearchModalBackdrop, + close_button_id: Id::SearchModalClose, +}; + #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum State { @@ -81,11 +86,7 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::SearchModalBackdrop, - close_button_id: Id::SearchModalClose, - }; - + // fmt subscription::batch(vec![ event_listener::on_input(Id::QueryInput, |captured| { to_parent_msg(Msg::QueryChanged(captured)) @@ -107,7 +108,7 @@ where ModifierKey::None, to_parent_msg(Msg::SelectNext), ), - modal::subscriptions(&modal_config, to_parent_msg(Msg::CloseModal)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::CloseModal)), ]) } @@ -257,13 +258,7 @@ where EntryId: Display + EntryExtra, { if let State::Open(model) = state { - modal::view_barebones( - view_search_modal(user_agent, model), - &modal::Config { - backdrop_id: Id::SearchModalBackdrop, - close_button_id: Id::SearchModalClose, - }, - ) + modal::view_minimal(view_search_modal(user_agent, model), &MODAL_CONFIG) } else { html! {} } diff --git a/glot_core/src/components/settings_modal.rs b/glot_core/src/components/settings_modal.rs index 7ca15f4..80c2688 100644 --- a/glot_core/src/components/settings_modal.rs +++ b/glot_core/src/components/settings_modal.rs @@ -1,3 +1,7 @@ +use crate::ace_editor::EditorKeyboardBindings; +use crate::ace_editor::EditorTheme; +use crate::view::dropdown; +use crate::view::modal; use maud::html; use poly::browser::dom_id::DomId; use poly::browser::effect::dom; @@ -8,10 +12,10 @@ use poly::browser::subscription::Subscription; use poly::browser::value::Capture; use serde::{Deserialize, Serialize}; -use crate::ace_editor::EditorKeyboardBindings; -use crate::ace_editor::EditorTheme; -use crate::view::dropdown; -use crate::view::modal; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::SettingsModalBackdrop, + close_button_id: Id::SettingsModalClose, +}; #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] @@ -56,10 +60,7 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::SettingsModalBackdrop, - close_button_id: Id::SettingsModalClose, - }; + // fmt subscription::batch(vec![ event_listener::on_change(Id::KeyboardBindings, |captured| { @@ -69,7 +70,7 @@ where to_parent_msg(Msg::EditorThemeChanged(captured)) }), event_listener::on_click(Id::SettingsSaveButton, to_parent_msg(Msg::Save)), - modal::subscriptions(&modal_config, to_parent_msg(Msg::Close)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::Close)), ]) } @@ -141,13 +142,7 @@ pub fn open( pub fn view(state: &State) -> maud::Markup { if let State::Open(model) = state { - modal::view( - view_modal(model), - &modal::Config { - backdrop_id: Id::SettingsModalBackdrop, - close_button_id: Id::SettingsModalClose, - }, - ) + modal::view(view_modal(model), &MODAL_CONFIG) } else { html! {} } diff --git a/glot_core/src/components/sharing_modal.rs b/glot_core/src/components/sharing_modal.rs index 43ebfed..39e2bd5 100644 --- a/glot_core/src/components/sharing_modal.rs +++ b/glot_core/src/components/sharing_modal.rs @@ -18,6 +18,11 @@ use std::fmt; use std::time::Duration; use url::Url; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::SharingModalBackdrop, + close_button_id: Id::SharingModalClose, +}; + #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum State { @@ -62,18 +67,14 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::SharingModalBackdrop, - close_button_id: Id::SharingModalClose, - }; - + // fmt subscription::batch(vec![ event_listener::on_click_closest( Id::CopyUrlButton, to_parent_msg(Msg::CopyUrlClicked), ), event_listener::on_click(Id::SharingModalCloseButton, to_parent_msg(Msg::Close)), - modal::subscriptions(&modal_config, to_parent_msg(Msg::Close)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::Close)), ]) } @@ -174,13 +175,7 @@ where pub fn view(state: &State) -> maud::Markup { if let State::Open(model) = state { - modal::view( - view_modal(model), - &modal::Config { - backdrop_id: Id::SharingModalBackdrop, - close_button_id: Id::SharingModalClose, - }, - ) + modal::view(view_modal(model), &MODAL_CONFIG) } else { html! {} } diff --git a/glot_core/src/components/stdin_modal.rs b/glot_core/src/components/stdin_modal.rs index e3ff89b..306b1ee 100644 --- a/glot_core/src/components/stdin_modal.rs +++ b/glot_core/src/components/stdin_modal.rs @@ -9,6 +9,11 @@ use poly::browser::subscription::Subscription; use poly::browser::value::Capture; use serde::{Deserialize, Serialize}; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::StdinModalBackdrop, + close_button_id: Id::StdinModalClose, +}; + #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum State { @@ -51,11 +56,7 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::StdinModalBackdrop, - close_button_id: Id::StdinModalClose, - }; - + // fmt subscription::batch(vec![ event_listener::on_input(Id::StdinInput, |captured| { to_parent_msg(Msg::StdinChanged(captured)) @@ -68,7 +69,7 @@ where Id::SaveStdinButton, to_parent_msg(Msg::UpdateStdinClicked), ), - modal::subscriptions(&modal_config, to_parent_msg(Msg::Close)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::Close)), ]) } State::Closed => subscription::none(), @@ -128,13 +129,7 @@ pub fn open(state: &mut State, value: &str) -> Effect maud::Markup { if let State::Open(model) = state { - modal::view( - view_modal(model), - &modal::Config { - backdrop_id: Id::StdinModalBackdrop, - close_button_id: Id::StdinModalClose, - }, - ) + modal::view(view_modal(model), &MODAL_CONFIG) } else { html! {} } diff --git a/glot_core/src/components/title_modal.rs b/glot_core/src/components/title_modal.rs index 51a6075..45fd91b 100644 --- a/glot_core/src/components/title_modal.rs +++ b/glot_core/src/components/title_modal.rs @@ -9,6 +9,11 @@ use poly::browser::subscription::Subscription; use poly::browser::value::Capture; use serde::{Deserialize, Serialize}; +const MODAL_CONFIG: modal::Config = modal::Config { + backdrop_id: Id::TitleModalBackdrop, + close_button_id: Id::TitleModalClose, +}; + #[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum State { @@ -51,11 +56,7 @@ where { match state { State::Open(_) => { - let modal_config = modal::Config { - backdrop_id: Id::TitleModalBackdrop, - close_button_id: Id::TitleModalClose, - }; - + // fmt subscription::batch(vec![ event_listener::on_input(Id::TitleInput, |captured| { to_parent_msg(Msg::TitleChanged(captured)) @@ -65,7 +66,7 @@ where to_parent_msg(Msg::UpdateTitleClicked), ), event_listener::on_submit(Id::TitleForm, to_parent_msg(Msg::UpdateTitleClicked)), - modal::subscriptions(&modal_config, to_parent_msg(Msg::Close)), + modal::subscriptions(&MODAL_CONFIG, to_parent_msg(Msg::Close)), ]) } @@ -125,13 +126,7 @@ pub fn open(state: &mut State, title: &str) -> Effect maud::Markup { if let State::Open(model) = state { - modal::view( - view_modal(model), - &modal::Config { - backdrop_id: Id::TitleModalBackdrop, - close_button_id: Id::TitleModalClose, - }, - ) + modal::view(view_modal(model), &MODAL_CONFIG) } else { html! {} } diff --git a/glot_core/src/view/modal.rs b/glot_core/src/view/modal.rs index f5779a3..9d73bb2 100644 --- a/glot_core/src/view/modal.rs +++ b/glot_core/src/view/modal.rs @@ -47,7 +47,7 @@ pub fn view(content: Markup, config: &Config) -> Markup { } } -pub fn view_barebones(content: Markup, config: &Config) -> Markup { +pub fn view_minimal(content: Markup, config: &Config) -> Markup { html! { div class="relative z-10" aria-labelledby="modal-title" role="dialog" aria-modal="true" { div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" {}