simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit ae4c3f76eef6a15a54860d6283eec80960e22651
parent abfa460d29ccec0f7a752585084ecb54d4cb8586
Author: Silas Brack <silasbrack@gmail.com>
Date:   Sat, 25 Apr 2026 22:08:15 +0200

chore: remove debug logging and add htmx preloading

- Remove eprintln debug statements from JWT parsing and vote/comment
- Add htmx preload extension for faster navigation
- Preload nav links and story links on mousedown

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Diffstat:
Msrc/trailbase.rs | 40++++------------------------------------
Mtemplates/application.html | 13+++++++------
Mtemplates/story_row.html | 4++--
3 files changed, 13 insertions(+), 44 deletions(-)

diff --git a/src/trailbase.rs b/src/trailbase.rs @@ -36,7 +36,6 @@ pub fn extract_user_id_from_token(auth_token: &str) -> Option<String> { // JWT format: header.payload.signature let parts: Vec<&str> = auth_token.split('.').collect(); if parts.len() != 3 { - eprintln!("JWT has {} parts, expected 3", parts.len()); return None; } @@ -44,15 +43,9 @@ pub fn extract_user_id_from_token(auth_token: &str) -> Option<String> { let payload = base64_decode_url_safe(parts[1])?; let payload_str = String::from_utf8(payload).ok()?; - eprintln!("JWT payload: {}", payload_str); - // Parse as JSON and extract "sub" claim let json: serde_json::Value = serde_json::from_str(&payload_str).ok()?; - let sub = json.get("sub").and_then(|v| v.as_str()).map(|s| s.to_string()); - - eprintln!("Extracted sub from JWT: {:?}", sub); - - sub + json.get("sub").and_then(|v| v.as_str()).map(|s| s.to_string()) } /// URL-safe base64 decode (handles missing padding) @@ -314,8 +307,6 @@ pub async fn create_comment(client: &Client, comment: CreateComment) -> Result<C let user_id = extract_user_id_from_token(&tokens.auth_token) .ok_or_else(|| ClientError::Auth("Invalid token".to_string()))?; - eprintln!("Creating comment with user_id: {}", user_id); - let comment_with_user = CreateCommentWithUser { story_id: comment.story_id, parent_id: comment.parent_id, @@ -325,16 +316,7 @@ pub async fn create_comment(client: &Client, comment: CreateComment) -> Result<C created_by: user_id, }; - let id_str = match client.records("comment").create(&comment_with_user).await { - Ok(id) => { - eprintln!("Comment created with id: {}", id); - id - } - Err(e) => { - eprintln!("Failed to create comment: {:?}", e); - return Err(e.into()); - } - }; + let id_str = client.records("comment").create(&comment_with_user).await?; let id: i64 = id_str.parse().unwrap_or(0); // Fetch the created comment @@ -401,10 +383,6 @@ pub async fn calculate_comment_path( /// Create a vote pub async fn vote(client: &Client, target_type: i64, target_id: i64) -> Result<(), ClientError> { - // Check if client has tokens - let has_tokens = client.tokens().is_some(); - eprintln!("Client has tokens: {}", has_tokens); - let tokens = client.tokens().ok_or_else(|| ClientError::Auth("Not authenticated".to_string()))?; let user_id = extract_user_id_from_token(&tokens.auth_token) .ok_or_else(|| ClientError::Auth("Invalid token".to_string()))?; @@ -423,18 +401,8 @@ pub async fn vote(client: &Client, target_type: i64, target_id: i64) -> Result<( target_id, }; - eprintln!("Creating vote with JSON: {}", serde_json::to_string(&vote_data).unwrap_or_default()); - - match client.records("vote").create(&vote_data).await { - Ok(id) => { - eprintln!("Vote created with id: {}", id); - Ok(()) - } - Err(e) => { - eprintln!("Failed to create vote: {:#?}", e); - Err(e.into()) - } - } + client.records("vote").create(&vote_data).await?; + Ok(()) } /// Remove a vote diff --git a/templates/application.html b/templates/application.html @@ -5,21 +5,22 @@ <title>News</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.1/preload.min.js"></script> <link rel="stylesheet" href="/static/style.css" /> </head> - <body> + <body hx-ext="preload"> <header class="site-header"> <nav class="nav-main"> <a href="/" class="logo">News</a> <div class="nav-links"> - <a href="/" class="nav-link">hot</a> - <a href="/new" class="nav-link">new</a> - <a href="/top" class="nav-link">top</a> + <a href="/" class="nav-link" preload="mousedown">hot</a> + <a href="/new" class="nav-link" preload="mousedown">new</a> + <a href="/top" class="nav-link" preload="mousedown">top</a> <span class="nav-separator">|</span> - <a href="/submit" class="nav-link">submit</a> + <a href="/submit" class="nav-link" preload="mousedown">submit</a> </div> <div class="nav-right"> - <a href="/search" class="nav-link">search</a> + <a href="/search" class="nav-link" preload="mousedown">search</a> </div> </nav> </header> diff --git a/templates/story_row.html b/templates/story_row.html @@ -25,7 +25,7 @@ {% when None %} {% endmatch %} {% when None %} - <a href="/story/{{ story.id }}" class="story-link">{{ story.title }}</a> + <a href="/story/{{ story.id }}" class="story-link" preload="mousedown">{{ story.title }}</a> {% endmatch %} </div> <div class="story-meta"> @@ -39,7 +39,7 @@ {% endmatch %} <span class="story-time">{{ story.time_ago }}</span> | - <a href="/story/{{ story.id }}" class="story-comments">{{ story.comment_count }} comment{% if story.comment_count != 1 %}s{% endif %}</a> + <a href="/story/{{ story.id }}" class="story-comments" preload="mousedown">{{ story.comment_count }} comment{% if story.comment_count != 1 %}s{% endif %}</a> {% if !story.tags.is_empty() %} | {% for tag in story.tags %}