This commit is contained in:
Adrian Woźniak 2021-10-12 17:54:55 +02:00
parent 97325d72ef
commit 285ca9e97e
No known key found for this signature in database
GPG Key ID: DE43476F72AD3F6C
4 changed files with 99 additions and 54 deletions

View File

@ -325,10 +325,15 @@ fn resolve_page(url: Url) -> Option<Page> {
#[wasm_bindgen]
pub fn render() {
console_error_panic_hook::set_once();
let app = seed::App::start("app", init, update, view);
wasm_logger::init(wasm_logger::Config::default());
wasm_logger::init(if cfg!(debug_assertions) {
console_error_panic_hook::set_once();
wasm_logger::Config::default()
} else {
wasm_logger::Config::new(log::Level::Error)
.message_on_new_line()
.module_prefix("jirs")
});
#[cfg(debug_assertions)]
crate::shared::on_event::keydown(move |ev| {

View File

@ -0,0 +1,72 @@
use jirs_data::IssueStatusId;
use seed::prelude::*;
type EvHandler = EventHandler<crate::Msg>;
pub fn on_submit_create_column() -> EvHandler {
ev(Ev::Submit, move |ev| {
ev.prevent_default();
ev.stop_propagation();
Some(crate::Msg::PageChanged(
crate::PageChanged::ProjectSettings(crate::ProjectPageChange::SubmitIssueStatusForm),
))
})
}
pub fn on_drag_start_start_drag_column(issue_status_id: IssueStatusId) -> EvHandler {
drag_ev(Ev::DragStart, move |_| {
crate::Msg::PageChanged(crate::PageChanged::ProjectSettings(
crate::ProjectPageChange::ColumnDragStarted(issue_status_id),
))
})
}
pub fn on_drag_end_stop_drag_column(issue_status_id: IssueStatusId) -> EvHandler {
drag_ev(Ev::DragEnd, move |_| {
Some(crate::Msg::PageChanged(
crate::PageChanged::ProjectSettings(crate::ProjectPageChange::ColumnDragStopped(
issue_status_id,
)),
))
})
}
pub fn on_drag_over_exchange_position(issue_status_id: IssueStatusId) -> EvHandler {
drag_ev(Ev::DragOver, move |ev| {
ev.prevent_default();
ev.stop_propagation();
Some(crate::Msg::PageChanged(
crate::PageChanged::ProjectSettings(crate::ProjectPageChange::ColumnExchangePosition(
issue_status_id,
)),
))
})
}
pub fn on_drag_leave_leave_drag_column(issue_status_id: IssueStatusId) -> EvHandler {
drag_ev(Ev::DragLeave, move |_| {
Some(crate::Msg::PageChanged(
crate::PageChanged::ProjectSettings(crate::ProjectPageChange::ColumnDragLeave(
issue_status_id,
)),
))
})
}
pub fn on_click_edit_column(issue_status_id: IssueStatusId) -> EvHandler {
mouse_ev(Ev::Click, move |_| {
crate::Msg::PageChanged(crate::PageChanged::ProjectSettings(
crate::ProjectPageChange::EditIssueStatusName(Some(issue_status_id)),
))
})
}
pub fn on_click_delete_column(issue_status_id: IssueStatusId) -> EvHandler {
mouse_ev(Ev::Click, move |ev| {
ev.prevent_default();
ev.stop_propagation();
crate::Msg::ModalOpened(crate::ModalType::DeleteIssueStatusModal(Some(
issue_status_id,
)))
})
}

View File

@ -2,6 +2,7 @@ pub use model::*;
pub use update::*;
pub use view::*;
mod events;
mod model;
mod update;
mod view;

View File

@ -15,7 +15,7 @@ use crate::components::styled_select::{SelectVariant, StyledSelect};
use crate::components::styled_select_child::StyledSelectOption;
use crate::components::styled_textarea::StyledTextarea;
use crate::model::{self, ModalType, Model, PageContent};
use crate::pages::project_settings_page::ProjectSettingsPage;
use crate::pages::project_settings_page::{events, ProjectSettingsPage};
use crate::shared::inner_layout;
use crate::{FieldId, Msg, PageChanged, ProjectFieldId, ProjectPageChange};
@ -35,7 +35,7 @@ pub fn view(model: &model::Model) -> Node<Msg> {
let category_field = category_field(page);
let time_tracking_field = time_tracking_select(&page);
let time_tracking_field = time_tracking_select(page);
let columns_field = columns_section(model, page);
@ -252,18 +252,12 @@ fn add_column(page: &ProjectSettingsPage, column_style: &str) -> Node<Msg> {
});
if page.edit_column_id == Some(0) {
let blur = ev("focusout", |_| {
/*let blur = ev("focusout", |_| {
Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::EditIssueStatusName(None),
))
});
let on_submit = ev(Ev::Submit, move |ev| {
ev.prevent_default();
ev.stop_propagation();
Some(Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::SubmitIssueStatusForm,
)))
});
});*/
let on_submit = events::on_submit_create_column();
let input = StyledInput {
value: page.name.value.as_str(),
@ -271,7 +265,7 @@ fn add_column(page: &ProjectSettingsPage, column_style: &str) -> Node<Msg> {
auto_focus: true,
variant: InputVariant::Primary,
id: Some(FieldId::ProjectSettings(ProjectFieldId::IssueStatusName)),
input_handlers: vec![blur],
input_handlers: vec![/*blur*/],
..Default::default()
}
.render();
@ -299,17 +293,17 @@ fn column_preview(
column_style: &str,
) -> Node<Msg> {
if page.edit_column_id == Some(is.id) {
let blur = ev("focusout", |_| {
Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::EditIssueStatusName(None),
))
});
// let blur = ev("focusout", |_| {
// Msg::PageChanged(PageChanged::ProjectSettings(
// ProjectPageChange::EditIssueStatusName(None),
// ))
// });
let input = StyledInput {
value: page.name.value.as_str(),
valid: page.name.is_valid(),
variant: InputVariant::Primary,
auto_focus: true,
input_handlers: vec![blur],
input_handlers: vec![/*blur*/],
id: Some(FieldId::ProjectSettings(ProjectFieldId::IssueStatusName)),
..Default::default()
}
@ -328,46 +322,19 @@ fn show_column_preview(
column_style: &str,
) -> Node<Msg> {
let id = is.id;
let drag_started = drag_ev(Ev::DragStart, move |_| {
Some(Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::ColumnDragStarted(id),
)))
});
let drag_stopped = drag_ev(Ev::DragEnd, move |_| {
Some(Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::ColumnDragStopped(id),
)))
});
let drag_over_handler = drag_ev(Ev::DragOver, move |ev| {
ev.prevent_default();
ev.stop_propagation();
Some(Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::ColumnExchangePosition(id),
)))
});
let drag_out = drag_ev(Ev::DragLeave, move |_| {
Some(Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::ColumnDragLeave(id),
)))
});
let drag_started = events::on_drag_start_start_drag_column(is.id);
let drag_stopped = events::on_drag_end_stop_drag_column(is.id);
let drag_over_handler = events::on_drag_over_exchange_position(is.id);
let drag_out = events::on_drag_leave_leave_drag_column(is.id);
let on_edit = events::on_click_edit_column(is.id);
let on_edit = mouse_ev(Ev::Click, move |_| {
Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::EditIssueStatusName(Some(id)),
))
});
let issue_count_in_column = per_column_issue_count.get(&id).cloned().unwrap_or_default();
let delete_row = if issue_count_in_column == 0 {
let on_delete = mouse_ev(Ev::Click, move |ev| {
ev.prevent_default();
ev.stop_propagation();
Msg::ModalOpened(ModalType::DeleteIssueStatusModal(Some(id)))
});
let delete = StyledButton {
variant: ButtonVariant::Primary,
class_list: "removeColumn",
icon: Some(StyledIcon::from(Icon::Trash).render()),
on_click: Some(on_delete),
on_click: Some(events::on_click_delete_column(is.id)),
..Default::default()
}
.render();