From 21be142ed526c5ec88c14c3ea6cad043a075a2b9 Mon Sep 17 00:00:00 2001 From: Jomar Milan Date: Sat, 30 May 2026 14:32:51 -0700 Subject: Add unimplemented color selection box --- assets/session.js | 5 +++++ src/main.rs | 40 ++++++++++++++++++++++------------------ src/session.rs | 15 ++++++++++++++- src/template.rs | 6 ++++++ templates/index.html | 4 ++-- templates/session.html | 22 ++++++++++++++++++++++ 6 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 assets/session.js create mode 100644 templates/session.html diff --git a/assets/session.js b/assets/session.js new file mode 100644 index 0000000..b4f95dd --- /dev/null +++ b/assets/session.js @@ -0,0 +1,5 @@ +const colorSelect = document.getElementById('color-select'); + +colorSelect.addEventListener('change', () => { + colorSelect.disabled = true; +}); \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cc8cc34..82c4f19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; use std::time::{SystemTime, UNIX_EPOCH}; -use askama::Template; +use askama::{Template}; use axum::extract::{Path, Query, State}; use axum::http::{header, StatusCode}; use axum::response::{Html, IntoResponse, Response}; @@ -13,7 +13,7 @@ use axum::Router; use axum::routing::{get}; use rust_embed::Embed; use crate::session::{Session}; -use crate::template::IndexTemplate; +use crate::template::{IndexTemplate, SessionTemplate}; #[derive(Embed)] #[folder = "assets/"] @@ -44,23 +44,28 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -async fn serve_index(State(state): State>) -> Response { - let sessions = state.sessions.lock().unwrap(); - let template = IndexTemplate { - sessions: &sessions - }; - +fn serve_template(template: impl Template) -> Response { match template.render() { Ok(html) => Html(html).into_response(), - Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Render error").into_response() + Err(err) => { + eprintln!("An error occurred while rendering a template: {}", err); + (StatusCode::INTERNAL_SERVER_ERROR, "Render error").into_response() + } } } +async fn serve_index(State(state): State>) -> Response { + let sessions = state.sessions.lock().unwrap(); + serve_template(IndexTemplate { + sessions: &sessions + }) +} + async fn serve_static(Path(path): Path) -> Response { match Asset::get(path.as_str()) { Some(content) => { let mime = match path.split('.').last() { - Some("html") => "text/html", + Some("js") => "application/javascript", _ => "application/octet-stream" }; ([(header::CONTENT_TYPE, mime)], content.data).into_response() @@ -76,10 +81,12 @@ async fn visit_session(Path(id): Path, Query(query): Query { - if passcode.map(|passcode| passcode.as_str() == session.passcode).unwrap_or(false) { - (StatusCode::OK, "hi").into_response() - } else { - (StatusCode::FORBIDDEN, "Incorrect session passcode").into_response() + match passcode { + Some(passcode) if passcode.as_str() == session.passcode => + serve_template(SessionTemplate { + session: &session + }), + _ => (StatusCode::FORBIDDEN, "Incorrect session passcode").into_response() } }, None => (StatusCode::NOT_FOUND, "Session does not exist").into_response() @@ -92,10 +99,7 @@ async fn create_session(Path(id): Path, Query(query): Query +} + +pub struct Hand { +} + +impl Session { + pub fn new(steam_name: String, passcode: String) -> Self { + Session { + steam_name, + passcode, + hands: HashMap::new() + } + } } \ No newline at end of file diff --git a/src/template.rs b/src/template.rs index d8b3511..c02a3df 100644 --- a/src/template.rs +++ b/src/template.rs @@ -6,4 +6,10 @@ use crate::session::Session; #[template(path = "index.html")] pub struct IndexTemplate<'a> { pub sessions: &'a HashMap +} + +#[derive(Template)] +#[template(path = "session.html")] +pub struct SessionTemplate<'a> { + pub session: &'a Session } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8b531d3..78d60e9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,11 +5,11 @@ Rusted Ambulator -

Sessions

+

Sessions

    {% for (id, session) in sessions %}
  • - {{session.steam_name}}'s game + {{session.steam_name}}'s game ({{id}})
    diff --git a/templates/session.html b/templates/session.html new file mode 100644 index 0000000..6319d05 --- /dev/null +++ b/templates/session.html @@ -0,0 +1,22 @@ + + + + + {{session.steam_name}}'s game + + + +

    {{session.steam_name}}'s game

    + +

    Player Selection

    + + +
    + + \ No newline at end of file -- cgit v1.2.3