diff --git a/app.py b/app.py index 16159e5..c8f688b 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, jsonify, request, session, redirect, url_for, send_file +from flask import Flask, render_template, jsonify, request, session, redirect, url_for, send_file, make_response from datetime import datetime, timedelta import os import sys @@ -85,7 +85,16 @@ def inject_apis(): def index(): """Home page with username input""" print("DEBUG: Index route accessed", flush=True) - return render_template('index.html') + # Get the last used username from cookie + last_username = request.cookies.get('last_username', '') + print(f"DEBUG: Last username from cookie: '{last_username}'", flush=True) + + # Auto-redirect to dashboard if username cookie exists + if last_username and last_username.strip(): + print(f"DEBUG: Auto-redirecting to dashboard for user: '{last_username}'", flush=True) + return redirect(url_for('dashboard_current', username=last_username.strip())) + + return render_template('index.html', last_username=last_username) @app.route('/dashboard') def dashboard_form(): @@ -153,6 +162,13 @@ def set_debug_time(): return_url = request.form.get('return_url', url_for('index')) return redirect(return_url) +@app.route('/change-username') +def change_username(): + """Clear username cookie and redirect to index""" + response = make_response(redirect(url_for('index'))) + response.set_cookie('last_username', '', expires=0) # Clear the cookie + return response + @app.route('/') def dashboard_current(username): """Dashboard for current NFL week""" @@ -161,7 +177,10 @@ def dashboard_current(username): nfl_state = sleeper_api.get_nfl_state() current_week = nfl_state.get('week', 1) print(f"DEBUG: Current week: {current_week}", flush=True) - return dashboard(username, current_week) + response = make_response(dashboard(username, current_week)) + # Set cookie to remember this username (expires in 30 days) + response.set_cookie('last_username', username, max_age=30*24*60*60) + return response except Exception as e: print(f"ERROR: dashboard_current exception - {str(e)}", flush=True) print(f"ERROR: Full traceback: {traceback.format_exc()}", flush=True) @@ -172,7 +191,10 @@ def dashboard_current(username): def dashboard_week(username, week): """Dashboard for specific week""" print(f"DEBUG: Dashboard week - username: '{username}', week: {week}", flush=True) - return dashboard(username, week) + response = make_response(dashboard(username, week)) + # Set cookie to remember this username (expires in 30 days) + response.set_cookie('last_username', username, max_age=30*24*60*60) + return response @app.route('///refresh', methods=['POST']) def refresh_scores(username, week): diff --git a/static/style.css b/static/style.css index 79fe901..fb3cb42 100644 --- a/static/style.css +++ b/static/style.css @@ -927,6 +927,45 @@ body { transform: translateY(-1px); } +/* Smaller refresh button */ +.refresh-btn-small { + background: var(--accent); + color: white; + border: none; + border-radius: 4px; + padding: 4px 8px; + font-size: 12px; + cursor: pointer; + transition: all 0.2s ease; + margin-right: 8px; +} + +.refresh-btn-small:hover { + background: var(--accent-hover); + transform: translateY(-1px); +} + +/* Change username button */ +.change-username-btn { + background: var(--bg-secondary); + color: var(--text-primary); + border: 1px solid var(--border-primary); + border-radius: 4px; + padding: 4px 8px; + font-size: 12px; + text-decoration: none; + cursor: pointer; + transition: all 0.2s ease; + display: inline-block; +} + +.change-username-btn:hover { + background: var(--bg-tertiary); + border-color: var(--accent); + color: var(--accent); + transform: translateY(-1px); +} + /* Timezone info */ .timezone-info { font-size: 0.8rem; diff --git a/templates/dashboard.html b/templates/dashboard.html index d349a92..2e35d3f 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -12,11 +12,12 @@ Week {{ week }} Week {{ week + 1 }} → - +
- +
+ Change Username
diff --git a/templates/index.html b/templates/index.html index 77d935a..05e7314 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@
- +