// Disabled: update user profile is now made with a post data ('edit_user_post').
// .route("/user/update", put(services::ron::update_user))
.route("/set_lang", put(services::ron::set_lang))
- .route("/recipe/get_titles", get(services::ron::recipe::get_titles))
- .route("/recipe/set_title", patch(services::ron::recipe::set_title))
+ .route("/recipe/titles", get(services::ron::recipe::get_titles))
+ .route("/recipe/title", patch(services::ron::recipe::set_title))
.route(
- "/recipe/set_description",
+ "/recipe/description",
patch(services::ron::recipe::set_description),
)
.route(
- "/recipe/set_servings",
+ "/recipe/servings",
patch(services::ron::recipe::set_servings),
)
.route(
- "/recipe/set_estimated_time",
+ "/recipe/estimated_time",
patch(services::ron::recipe::set_estimated_time),
)
- .route("/recipe/get_tags", get(services::ron::recipe::get_tags))
- .route("/recipe/add_tags", post(services::ron::recipe::add_tags))
- .route("/recipe/rm_tags", delete(services::ron::recipe::rm_tags))
.route(
- "/recipe/set_difficulty",
+ "/recipe/tags",
+ get(services::ron::recipe::get_tags)
+ .post(services::ron::recipe::add_tags)
+ .delete(services::ron::recipe::rm_tags),
+ )
+ .route(
+ "/recipe/difficulty",
patch(services::ron::recipe::set_difficulty),
)
.route(
- "/recipe/set_language",
+ "/recipe/language",
patch(services::ron::recipe::set_language),
)
.route(
- "/recipe/set_is_published",
+ "/recipe/is_published",
patch(services::ron::recipe::set_is_published),
)
- .route("/recipe/remove", delete(services::ron::recipe::rm))
- .route("/recipe/get_groups", get(services::ron::recipe::get_groups))
- .route("/recipe/add_group", post(services::ron::recipe::add_group))
+ .route("/recipe", delete(services::ron::recipe::rm))
+ .route("/recipe/groups", get(services::ron::recipe::get_groups))
.route(
- "/recipe/remove_group",
- delete(services::ron::recipe::rm_group),
+ "/recipe/group",
+ post(services::ron::recipe::add_group).delete(services::ron::recipe::rm_group),
)
.route(
- "/recipe/set_group_name",
+ "/recipe/group_name",
patch(services::ron::recipe::set_group_name),
)
.route(
- "/recipe/set_group_comment",
+ "/recipe/group_comment",
patch(services::ron::recipe::set_group_comment),
)
.route(
- "/recipe/set_groups_order",
+ "/recipe/groups_order",
patch(services::ron::recipe::set_groups_order),
)
- .route("/recipe/add_step", post(services::ron::recipe::add_step))
.route(
- "/recipe/remove_step",
- delete(services::ron::recipe::rm_step),
+ "/recipe/step",
+ post(services::ron::recipe::add_step).delete(services::ron::recipe::rm_step),
)
.route(
- "/recipe/set_step_action",
+ "/recipe/step_action",
patch(services::ron::recipe::set_step_action),
)
.route(
- "/recipe/set_steps_order",
+ "/recipe/steps_order",
patch(services::ron::recipe::set_steps_order),
)
.route(
- "/recipe/add_ingredient",
- post(services::ron::recipe::add_ingredient),
- )
- .route(
- "/recipe/remove_ingredient",
- delete(services::ron::recipe::rm_ingredient),
+ "/recipe/ingredient",
+ post(services::ron::recipe::add_ingredient)
+ .delete(services::ron::recipe::rm_ingredient),
)
.route(
- "/recipe/set_ingredient_name",
+ "/recipe/ingredient_name",
patch(services::ron::recipe::set_ingredient_name),
)
.route(
- "/recipe/set_ingredient_comment",
+ "/recipe/ingredient_comment",
patch(services::ron::recipe::set_ingredient_comment),
)
.route(
- "/recipe/set_ingredient_quantity",
+ "/recipe/ingredient_quantity",
patch(services::ron::recipe::set_ingredient_quantity),
)
.route(
- "/recipe/set_ingredient_unit",
+ "/recipe/ingredient_unit",
patch(services::ron::recipe::set_ingredient_unit),
)
.route(
- "/recipe/set_ingredients_order",
+ "/recipe/ingredients_order",
patch(services::ron::recipe::set_ingredients_order),
)
.route(
- "/calendar/get_scheduled_recipes",
+ "/calendar/scheduled_recipes",
get(services::ron::calendar::get_scheduled_recipes),
)
.route(
"/calendar/schedule_recipe",
- post(services::ron::calendar::schedule_recipe),
- )
- .route(
- "/calendar/remove_scheduled_recipe",
- delete(services::ron::calendar::rm_scheduled_recipe),
- )
- .route(
- "/shopping_list/get_list",
- get(services::ron::shopping_list::get),
+ post(services::ron::calendar::schedule_recipe)
+ .delete(services::ron::calendar::rm_scheduled_recipe),
)
+ .route("/shopping_list", get(services::ron::shopping_list::get))
.route(
- "/shopping_list/set_checked",
+ "/shopping_list/checked",
patch(services::ron::shopping_list::set_entry_checked),
)
.fallback(services::ron::not_found);
scanf = "1.2"
-wasm-bindgen = "0.2"
-wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [
"console",
"Document",
"KeyboardEvent",
"Element",
"DomStringMap",
+ "HtmlDocument",
"HtmlElement",
"HtmlDivElement",
"HtmlLabelElement",
"HtmlDialogElement",
] }
-gloo = "0.11"
+gloo = { version = "0.11", features = ["futures"] }
+
+wasm-cookies = "0.2"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1", optional = true }
+wasm-bindgen = "0.2"
+wasm-bindgen-futures = "0.4"
date,
remove_ingredients_from_shopping_list,
};
- let _ =
- request::delete::<(), _>("calendar/remove_scheduled_recipe", body).await;
+ let _ = request::delete::<(), _>("calendar/scheduled_recipe", body).await;
window().location().reload().unwrap();
}
});
// Dark/light theme handling.
let toggle_theme: HtmlInputElement = selector("#toggle-theme input");
EventListener::new(&toggle_theme.clone(), "change", move |_event| {
- wasm_cookies::set(
- common::consts::COOKIE_DARK_THEME,
- &(!toggle_theme.checked()).to_string(),
- &wasm_cookies::CookieOptions {
- path: Some("/"),
- domain: None,
- expires: None,
- secure: false,
- same_site: wasm_cookies::SameSite::Strict,
- },
- );
+ set_cookie_dark_theme(!toggle_theme.checked());
window().location().reload().unwrap();
})
.forget();
Ok(())
}
+
+/// `wasm_cookies::set` is specific for the wasm32 target architecture and Rust Analyzer says
+/// it's an error, it's not possible to configure different target configurations into the same
+/// workspace. Here is the issue:
+/// https://users.rust-lang.org/t/can-i-configure-rust-analyzer-vscode-to-use-a-different-target-for-different-crates-in-my-workspce/123661
+#[cfg(target_arch = "wasm32")]
+fn set_cookie_dark_theme(dark_theme: bool) {
+ wasm_cookies::set(
+ common::consts::COOKIE_DARK_THEME,
+ &dark_theme.to_string(),
+ &wasm_cookies::CookieOptions {
+ path: Some("/"),
+ domain: None,
+ expires: None,
+ secure: false,
+ same_site: wasm_cookies::SameSite::Strict,
+ },
+ );
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+fn set_cookie_dark_theme(_dark_theme: bool) {}
title: title.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_title", body).await;
+ let _ = request::patch::<(), _>("recipe/title", body).await;
reload_recipes_list(recipe_id).await;
});
}
description: description.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_description", body).await;
+ let _ = request::patch::<(), _>("recipe/description", body).await;
});
}
})
servings,
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_servings", body).await;
+ let _ = request::patch::<(), _>("recipe/servings", body).await;
});
}
})
estimated_time: time,
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_estimated_time", body).await;
+ let _ = request::patch::<(), _>("recipe/estimated_time", body).await;
});
}
})
.unwrap(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_difficulty", body).await;
+ let _ = request::patch::<(), _>("recipe/difficulty", body).await;
});
}
})
{
spawn_local(async move {
let tags: ron_api::Tags = request::get(
- "recipe/get_tags",
+ "recipe/tags",
ron_api::Id { id: recipe_id }, /*[("id", &recipe_id.to_string())]*/
)
.await
recipe_id,
tags: tag_list.clone(),
};
- let _ = request::post::<(), _>("recipe/add_tags", body).await;
+ let _ = request::post::<(), _>("recipe/tags", body).await;
create_tag_elements(recipe_id, &tag_list);
}
by_id::<HtmlInputElement>("input-tags").set_value("");
lang: language.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_language", body).await;
+ let _ = request::patch::<(), _>("recipe/language", body).await;
});
}
})
is_published: is_published.checked(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_is_published", body).await;
+ let _ = request::patch::<(), _>("recipe/is_published", body).await;
reload_recipes_list(recipe_id).await;
});
})
.is_some()
{
let body = ron_api::Id { id: recipe_id };
- let _ = request::delete::<(), _>("recipe/remove", body).await;
+ let _ = request::delete::<(), _>("recipe", body).await;
window()
.location()
.set_href(&format!("/{}/", get_current_lang()))
{
spawn_local(async move {
let groups: Vec<common::ron_api::Group> =
- request::get("recipe/get_groups", ron_api::Id { id: recipe_id })
+ request::get("recipe/groups", ron_api::Id { id: recipe_id })
.await
.unwrap();
EventListener::new(&button_add_group, "click", move |_event| {
let body = ron_api::Id { id: recipe_id };
spawn_local(async move {
- let response: ron_api::Id = request::post("recipe/add_group", body).await.unwrap();
+ let response: ron_api::Id = request::post("recipe/group", body).await.unwrap();
create_group_element(&ron_api::Group {
id: response.id,
name: "".to_string(),
.collect();
let body = ron_api::Ids { ids };
- let _ = request::patch::<(), _>("recipe/set_groups_order", body).await;
+ let _ = request::patch::<(), _>("recipe/groups_order", body).await;
});
});
name: name.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_group_name", body).await;
+ let _ = request::patch::<(), _>("recipe/group_name", body).await;
})
}
})
comment: comment.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_group_comment", body).await;
+ let _ = request::patch::<(), _>("recipe/group_comment", body).await;
});
}
})
.is_some()
{
let body = ron_api::Id { id: group_id };
- let _ = request::delete::<(), _>("recipe/remove_group", body).await;
+ let _ = request::delete::<(), _>("recipe/group", body).await;
let group_element = by_id::<Element>(&format!("group-{}", group_id));
group_element.next_element_sibling().unwrap().remove();
group_element.remove();
EventListener::new(&add_step_button, "click", move |_event| {
spawn_local(async move {
let body = ron_api::Id { id: group_id };
- let response: ron_api::Id = request::post("recipe/add_step", body).await.unwrap();
+ let response: ron_api::Id = request::post("recipe/step", body).await.unwrap();
create_step_element(
&selector::<Element>(&format!("#group-{} .steps", group_id)),
&ron_api::Step {
recipe_id,
tags: vec![tag],
};
- let _ = request::delete::<(), _>("recipe/rm_tags", body).await;
+ let _ = request::delete::<(), _>("recipe/tags", body).await;
tag_span.remove();
});
})
.collect();
let body = ron_api::Ids { ids };
- let _ = request::patch::<(), _>("recipe/set_steps_order", body).await;
+ let _ = request::patch::<(), _>("recipe/steps_order", body).await;
});
});
action: action.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_step_action", body).await;
+ let _ = request::patch::<(), _>("recipe/step_action", body).await;
});
}
})
.is_some()
{
let body = ron_api::Id { id: step_id };
- let _ = request::delete::<(), _>("recipe/remove_step", body).await;
+ let _ = request::delete::<(), _>("recipe/step", body).await;
let step_element = by_id::<Element>(&format!("step-{}", step_id));
step_element.next_element_sibling().unwrap().remove();
step_element.remove();
EventListener::new(&add_ingredient_button, "click", move |_event| {
spawn_local(async move {
let body = ron_api::Id { id: step_id };
- let response: ron_api::Id = request::post("recipe/add_ingredient", body).await.unwrap();
+ let response: ron_api::Id = request::post("recipe/ingredient", body).await.unwrap();
create_ingredient_element(
&selector::<Element>(&format!("#step-{} .ingredients", step_id)),
&ron_api::Ingredient {
.collect();
let body = ron_api::Ids { ids };
- let _ = request::patch::<(), _>("recipe/set_ingredients_order", body).await;
+ let _ = request::patch::<(), _>("recipe/ingredients_order", body).await;
});
});
name: name.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_ingredient_name", body).await;
+ let _ = request::patch::<(), _>("recipe/ingredient_name", body).await;
});
}
})
comment: comment.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_ingredient_comment", body).await;
+ let _ = request::patch::<(), _>("recipe/ingredient_comment", body).await;
});
}
})
quantity: q,
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_ingredient_quantity", body).await;
+ let _ = request::patch::<(), _>("recipe/ingredient_quantity", body).await;
});
}
})
unit: unit.value(),
};
spawn_local(async move {
- let _ = request::patch::<(), _>("recipe/set_ingredient_unit", body).await;
+ let _ = request::patch::<(), _>("recipe/ingredient_unit", body).await;
});
}
})
.is_some()
{
let body = ron_api::Id { id: ingredient_id };
- let _ = request::delete::<(), _>("recipe/remove_ingredient", body).await;
+ let _ = request::delete::<(), _>("recipe/ingredient", body).await;
let ingredient_element = by_id::<Element>(&format!("ingredient-{}", ingredient_id));
ingredient_element.next_element_sibling().unwrap().remove();
ingredient_element.remove();
}
let titles: ron_api::Strings = request::get(
- "recipe/get_titles",
+ "recipe/titles",
ron_api::Ids {
ids: recipe_ids_and_dates
.iter()
.collect::<Vec<_>>())
} else {
let scheduled_recipes: ron_api::ScheduledRecipes = request::get(
- "calendar/get_scheduled_recipes",
+ "calendar/scheduled_recipes",
ron_api::DateRange {
start_date,
end_date,
if self.is_local {
Ok(vec![]) // TODO
} else {
- Ok(request::get("shopping_list/get_list", ()).await?)
+ Ok(request::get("shopping_list", ()).await?)
}
}
todo!();
} else {
request::patch(
- "shopping_list/set_checked",
+ "shopping_list/checked",
ron_api::Value {
id: item_id,
value: is_checked,