-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use yew::prelude::*; | ||
|
||
use crate::{wages_param::WagesParam, criterias::Criteria, slider_component::{Slider, SliderMessage, SliderCoefMessage}}; | ||
|
||
#[derive(Properties, PartialEq)] | ||
pub struct Props { | ||
pub wages_param: Vec<WagesParam>, | ||
pub criterias: Vec<Criteria>, | ||
pub on_parameter_slide: Callback<Vec<WagesParam>>, | ||
pub on_coef_slide: Callback<Vec<Criteria>>, | ||
} | ||
|
||
#[function_component] | ||
pub fn JobSliders(props: &Props) -> Html { | ||
|
||
let wages_param = props.wages_param.clone(); | ||
let on_parameter_slide = props.on_parameter_slide.clone(); | ||
let criterias = props.criterias.clone(); | ||
let on_coef_slide: Callback<Vec<Criteria>> = props.on_coef_slide.clone(); | ||
|
||
let on_param_value_slide: Callback<SliderMessage> = { | ||
Callback::from(move |msg: SliderMessage| { | ||
let mut new_params = wages_param.clone(); | ||
let param = new_params | ||
.iter_mut() | ||
.find(|param| param.id == msg.id) | ||
.expect(format!("param not found : {} ", msg.id).as_str()); | ||
param.value = msg.value; | ||
on_parameter_slide.emit(new_params); | ||
}) | ||
}; | ||
|
||
|
||
let on_coef_slide: Callback<SliderCoefMessage> = { | ||
Callback::from(move |msg: SliderCoefMessage| { | ||
let mut crit_state = criterias.clone(); | ||
let criteria = crit_state | ||
.iter_mut() | ||
.find(|criteria| criteria.id == msg.id) | ||
.expect(format!("criteria not found : {} ", msg.id).as_str()); | ||
criteria.coefficient = msg.coef; | ||
on_coef_slide.emit(crit_state); | ||
}) | ||
}; | ||
|
||
html! { | ||
<div class="contentBlock"> | ||
<div class="w3-row parameterHeader"> | ||
<div class="w3-half">{ "Criteria" }</div> | ||
<div class="w3-quarter">{ "my job" }</div> | ||
<div class="w3-quarter">{ "How it maters" }</div> | ||
</div> | ||
if props.criterias.len() == props.wages_param.len() { | ||
<div> | ||
{ | ||
for props.criterias.clone().into_iter().map(|criteria: Criteria| { | ||
let param = props.wages_param.clone().into_iter().find(|param| param.id == criteria.id).unwrap(); | ||
html! { | ||
<div> | ||
<Slider on_parameter_slide={on_param_value_slide.clone()} on_coef_slide={on_coef_slide.clone()} wages_param={param} criteria={criteria} /> | ||
</div> | ||
} | ||
}) | ||
} | ||
</div> | ||
} else { | ||
<div>{"loading or data mismatch somewhere..."}</div> | ||
} | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters