Fix redundant rebuild Project page

This commit is contained in:
eraden 2021-04-30 23:08:39 +02:00
parent 10bda7bb9c
commit 146be0184b
4 changed files with 36 additions and 17 deletions

View File

@ -1,8 +1,9 @@
use jirs_data::WsMsg;
use seed::app::Orders;
use crate::model::{Model, Page, PageContent};
use crate::pages::epics_page::EpicsPage;
use crate::ws::board_load;
use crate::ws::{board_load, send_ws_msg};
use crate::{Msg, OperationKind, ResourceKind};
pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Orders<Msg>) {
@ -13,14 +14,17 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
if matches!(model.page, Page::IssuesAndFilters)
&& !matches!(model.page_content, PageContent::IssuesAndFilters(..))
{
build_page_content(model);
build_page_content(model, orders);
}
match msg {
Msg::ResourceChanged(ResourceKind::Auth, OperationKind::SingleLoaded, Some(_))
| Msg::ChangePage(Page::Epics) => {
board_load(model, orders);
build_page_content(model);
build_page_content(model, orders);
}
Msg::ResourceChanged(ResourceKind::IssueStatus, OperationKind::ListLoaded, _) => {
//
}
Msg::ResourceChanged(ResourceKind::Issue, OperationKind::ListLoaded, ..) => {
let hash = EpicsPage::build_issues_per_epic(model);
@ -30,9 +34,10 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
}
}
fn build_page_content(model: &mut Model) {
fn build_page_content(model: &mut Model, orders: &mut impl Orders<Msg>) {
if matches!(model.page_content, PageContent::Epics(..)) {
return;
}
model.page_content = PageContent::Epics(Box::new(super::EpicsPage::new(model)));
send_ws_msg(WsMsg::IssueStatusesLoad, model.ws.as_ref(), orders);
}

View File

@ -1,5 +1,5 @@
use chrono::NaiveDateTime;
use jirs_data::Issue;
use jirs_data::{Issue, IssueStatus};
use seed::prelude::*;
use seed::*;
@ -42,7 +42,10 @@ pub fn view(model: &Model) -> Node<Msg> {
C!["issues"],
issues
.into_iter()
.map(|issue| render_issue(issue))
.map(|issue| render_issue(
issue,
model.issue_statuses_by_id.get(&issue.issue_status_id)
))
.collect::<Vec<Node<Msg>>>()
]
]
@ -76,10 +79,16 @@ fn date_field(
}
}
fn render_issue(issue: &Issue) -> Node<Msg> {
fn render_issue(issue: &Issue, status: Option<&IssueStatus>) -> Node<Msg> {
div![
C!["issue"],
div![C!["name"], issue.title.as_str()],
div![
C!["status"],
status
.map(|status| status.name.as_str())
.unwrap_or_default()
],
div![
C!["flags"],
div![

View File

@ -127,5 +127,8 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
}
fn build_page_content(model: &mut Model) {
if matches!(model.page_content, PageContent::Project(..)) {
return;
}
model.page_content = PageContent::Project(Box::new(ProjectPage::default()));
}

View File

@ -17,8 +17,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
match msg {
Msg::ProjectChanged(Some(_)) => {
build_page_content(model);
send_ws_msg(WsMsg::IssueStatusesLoad, model.ws.as_ref(), orders);
build_page_content(model, orders);
}
Msg::WebSocketChange(ref change) => match change {
WebSocketChanged::WsMsg(WsMsg::AuthorizeLoaded(..)) => {
@ -35,7 +34,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
_ => (),
},
Msg::ChangePage(Page::ProjectSettings) => {
build_page_content(model);
build_page_content(model, orders);
if model.user.is_some() {
board_load(model, orders);
}
@ -55,8 +54,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
if matches!(model.page, Page::ProjectSettings)
&& !matches!(model.page_content, PageContent::ProjectSettings(..))
{
build_page_content(model);
send_ws_msg(WsMsg::IssueStatusesLoad, model.ws.as_ref(), orders);
build_page_content(model, orders);
}
let page = match_page_mut!(model, ProjectSettings);
@ -80,8 +78,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
FieldId::ProjectSettings(ProjectFieldId::Category),
StyledSelectChanged::Changed(Some(value)),
) => {
let category = value.into();
page.payload.category = Some(category);
page.payload.category = Some(value.into());
}
Msg::PageChanged(PageChanged::ProjectSettings(
ProjectPageChange::SubmitProjectSettingsForm,
@ -174,7 +171,7 @@ fn exchange_position(bellow_id: IssueStatusId, model: &mut Model) {
}
let dragged_id = match page.column_drag.dragged_id.as_ref().cloned() {
Some(id) => id,
_ => return error!("Nothing is dragged"),
_ => return log::error!("Nothing is dragged"),
};
let mut below = None;
@ -221,7 +218,7 @@ fn sync(model: &mut Model, orders: &mut impl Orders<Msg>) {
std::mem::swap(&mut old, &mut page.column_drag.dirty);
old
}
_ => return error!("bad content type"),
_ => return log::error!("bad content type"),
};
for id in dirty {
let IssueStatus { name, position, .. } =
@ -237,7 +234,10 @@ fn sync(model: &mut Model, orders: &mut impl Orders<Msg>) {
}
}
fn build_page_content(model: &mut Model) {
fn build_page_content(model: &mut Model, orders: &mut impl Orders<Msg>) {
if matches!(model.page_content, PageContent::ProjectSettings(..)) {
return;
}
if let Some(project) = &model.project {
let mode = model
.user_settings
@ -247,4 +247,6 @@ fn build_page_content(model: &mut Model) {
model.page_content =
PageContent::ProjectSettings(Box::new(ProjectSettingsPage::new(mode, project)));
}
send_ws_msg(WsMsg::IssueStatusesLoad, model.ws.as_ref(), orders);
}