mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Fix incorrect dirty form handling for recipe and categories
This commit is contained in:
parent
b957ed7f3a
commit
2d1c11e5d7
@ -44,6 +44,8 @@ pub fn Categories<G: Html>(cx: Scope) -> View<G> {
|
||||
let save_signal = create_signal(cx, ());
|
||||
let error_text = create_signal(cx, String::new());
|
||||
let category_text: &Signal<String> = create_signal(cx, String::new());
|
||||
let dirty = create_signal(cx, false);
|
||||
|
||||
spawn_local_scoped(cx, {
|
||||
let store = crate::api::HttpStore::get_from_context(cx);
|
||||
async move {
|
||||
@ -58,8 +60,10 @@ pub fn Categories<G: Html>(cx: Scope) -> View<G> {
|
||||
});
|
||||
|
||||
create_effect(cx, move || {
|
||||
// TODO(jwall): This is triggering on load which is not desired.
|
||||
save_signal.track();
|
||||
if !*dirty.get() {
|
||||
return;
|
||||
}
|
||||
spawn_local_scoped(cx, {
|
||||
let store = crate::api::HttpStore::get_from_context(cx);
|
||||
async move {
|
||||
@ -70,6 +74,8 @@ pub fn Categories<G: Html>(cx: Scope) -> View<G> {
|
||||
{
|
||||
error!(?e, "Failed to save categories");
|
||||
error_text.set(format!("{:?}", e));
|
||||
} else {
|
||||
dirty.set(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -94,7 +100,9 @@ pub fn Categories<G: Html>(cx: Scope) -> View<G> {
|
||||
|
||||
view! {cx,
|
||||
(dialog_view)
|
||||
textarea(bind:value=category_text, rows=20)
|
||||
textarea(bind:value=category_text, rows=20, on:change=move |_| {
|
||||
dirty.set(true);
|
||||
})
|
||||
span(role="button", on:click=move |_| {
|
||||
check_category_text_parses(category_text.get().as_str(), error_text);
|
||||
}) { "Check" } " "
|
||||
|
@ -45,10 +45,13 @@ fn Editor<G: Html>(cx: Scope, recipe: RecipeEntry) -> View<G> {
|
||||
let text = create_signal(cx, recipe.recipe_text().to_owned());
|
||||
let error_text = create_signal(cx, String::new());
|
||||
let save_signal = create_signal(cx, ());
|
||||
let dirty = create_signal(cx, false);
|
||||
|
||||
create_effect(cx, move || {
|
||||
// TODO(jwall): This is triggering on load which is not desired.
|
||||
save_signal.track();
|
||||
if !*dirty.get() {
|
||||
return;
|
||||
}
|
||||
spawn_local_scoped(cx, {
|
||||
let store = crate::api::HttpStore::get_from_context(cx);
|
||||
async move {
|
||||
@ -61,6 +64,8 @@ fn Editor<G: Html>(cx: Scope, recipe: RecipeEntry) -> View<G> {
|
||||
{
|
||||
error!(?e, "Failed to save recipe");
|
||||
error_text.set(format!("{:?}", e));
|
||||
} else {
|
||||
dirty.set(false);
|
||||
};
|
||||
}
|
||||
});
|
||||
@ -85,7 +90,9 @@ fn Editor<G: Html>(cx: Scope, recipe: RecipeEntry) -> View<G> {
|
||||
|
||||
view! {cx,
|
||||
(dialog_view)
|
||||
textarea(bind:value=text, rows=20)
|
||||
textarea(bind:value=text, rows=20, on:change=move |_| {
|
||||
dirty.set(true);
|
||||
})
|
||||
span(role="button", on:click=move |_| {
|
||||
let unparsed = text.get();
|
||||
check_recipe_parses(unparsed.as_str(), error_text.clone());
|
||||
|
Loading…
x
Reference in New Issue
Block a user