Remove useless verbs in web api urls
This commit is contained in:
parent
559ed139aa
commit
315626b3ed
7 changed files with 100 additions and 94 deletions
|
|
@ -24,8 +24,6 @@ futures = "0.3"
|
|||
|
||||
scanf = "1.2"
|
||||
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
web-sys = { version = "0.3", features = [
|
||||
"console",
|
||||
"Document",
|
||||
|
|
@ -40,6 +38,7 @@ web-sys = { version = "0.3", features = [
|
|||
"KeyboardEvent",
|
||||
"Element",
|
||||
"DomStringMap",
|
||||
"HtmlDocument",
|
||||
"HtmlElement",
|
||||
"HtmlDivElement",
|
||||
"HtmlLabelElement",
|
||||
|
|
@ -49,10 +48,14 @@ web-sys = { version = "0.3", features = [
|
|||
"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"
|
||||
|
|
|
|||
|
|
@ -176,8 +176,7 @@ pub fn setup(
|
|||
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();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -83,20 +83,32 @@ pub fn main() -> Result<(), JsValue> {
|
|||
// 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) {}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
description: description.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_description", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/description", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -87,7 +87,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
servings,
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_servings", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/servings", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -119,7 +119,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
estimated_time: time,
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_estimated_time", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/estimated_time", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -143,7 +143,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
.unwrap(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_difficulty", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/difficulty", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -154,7 +154,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
{
|
||||
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
|
||||
|
|
@ -171,7 +171,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
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("");
|
||||
|
|
@ -219,7 +219,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
lang: language.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_language", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/language", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -235,7 +235,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
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;
|
||||
});
|
||||
})
|
||||
|
|
@ -261,7 +261,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
.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()))
|
||||
|
|
@ -275,7 +275,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
{
|
||||
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();
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ pub fn setup_page(recipe_id: i64) {
|
|||
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(),
|
||||
|
|
@ -333,7 +333,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
|||
.collect();
|
||||
|
||||
let body = ron_api::Ids { ids };
|
||||
let _ = request::patch::<(), _>("recipe/set_groups_order", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/groups_order", body).await;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -349,7 +349,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
|||
name: name.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_group_name", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/group_name", body).await;
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
@ -367,7 +367,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
|||
comment: comment.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_group_comment", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/group_comment", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -393,7 +393,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
|||
.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();
|
||||
|
|
@ -407,7 +407,7 @@ fn create_group_element(group: &ron_api::Group) -> Element {
|
|||
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 {
|
||||
|
|
@ -468,7 +468,7 @@ where
|
|||
recipe_id,
|
||||
tags: vec![tag],
|
||||
};
|
||||
let _ = request::delete::<(), _>("recipe/rm_tags", body).await;
|
||||
let _ = request::delete::<(), _>("recipe/tags", body).await;
|
||||
tag_span.remove();
|
||||
});
|
||||
})
|
||||
|
|
@ -494,7 +494,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
|
|||
.collect();
|
||||
|
||||
let body = ron_api::Ids { ids };
|
||||
let _ = request::patch::<(), _>("recipe/set_steps_order", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/steps_order", body).await;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -510,7 +510,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
|
|||
action: action.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_step_action", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/step_action", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -536,7 +536,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
|
|||
.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();
|
||||
|
|
@ -550,7 +550,7 @@ fn create_step_element(group_element: &Element, step: &ron_api::Step) -> Element
|
|||
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 {
|
||||
|
|
@ -586,7 +586,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
.collect();
|
||||
|
||||
let body = ron_api::Ids { ids };
|
||||
let _ = request::patch::<(), _>("recipe/set_ingredients_order", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/ingredients_order", body).await;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -602,7 +602,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
name: name.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_ingredient_name", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/ingredient_name", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -620,7 +620,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
comment: comment.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_ingredient_comment", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/ingredient_comment", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -647,7 +647,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
quantity: q,
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_ingredient_quantity", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/ingredient_quantity", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -665,7 +665,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
unit: unit.value(),
|
||||
};
|
||||
spawn_local(async move {
|
||||
let _ = request::patch::<(), _>("recipe/set_ingredient_unit", body).await;
|
||||
let _ = request::patch::<(), _>("recipe/ingredient_unit", body).await;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
|
@ -691,7 +691,7 @@ fn create_ingredient_element(step_element: &Element, ingredient: &ron_api::Ingre
|
|||
.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();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ impl RecipeScheduler {
|
|||
}
|
||||
|
||||
let titles: ron_api::Strings = request::get(
|
||||
"recipe/get_titles",
|
||||
"recipe/titles",
|
||||
ron_api::Ids {
|
||||
ids: recipe_ids_and_dates
|
||||
.iter()
|
||||
|
|
@ -98,7 +98,7 @@ impl RecipeScheduler {
|
|||
.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,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ impl ShoppingList {
|
|||
if self.is_local {
|
||||
Ok(vec![]) // TODO
|
||||
} else {
|
||||
Ok(request::get("shopping_list/get_list", ()).await?)
|
||||
Ok(request::get("shopping_list", ()).await?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ impl ShoppingList {
|
|||
todo!();
|
||||
} else {
|
||||
request::patch(
|
||||
"shopping_list/set_checked",
|
||||
"shopping_list/checked",
|
||||
ron_api::Value {
|
||||
id: item_id,
|
||||
value: is_checked,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue