mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Fix issue #14
This commit is contained in:
parent
a1fc1125a0
commit
1396c54cdd
@ -52,7 +52,7 @@ where
|
|||||||
fn get_user_store(&self, user: String) -> S;
|
fn get_user_store(&self, user: String) -> S;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct RecipeEntry(pub String, pub String);
|
pub struct RecipeEntry(pub String, pub String);
|
||||||
|
|
||||||
impl RecipeEntry {
|
impl RecipeEntry {
|
||||||
|
@ -41,7 +41,7 @@ fn check_recipe_parses(text: &str, error_text: &Signal<String>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Editor<G: Html>(cx: Scope, recipe: &RecipeEntry) -> View<G> {
|
fn Editor<G: Html>(cx: Scope, recipe: RecipeEntry) -> View<G> {
|
||||||
let id = create_signal(cx, recipe.recipe_id().to_owned());
|
let id = create_signal(cx, recipe.recipe_id().to_owned());
|
||||||
let text = create_signal(cx, recipe.recipe_text().to_owned());
|
let text = create_signal(cx, recipe.recipe_text().to_owned());
|
||||||
let error_text = create_signal(cx, String::new());
|
let error_text = create_signal(cx, String::new());
|
||||||
@ -87,11 +87,11 @@ fn Editor<G: Html>(cx: Scope, recipe: &RecipeEntry) -> View<G> {
|
|||||||
view! {cx,
|
view! {cx,
|
||||||
(dialog_view)
|
(dialog_view)
|
||||||
textarea(bind:value=text, rows=20)
|
textarea(bind:value=text, rows=20)
|
||||||
a(role="button" , href="#", on:click=move |_| {
|
span(role="button", on:click=move |_| {
|
||||||
let unparsed = text.get();
|
let unparsed = text.get();
|
||||||
check_recipe_parses(unparsed.as_str(), error_text.clone());
|
check_recipe_parses(unparsed.as_str(), error_text.clone());
|
||||||
}) { "Check" } " "
|
}) { "Check" } " "
|
||||||
a(role="button", href="#", on:click=move |_| {
|
span(role="button", on:click=move |_| {
|
||||||
let unparsed = text.get();
|
let unparsed = text.get();
|
||||||
if check_recipe_parses(unparsed.as_str(), error_text.clone()) {
|
if check_recipe_parses(unparsed.as_str(), error_text.clone()) {
|
||||||
debug!("triggering a save");
|
debug!("triggering a save");
|
||||||
@ -144,6 +144,12 @@ pub fn Recipe<'ctx, G: Html>(cx: Scope<'ctx>, recipe_id: String) -> View<G> {
|
|||||||
.expect(&format!("No recipe counts for recipe id: {}", recipe_id))
|
.expect(&format!("No recipe counts for recipe id: {}", recipe_id))
|
||||||
.get(&recipe_id)
|
.get(&recipe_id)
|
||||||
{
|
{
|
||||||
|
let recipe_text = create_signal(
|
||||||
|
cx,
|
||||||
|
app_service
|
||||||
|
.fetch_recipe_text(recipe_id.as_str())
|
||||||
|
.expect("No such recipe"),
|
||||||
|
);
|
||||||
let recipe = create_signal(cx, recipe.clone());
|
let recipe = create_signal(cx, recipe.clone());
|
||||||
let title = create_memo(cx, move || recipe.get().title.clone());
|
let title = create_memo(cx, move || recipe.get().title.clone());
|
||||||
let desc = create_memo(cx, move || {
|
let desc = create_memo(cx, move || {
|
||||||
@ -156,37 +162,31 @@ pub fn Recipe<'ctx, G: Html>(cx: Scope<'ctx>, recipe_id: String) -> View<G> {
|
|||||||
});
|
});
|
||||||
let steps = create_memo(cx, move || recipe.get().steps.clone());
|
let steps = create_memo(cx, move || recipe.get().steps.clone());
|
||||||
create_effect(cx, move || {
|
create_effect(cx, move || {
|
||||||
|
debug!("Choosing edit or view for recipe.");
|
||||||
if *show_edit.get() {
|
if *show_edit.get() {
|
||||||
return;
|
{
|
||||||
}
|
debug!("Showing editor for recipe.");
|
||||||
view.set(view! {cx,
|
view.set(view! {cx,
|
||||||
div(class="recipe") {
|
Editor(recipe_text.get().as_ref().clone().unwrap())
|
||||||
h1(class="recipe_title") { (title.get()) }
|
});
|
||||||
div(class="recipe_description") {
|
|
||||||
(desc.get())
|
|
||||||
}
|
|
||||||
Steps(steps)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if let Some(entry) = app_service
|
|
||||||
.fetch_recipe_text(recipe_id.as_str())
|
|
||||||
.expect("No such recipe")
|
|
||||||
{
|
|
||||||
let entry_ref = create_ref(cx, entry);
|
|
||||||
create_effect(cx, move || {
|
|
||||||
if !(*show_edit.get()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
debug!("Showing text for recipe.");
|
||||||
view.set(view! {cx,
|
view.set(view! {cx,
|
||||||
Editor(entry_ref)
|
div(class="recipe") {
|
||||||
|
h1(class="recipe_title") { (title.get()) }
|
||||||
|
div(class="recipe_description") {
|
||||||
|
(desc.get())
|
||||||
|
}
|
||||||
|
Steps(steps)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
view! {cx,
|
view! {cx,
|
||||||
a(role="button", href="#", on:click=move |_| { show_edit.set(true); }) { "Edit" } " "
|
span(role="button", on:click=move |_| { show_edit.set(true); }) { "Edit" } " "
|
||||||
a(role="button", href="#", on:click=move |_| { show_edit.set(false); }) { "View" }
|
span(role="button", on:click=move |_| { show_edit.set(false); }) { "View" }
|
||||||
(view.get().as_ref())
|
(view.get().as_ref())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user