Skip to content

Commit

Permalink
🩹 fix if no param data
Browse files Browse the repository at this point in the history
  • Loading branch information
ad2ien committed Oct 14, 2023
1 parent 37543cc commit 61c5940
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def criterias():
data = json.load(file)
return data

@app.route('/params')
def params():
print("get params")

with open('data.csv', 'r') as file:
content = file.read()
return content

if __name__ == '__main__':
app.run(port=1984)
22 changes: 15 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,22 @@ fn App() -> Html {
<div class="w3-quarter">{ "my job" }</div>
<div class="w3-quarter">{ "How it maters" }</div>
</div>
{ for (*criterias_state_5).clone().into_iter().map(|criteria: Criteria| {
let param = (*parameter_state).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()} salary_param={param} criteria={criteria} />
</div>
if (*criterias_state_5).len() == (*parameter_state).len() {
<div>
{
for (*criterias_state_5).clone().into_iter().map(|criteria: Criteria| {
let param = (*parameter_state).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()} salary_param={param} criteria={criteria} />
</div>
}
})
}
})}
</div>
} else {
<div>{"loading or data mismatch somewhere..."}</div>
}
</div>
</div>
}
Expand Down
6 changes: 5 additions & 1 deletion src/salary_param.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#[derive(Copy, Clone, Debug)]
use serde::Deserialize;

const _PARAM_DATA_URL: &str = "http://localhost:1984/params";

#[derive(Clone, Debug, Deserialize)]
pub struct SalaryParam {
pub id: &'static str,
pub value: i8,
Expand Down
3 changes: 2 additions & 1 deletion src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn Slider(props: &Props) -> Html {
let coef_value = (*coef_value_handle).clone();

let salary_param = props.salary_param.clone();
let salary_param_2 = props.salary_param.clone();
let criteria = props.criteria.clone();

let cb_value_handle = props.on_parameter_slide.clone();
Expand All @@ -55,7 +56,7 @@ pub fn Slider(props: &Props) -> Html {
if let Some(input) = input {
coef_value_handle.set(input.value());
cb_coef_handle.emit( SliderCoefMessage {
id: salary_param.id.to_string(),
id: salary_param_2.id.to_string(),
coef: input.value().parse::<f64>().expect("expected number")
});
}
Expand Down

0 comments on commit 61c5940

Please sign in to comment.