Calendar is now displayed on home page and recipes can be scheduled without being logged
This commit is contained in:
parent
ccb1248da3
commit
37721ac3ea
22 changed files with 538 additions and 166 deletions
|
|
@ -1,8 +1,5 @@
|
|||
use common::ron_api;
|
||||
use gloo::{
|
||||
console::log,
|
||||
net::http::{Request, RequestBuilder},
|
||||
};
|
||||
use gloo::net::http::{Request, RequestBuilder};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -42,20 +39,18 @@ where
|
|||
send_req(request_builder.body(ron_api::to_string(body))?).await
|
||||
}
|
||||
|
||||
async fn req_with_params<'a, T, U, V>(
|
||||
async fn req_with_params<T, U>(
|
||||
api_name: &str,
|
||||
params: U,
|
||||
method_fn: fn(&str) -> RequestBuilder,
|
||||
) -> Result<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
U: IntoIterator<Item = (&'a str, V)>,
|
||||
V: AsRef<str>,
|
||||
U: Serialize,
|
||||
{
|
||||
let url = format!("/ron-api/{}", api_name);
|
||||
let request_builder = method_fn(&url)
|
||||
.header(CONTENT_TYPE, CONTENT_TYPE_RON)
|
||||
.query(params);
|
||||
let mut url = format!("/ron-api/{}?", api_name);
|
||||
serde_html_form::ser::push_to_string(&mut url, params).unwrap();
|
||||
let request_builder = method_fn(&url).header(CONTENT_TYPE, CONTENT_TYPE_RON);
|
||||
send_req(request_builder.build()?).await
|
||||
}
|
||||
|
||||
|
|
@ -111,28 +106,10 @@ where
|
|||
req_with_body(api_name, body, Request::delete).await
|
||||
}
|
||||
|
||||
pub async fn get<'a, T, U, V>(api_name: &str, params: U) -> Result<T>
|
||||
pub async fn get<T, U>(api_name: &str, params: U) -> Result<T>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
U: IntoIterator<Item = (&'a str, V)>,
|
||||
V: AsRef<str>,
|
||||
U: Serialize,
|
||||
{
|
||||
req_with_params(api_name, params, Request::get).await
|
||||
}
|
||||
|
||||
// pub async fn api_request_get<T>(api_name: &str, params: QueryParams) -> Result<T, String>
|
||||
// where
|
||||
// T: DeserializeOwned,
|
||||
// {
|
||||
// match Request::get(&format!("/ron-api/recipe/{}?{}", api_name, params))
|
||||
// .header("Content-Type", "application/ron")
|
||||
// .send()
|
||||
// .await
|
||||
// {
|
||||
// Err(error) => {
|
||||
// toast::show(Level::Info, &format!("Internal server error: {}", error));
|
||||
// Err(error.to_string())
|
||||
// }
|
||||
// Ok(response) => Ok(ron::de::from_bytes::<T>(&response.binary().await.unwrap()).unwrap()),
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue