From d3658be232e863b5a44efcdbb67f2c20f2cab703 Mon Sep 17 00:00:00 2001 From: Lol3rrr Date: Sun, 8 Sep 2024 04:07:59 +0200 Subject: [PATCH] Add user status api endpoint and update frontend --- backend/src/api.rs | 16 ++++++++++++++++ frontend/src/lib.rs | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/backend/src/api.rs b/backend/src/api.rs index 477a1a9..8e91284 100644 --- a/backend/src/api.rs +++ b/backend/src/api.rs @@ -108,8 +108,24 @@ pub mod steam { } } +pub mod user { + pub fn router() -> axum::Router { + axum::Router::new() + .route("/status", axum::routing::get(status)) + } + + async fn status(session: crate::UserSession) -> axum::http::StatusCode { + if session.data().steam_id.is_some() { + axum::http::StatusCode::OK + } else { + axum::http::StatusCode::UNAUTHORIZED + } + } +} + pub fn router() -> axum::Router { axum::Router::new() .nest("/steam/", steam::router("http://192.168.0.156:3000", "/api/steam/callback")) .nest("/demos/", demos::router("uploads/")) + .nest("/user/", user::router()) } diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs index b57c0a5..caaeb91 100644 --- a/frontend/src/lib.rs +++ b/frontend/src/lib.rs @@ -15,10 +15,25 @@ pub fn demo_list_entry(demo: common::BaseDemoInfo) -> impl leptos::IntoView { #[leptos::component] pub fn steam_login(height: &'static str, width: &'static str) -> impl leptos::IntoView { + let user_status = create_resource(|| (), |_| async move { + let res = reqwasm::http::Request::get("/api/user/status").send().await.unwrap(); + res.status() == 200 + }); + + let tmp = move || if user_status.get().unwrap_or(false) { + view! { +

Logged in

+ }.into_any() + } else { + view! { + + Steam Login + + }.into_any() + }; + view! { - - Steam Login - + { tmp } } } @@ -49,10 +64,14 @@ pub fn top_bar() -> impl leptos::IntoView { background-color: #28282f; color: #d5d5d5; + + display: grid; + grid-template-columns: 15vw auto auto calc(4vh * (180/35) + 20px); } .group { - display: inline-block; + display: block; + width: 30vw; } .elem { @@ -61,23 +80,25 @@ pub fn top_bar() -> impl leptos::IntoView { .logo { color: #d5d5d5; + width: 15vw; + font-size: 24px; + padding: 0px; + margin: 0px; } }; view! {class = style,
- + -
-
- Upload Demo -
+
+ Upload Demo +
-
- -
+
+
}