From acdf653eaa3fb57aa636603597961cabd816114b Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 11 Aug 2025 16:01:51 -0400 Subject: [PATCH] Enhance user experience with multiple improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add username field to right sidebar and mobile modal with 'guest' default - Implement real-time username sync with URL query string updates - Add opencompletion.com button and new room creation in left sidebar - Implement room name slugification (e.g. "a whole new world" → "a-whole-new-world") - Create shared utils.js for common functions like slugify - Add single search result auto-redirect functionality - Remove redundant UI elements ("Create New Room" header, docs link) - Preserve user settings (username, model, voice) across redirects and room creation Technical improvements: - Consolidated duplicate code into shared utility functions - Enhanced search logic with parameter preservation - Improved mobile/desktop sync for all input fields - Better URL handling and query string management --- app.py | 21 ++++++ static/js/utils.js | 12 ++++ templates/base.html | 156 ++++++++++++++++++++++++++++++++++++++++++- templates/chat.html | 90 ++++++++++++++++++++++--- templates/index.html | 5 +- 5 files changed, 267 insertions(+), 17 deletions(-) create mode 100644 static/js/utils.js diff --git a/app.py b/app.py index fea7e62..ea10b9b 100644 --- a/app.py +++ b/app.py @@ -22,6 +22,8 @@ from flask import ( send_from_directory, jsonify, Response, + redirect, + url_for, ) from flask_socketio import SocketIO, emit, join_room, leave_room @@ -365,6 +367,25 @@ def search_page(): # Call the function to search messages search_results = search_messages(keywords) + # If there's exactly one search result, redirect directly to that room + if len(search_results) == 1: + room_result = search_results[0] + room_name = room_result["room_name"] + + # Build the redirect URL with current parameters + redirect_params = {} + if username and username != "guest": + redirect_params["username"] = username + + # Preserve other URL parameters like model, voice, etc. + for param in ["model", "voice"]: + value = request.args.get(param) + if value: + redirect_params[param] = value + + redirect_url = url_for("chat", room_name=room_name, **redirect_params) + return redirect(redirect_url) + return render_template( "search.html", rooms=rooms, diff --git a/static/js/utils.js b/static/js/utils.js new file mode 100644 index 0000000..afb4d86 --- /dev/null +++ b/static/js/utils.js @@ -0,0 +1,12 @@ +/** + * Utility functions for the OpenCompletion application + */ + +/** + * Convert a string to a URL-friendly slug + * @param {string} str - The string to slugify + * @returns {string} - The slugified string + */ +function slugify(str) { + return str.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, ''); +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 65560ea..7ed5d62 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,6 +22,9 @@ + + + +