Merge modal and modals

This commit is contained in:
Adrian Woźniak 2021-01-16 08:22:39 +01:00
parent 23c6cd1a8c
commit 915ff46281
9 changed files with 77 additions and 76 deletions

View File

@ -23,7 +23,6 @@ pub use {changes::*, fields::*, images::*};
mod changes;
mod fields;
mod images;
mod modal;
mod modals;
mod model;
mod pages;
@ -235,7 +234,7 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
aside::update(&msg, model, orders);
navbar_left::update(&msg, model, orders);
}
crate::modal::update(&msg, model, orders);
crate::modals::update(&msg, model, orders);
match model.page {
Page::Project | Page::AddIssue | Page::EditIssue(..) => {

View File

@ -1,7 +1,9 @@
use {
crate::{
model::{IssueModal, Model},
shared::{styled_field::StyledField, styled_select::StyledSelect, ToChild, ToNode},
shared::styled_field::StyledField,
shared::styled_select::StyledSelect,
shared::{ToChild, ToNode},
FieldId, Msg,
},
jirs_data::EpicId,

View File

@ -1,7 +1,9 @@
use {
crate::{
modal::issues::epic_field,
modals::issues_create::{Model as AddIssueModal, Type},
modals::{
epic_field,
issues_create::{Model as AddIssueModal, Type},
},
model::Model,
shared::{
styled_button::StyledButton, styled_date_time_input::StyledDateTimeInput,

View File

@ -1,7 +1,8 @@
use {
crate::{
modal::issues::epic_field,
modals::{issues_edit::Model as EditIssueModal, time_tracking::time_tracking_field},
modals::{
epic_field, issues_edit::Model as EditIssueModal, time_tracking::time_tracking_field,
},
model::{ModalType, Model},
shared::{
styled_avatar::StyledAvatar, styled_button::StyledButton, styled_editor::StyledEditor,

View File

@ -1,3 +1,5 @@
pub use {epic_field::*, update::*, view::*};
#[cfg(debug_assertions)]
pub mod debug;
pub mod issue_statuses_delete;
@ -5,3 +7,7 @@ pub mod issues_create;
pub mod issues_delete;
pub mod issues_edit;
pub mod time_tracking;
mod epic_field;
mod update;
mod view;

View File

@ -2,7 +2,6 @@ use {
crate::{
model::{ModalType, Model},
shared::{
find_issue,
styled_button::StyledButton,
styled_field::StyledField,
styled_input::{StyledInput, StyledInputState},
@ -17,8 +16,6 @@ use {
seed::{prelude::*, *},
};
// use crate::shared::styled_select_child::*;
pub fn value_for_time_tracking(v: &Option<i32>, time_tracking_type: &TimeTracking) -> String {
match (time_tracking_type, v.as_ref()) {
(TimeTracking::Untracked, _) => "".to_string(),
@ -29,10 +26,9 @@ pub fn value_for_time_tracking(v: &Option<i32>, time_tracking_type: &TimeTrackin
}
pub fn view(model: &Model, issue_id: IssueId) -> Node<Msg> {
let _issue = match find_issue(model, issue_id) {
Some(issue) => issue,
_ => return empty![],
};
if model.issues_by_id.get(&issue_id).is_none() {
return Node::Empty;
}
let edit_issue_modal = match model.modals.get(0) {
Some(ModalType::EditIssue(_, modal)) => modal,

View File

@ -1,12 +1,7 @@
use {
crate::{
model::{self, ModalType, Model, Page},
shared::{
find_issue, go_to_board,
styled_confirm_modal::StyledConfirmModal,
styled_modal::{StyledModal, Variant as ModalVariant},
ToNode,
},
model::{ModalType, Model, Page},
shared::go_to_board,
ws::send_ws_msg,
FieldChange, FieldId, Msg, OperationKind, ResourceKind,
},
@ -14,9 +9,7 @@ use {
seed::{prelude::*, *},
};
pub mod issues;
pub fn update(msg: &Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
match msg {
Msg::ModalDropped => match model.modals.pop() {
Some(ModalType::EditIssue(..)) | Some(ModalType::AddIssue(..)) => {
@ -74,50 +67,6 @@ pub fn update(msg: &Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>
issue_statuses_delete::update(msg, model, orders);
}
pub fn view(model: &model::Model) -> Node<Msg> {
use crate::modals::{issue_statuses_delete, issues_create, issues_edit};
let modals: Vec<Node<Msg>> = model
.modals
.iter()
.map(|modal| match modal {
ModalType::EditIssue(issue_id, modal) => {
if let Some(_issue) = find_issue(model, *issue_id) {
let details = issues_edit::view(model, modal.as_ref());
StyledModal::build()
.variant(ModalVariant::Center)
.width(1040)
.children(vec![details])
.build()
.into_node()
} else {
empty![]
}
}
ModalType::DeleteIssueConfirm(_id) => crate::modals::issues_delete::view(model),
ModalType::AddIssue(modal) => issues_create::view(model, modal),
ModalType::DeleteCommentConfirm(comment_id) => {
let comment_id = *comment_id;
StyledConfirmModal::build()
.title("Are you sure you want to delete this comment?")
.message("Once you delete, it's gone for good.")
.confirm_text("Delete comment")
.on_confirm(mouse_ev(Ev::Click, move |_| Msg::DeleteComment(comment_id)))
.build()
.into_node()
}
ModalType::TimeTracking(issue_id) => {
crate::modals::time_tracking::view(model, *issue_id)
}
ModalType::DeleteIssueStatusModal(delete_issue_modal) => {
issue_statuses_delete::view(model, delete_issue_modal.delete_id)
}
#[cfg(debug_assertions)]
ModalType::DebugModal => crate::modals::debug::view(model),
})
.collect();
section![id!["modals"], modals]
}
fn push_add_modal(model: &mut Model, _orders: &mut impl Orders<Msg>) {
use crate::modals::issues_create::Model;
model.modals.push(ModalType::AddIssue(Box::new(Model {
@ -133,7 +82,7 @@ fn push_edit_modal(issue_id: i32, model: &mut Model, orders: &mut impl Orders<Ms
.map(|p| p.time_tracking)
.unwrap_or_else(|| TimeTracking::Untracked);
let modal = {
let issue = match find_issue(model, issue_id) {
let issue = match model.issues_by_id.get(&issue_id) {
Some(issue) => issue,
_ => return,
};

View File

@ -0,0 +1,51 @@
use {
crate::{
model::*, shared::styled_confirm_modal::StyledConfirmModal,
shared::styled_modal::StyledModal, shared::ToNode, Msg,
},
seed::{prelude::*, *},
};
pub fn view(model: &Model) -> Node<Msg> {
use crate::modals::{issue_statuses_delete, issues_create, issues_edit};
let modals: Vec<Node<Msg>> = model
.modals
.iter()
.map(|modal| match modal {
ModalType::EditIssue(issue_id, modal) => {
if let Some(_issue) = model.issues_by_id.get(issue_id) {
let details = issues_edit::view(model, modal.as_ref());
StyledModal::build()
.variant(crate::shared::styled_modal::Variant::Center)
.width(1040)
.children(vec![details])
.build()
.into_node()
} else {
empty![]
}
}
ModalType::DeleteIssueConfirm(_id) => crate::modals::issues_delete::view(model),
ModalType::AddIssue(modal) => issues_create::view(model, modal),
ModalType::DeleteCommentConfirm(comment_id) => {
let comment_id = *comment_id;
StyledConfirmModal::build()
.title("Are you sure you want to delete this comment?")
.message("Once you delete, it's gone for good.")
.confirm_text("Delete comment")
.on_confirm(mouse_ev(Ev::Click, move |_| Msg::DeleteComment(comment_id)))
.build()
.into_node()
}
ModalType::TimeTracking(issue_id) => {
crate::modals::time_tracking::view(model, *issue_id)
}
ModalType::DeleteIssueStatusModal(delete_issue_modal) => {
issue_statuses_delete::view(model, delete_issue_modal.delete_id)
}
#[cfg(debug_assertions)]
ModalType::DebugModal => crate::modals::debug::view(model),
})
.collect();
section![id!["modals"], modals]
}

View File

@ -3,7 +3,6 @@ use {
model::{Model, Page},
resolve_page, Msg,
},
jirs_data::*,
seed::{prelude::*, *},
};
@ -63,10 +62,6 @@ pub fn go_to(url: &str, orders: &mut impl Orders<Msg>) {
}
}
pub fn find_issue(model: &'_ Model, issue_id: IssueId) -> Option<&'_ Issue> {
model.issues.iter().find(|issue| issue.id == issue_id)
}
pub trait ToNode {
fn into_node(self) -> Node<Msg>;
}
@ -78,7 +73,7 @@ pub fn divider() -> Node<Msg> {
#[inline]
pub fn inner_layout(model: &Model, page_name: &str, children: &[Node<Msg>]) -> Node<Msg> {
let modal_node = crate::modal::view(model);
let modal_node = crate::modals::view(model);
article![
modal_node,
C!["inner-layout", "innerPage"],
@ -91,7 +86,7 @@ pub fn inner_layout(model: &Model, page_name: &str, children: &[Node<Msg>]) -> N
#[inline]
pub fn outer_layout(model: &Model, page_name: &str, children: Vec<Node<Msg>>) -> Node<Msg> {
let modal = crate::modal::view(model);
let modal = crate::modals::view(model);
article![
C!["outer-layout", "outerPage"],
id![page_name],