Skip to content

Commit

Permalink
Make modal_config a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Aug 3, 2024
1 parent d723448 commit 95414ba
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 81 deletions.
20 changes: 8 additions & 12 deletions glot_core/src/components/file_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use poly::browser::subscription::Subscription;
use poly::browser::value::Capture;
use serde::{Deserialize, Serialize};

const MODAL_CONFIG: modal::Config<Id> = modal::Config {
backdrop_id: Id::FileModalBackdrop,
close_button_id: Id::FileModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum State {
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
])
}

Expand Down Expand Up @@ -214,13 +216,7 @@ pub fn open_for_add<ParentMsg, AppEffect>(

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! {},
}
}
Expand Down
21 changes: 8 additions & 13 deletions glot_core/src/components/search_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use poly::browser::value::Capture;
use serde::{Deserialize, Serialize};
use std::{fmt::Display, hash::Hash};

const MODAL_CONFIG: modal::Config<Id> = modal::Config {
backdrop_id: Id::SearchModalBackdrop,
close_button_id: Id::SearchModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum State<EntryId> {
Expand Down Expand Up @@ -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))
Expand All @@ -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)),
])
}

Expand Down Expand Up @@ -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! {}
}
Expand Down
27 changes: 11 additions & 16 deletions glot_core/src/components/settings_modal.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Id> = modal::Config {
backdrop_id: Id::SettingsModalBackdrop,
close_button_id: Id::SettingsModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -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| {
Expand All @@ -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)),
])
}

Expand Down Expand Up @@ -141,13 +142,7 @@ pub fn open<ParentMsg, AppEffect>(

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! {}
}
Expand Down
21 changes: 8 additions & 13 deletions glot_core/src/components/sharing_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ use std::fmt;
use std::time::Duration;
use url::Url;

const MODAL_CONFIG: modal::Config<Id> = modal::Config {
backdrop_id: Id::SharingModalBackdrop,
close_button_id: Id::SharingModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum State {
Expand Down Expand Up @@ -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)),
])
}

Expand Down Expand Up @@ -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! {}
}
Expand Down
21 changes: 8 additions & 13 deletions glot_core/src/components/stdin_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use poly::browser::subscription::Subscription;
use poly::browser::value::Capture;
use serde::{Deserialize, Serialize};

const MODAL_CONFIG: modal::Config<Id> = modal::Config {
backdrop_id: Id::StdinModalBackdrop,
close_button_id: Id::StdinModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum State {
Expand Down Expand Up @@ -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))
Expand All @@ -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(),
Expand Down Expand Up @@ -128,13 +129,7 @@ pub fn open<ParentMsg, AppEffect>(state: &mut State, value: &str) -> Effect<Pare

pub fn view(state: &State) -> 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! {}
}
Expand Down
21 changes: 8 additions & 13 deletions glot_core/src/components/title_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use poly::browser::subscription::Subscription;
use poly::browser::value::Capture;
use serde::{Deserialize, Serialize};

const MODAL_CONFIG: modal::Config<Id> = modal::Config {
backdrop_id: Id::TitleModalBackdrop,
close_button_id: Id::TitleModalClose,
};

#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum State {
Expand Down Expand Up @@ -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))
Expand All @@ -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)),
])
}

Expand Down Expand Up @@ -125,13 +126,7 @@ pub fn open<ParentMsg, AppEffect>(state: &mut State, title: &str) -> Effect<Pare

pub fn view(state: &State) -> 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! {}
}
Expand Down
2 changes: 1 addition & 1 deletion glot_core/src/view/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn view<Id: DomId>(content: Markup, config: &Config<Id>) -> Markup {
}
}

pub fn view_barebones<Id: DomId>(content: Markup, config: &Config<Id>) -> Markup {
pub fn view_minimal<Id: DomId>(content: Markup, config: &Config<Id>) -> 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" {}
Expand Down

0 comments on commit 95414ba

Please sign in to comment.