Refactor load_config method
This commit is contained in:
parent
a0d4fcda92
commit
d94392362a
@ -11,7 +11,7 @@ pub struct Config {
|
||||
pub fn App() -> impl IntoView {
|
||||
let (count, set_count) = signal(0);
|
||||
let config = LocalResource::new(load_config);
|
||||
|
||||
|
||||
view! {
|
||||
<div style="background-color: #292b29; color: #ffffff; font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0;">
|
||||
<div style="background-color: #196e0a; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); text-align: center; max-width: 400px; width: 100%;">
|
||||
@ -23,8 +23,14 @@ pub fn App() -> impl IntoView {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async fn load_config() -> std::result::Result<Config, gloo_net::Error> {
|
||||
Request::get("/config.json").send().await?.json::<Config>().await
|
||||
async fn load_config() -> std::result::Result<Config, String> {
|
||||
let response = Request::get("/config.json")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("HTTP error: {e}"))?;
|
||||
let config = response
|
||||
.json::<Config>()
|
||||
.await
|
||||
.map_err(|e| format!("JSON error: {e}"))?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user