Remove load button

main
Elnu 1 year ago
parent e58fca9fa6
commit 127639355f

@ -104,8 +104,7 @@ fn KeyboardFromFile(
let file_input = create_node_ref::<Input>(cx); let file_input = create_node_ref::<Input>(cx);
let (file, set_file) = create_signal(cx, Option::<File>::None); let (file, set_file) = create_signal(cx, Option::<File>::None);
let (result_message, set_result_message) = create_signal(cx, Option::<ResultMessageData>::None); let (result_message, set_result_message) = create_signal(cx, Option::<ResultMessageData>::None);
let on_submit = move |e: SubmitEvent| { let on_submit = move || {
e.prevent_default();
spawn_local(async move { spawn_local(async move {
match read_kle_from_file(&file).await { match read_kle_from_file(&file).await {
Ok(keyboard) => { Ok(keyboard) => {
@ -119,7 +118,8 @@ fn KeyboardFromFile(
})); }));
set_keyboard(Some(keyboard)); set_keyboard(Some(keyboard));
} }
Err(err) => set_result_message(Some(ResultMessageData { Err(err) => {
set_result_message(Some(ResultMessageData {
message: view! { cx, message: view! { cx,
{ {
err.to_string() err.to_string()
@ -128,25 +128,25 @@ fn KeyboardFromFile(
.into_view(cx), .into_view(cx),
title: <ReadKleError as Into<&str>>::into(err).to_string(), title: <ReadKleError as Into<&str>>::into(err).to_string(),
colorway: Colorway::Bad, colorway: Colorway::Bad,
})), }));
file_input().unwrap().set_value("");
},
} }
}); });
}; };
view! { cx, view! { cx,
<h3>"Load KLE JSON from file"</h3> <h3>"Load KLE JSON from file"</h3>
<ResultMessage message=result_message /> <ResultMessage message=result_message />
<form class="f-row align-items:center" on:submit=on_submit> <form class="f-row align-items:center">
<input <input
type="file" type="file"
accept="application/json" accept="application/json"
node_ref=file_input node_ref=file_input
on:change=move |_| { on:change=move |_| {
set_file(file_input().unwrap().files().map(|files| files.get(0)).flatten()); set_file(file_input().unwrap().files().map(|files| files.get(0)).flatten());
on_submit();
} }
/> />
<Show when=move || file().is_some() fallback=move |_| {}>
<input type="submit" value="Load" />
</Show>
</form> </form>
} }
} }

Loading…
Cancel
Save