Show edit modal on start

This commit is contained in:
Adrian Woźniak 2020-04-10 14:26:50 +02:00
parent f2081c9974
commit 767d247647

View File

@ -1,9 +1,10 @@
use seed::{prelude::*, *};
use jirs_data::UpdateIssuePayload;
use jirs_data::*;
use crate::api::send_ws_msg;
use crate::model::{AddIssueModal, EditIssueModal, ModalType, Page};
use crate::model::{AddIssueModal, EditIssueModal, ModalType, Model, Page};
use crate::shared::styled_editor::Mode;
use crate::shared::styled_modal::{StyledModal, Variant as ModalVariant};
use crate::shared::styled_select::StyledSelectState;
@ -36,43 +37,17 @@ pub fn update(msg: &Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>
model.modals.push(modal_type.clone());
}
Msg::WsMsg(jirs_data::WsMsg::ProjectIssuesLoaded(issues)) => match model.page.clone() {
Page::EditIssue(issue_id) if model.modals.is_empty() => {
push_edit_modal(&issue_id, model)
}
_ => (),
},
Msg::ChangePage(Page::EditIssue(issue_id)) => {
let modal = {
let issue = match find_issue(model, *issue_id) {
Some(issue) => issue,
_ => return,
};
ModalType::EditIssue(
*issue_id,
EditIssueModal {
id: *issue_id,
link_copied: false,
payload: UpdateIssuePayload {
title: issue.title.clone(),
issue_type: issue.issue_type.clone(),
status: issue.status.clone(),
priority: issue.priority.clone(),
list_position: issue.list_position.clone(),
description: issue.description.clone(),
description_text: issue.description_text.clone(),
estimate: issue.estimate.clone(),
time_spent: issue.time_spent.clone(),
time_remaining: issue.time_remaining.clone(),
project_id: issue.project_id.clone(),
reporter_id: issue.reporter_id.clone(),
user_ids: issue.user_ids.clone(),
},
top_type_state: StyledSelectState::new(FieldId::IssueTypeEditModalTop),
status_state: StyledSelectState::new(FieldId::StatusIssueEditModal),
reporter_state: StyledSelectState::new(FieldId::ReporterIssueEditModal),
assignees_state: StyledSelectState::new(FieldId::AssigneesIssueEditModal),
priority_state: StyledSelectState::new(FieldId::PriorityIssueEditModal),
description_editor_mode: Mode::Editor,
},
)
};
model.modals.push(modal);
push_edit_modal(issue_id, model);
}
Msg::ChangePage(Page::AddIssue) => {
let mut modal = AddIssueModal::default();
modal.project_id = model.project.as_ref().map(|p| p.id);
@ -109,3 +84,41 @@ pub fn view(model: &model::Model) -> Node<Msg> {
.collect();
section![id!["modals"], modals]
}
fn push_edit_modal(issue_id: &i32, model: &mut Model) {
let modal = {
let issue = match find_issue(model, *issue_id) {
Some(issue) => issue,
_ => return,
};
ModalType::EditIssue(
*issue_id,
EditIssueModal {
id: *issue_id,
link_copied: false,
payload: UpdateIssuePayload {
title: issue.title.clone(),
issue_type: issue.issue_type.clone(),
status: issue.status.clone(),
priority: issue.priority.clone(),
list_position: issue.list_position.clone(),
description: issue.description.clone(),
description_text: issue.description_text.clone(),
estimate: issue.estimate.clone(),
time_spent: issue.time_spent.clone(),
time_remaining: issue.time_remaining.clone(),
project_id: issue.project_id.clone(),
reporter_id: issue.reporter_id.clone(),
user_ids: issue.user_ids.clone(),
},
top_type_state: StyledSelectState::new(FieldId::IssueTypeEditModalTop),
status_state: StyledSelectState::new(FieldId::StatusIssueEditModal),
reporter_state: StyledSelectState::new(FieldId::ReporterIssueEditModal),
assignees_state: StyledSelectState::new(FieldId::AssigneesIssueEditModal),
priority_state: StyledSelectState::new(FieldId::PriorityIssueEditModal),
description_editor_mode: Mode::Editor,
},
)
};
model.modals.push(modal);
}