feat: add centralized API service layer for frontend
All checks were successful
Build MIPS Binary / build (push) Successful in 5m18s
All checks were successful
Build MIPS Binary / build (push) Successful in 5m18s
- Create frontend/src/api/mod.rs with centralized HTTP client and error handling - Implement api::auth module (login, logout, check_auth, get_user) - Implement api::torrent module (add, action, delete, start, stop, set_label, set_priority) - Implement api::setup module (get_status, setup) - Implement api::settings module (set_global_limits) - Implement api::push module (get_public_key, subscribe) - Update all components to use api service layer instead of direct gloo_net calls - Add thiserror dependency for error handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use leptos::wasm_bindgen::JsCast;
|
||||
use leptos::*;
|
||||
use crate::api;
|
||||
|
||||
#[component]
|
||||
pub fn Sidebar() -> impl IntoView {
|
||||
@@ -76,12 +77,8 @@ pub fn Sidebar() -> impl IntoView {
|
||||
|
||||
let handle_logout = move |_| {
|
||||
spawn_local(async move {
|
||||
let client = gloo_net::http::Request::post("/api/auth/logout");
|
||||
if let Ok(resp) = client.send().await {
|
||||
if resp.ok() {
|
||||
// Force full reload to clear state
|
||||
let _ = window().location().set_href("/login");
|
||||
}
|
||||
if api::auth::logout().await.is_ok() {
|
||||
let _ = window().location().set_href("/login");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user