diff --git a/QWEN.md b/QWEN.md index 93ae7b3..1e0a6c7 100644 --- a/QWEN.md +++ b/QWEN.md @@ -7,4 +7,5 @@ Here are special rules you must follow: 6. Prefer using alpinejs over raw javascript. Raw javascript should almost never be needed. 7. Always print unhandled exceptions to the console. 8. Follow best practices for jinja template partials. That is, separate out components where appropriate. -9. Ask the user when there is something unclear. \ No newline at end of file +9. Ask the user when there is something unclear. +10. I always run the server locally on port 5000, so you can use curl to test. No need to start it yourself. \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index af04790..ce1aa79 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, request, jsonify +from flask import Blueprint, render_template, request, jsonify, make_response from app import db from app.models import Folder, User import uuid @@ -9,6 +9,13 @@ main = Blueprint('main', __name__) # For prototype, use a fixed user ID MOCK_USER_ID = '123e4567-e89b-12d3-a456-426614174000' +@main.route('/api/folders/new', methods=['GET']) +def new_folder_modal(): + # Return the add folder modal + response = make_response(render_template('partials/folder_modal.html')) + response.headers['HX-Trigger'] = 'open-modal' + return response + @main.route('/') def index(): # Ensure the mock user exists @@ -50,7 +57,10 @@ def add_folder(): folders = Folder.query.filter_by(user_id=MOCK_USER_ID).all() # Return the updated folders list HTML - return render_template('partials/folders_list.html', folders=folders) + + response = make_response(render_template('partials/folders_list.html', folders=folders)) + response.headers['HX-Trigger'] = 'close-modal' + return response except Exception as e: # Print unhandled exceptions to the console as required @@ -120,8 +130,9 @@ def update_folder(folder_id): # Get updated list of folders folders = Folder.query.filter_by(user_id=MOCK_USER_ID).all() - # Return the updated folders list HTML - return render_template('partials/folders_list.html', folders=folders) + response = make_response(render_template('partials/folders_list.html', folders=folders)) + response.headers['HX-Trigger'] = 'close-modal' + return response except Exception as e: # Print unhandled exceptions to the console as required @@ -151,4 +162,24 @@ def get_folder(folder_id): except Exception as e: # Print unhandled exceptions to the console as required logging.exception("Error getting folder: %s", e) - return jsonify({'error': 'Error retrieving folder'}), 500 \ No newline at end of file + return jsonify({'error': 'Error retrieving folder'}), 500 + + +@main.route('/api/folders//edit', methods=['GET']) +def edit_folder_modal(folder_id): + try: + # Find the folder by ID + folder = Folder.query.filter_by(id=folder_id, user_id=MOCK_USER_ID).first() + + if not folder: + return jsonify({'error': 'Folder not found'}), 404 + + # Return the edit folder modal with folder data + response = make_response(render_template('partials/folder_modal.html', folder=folder)) + response.headers['HX-Trigger'] = 'open-modal' + return response + + except Exception as e: + # Print unhandled exceptions to the console as required + logging.exception("Error getting folder for edit: %s", e) + return jsonify({'error': 'Error retrieving folder'}), 500 diff --git a/app/templates/index.html b/app/templates/index.html index cc5bce8..d8368e8 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -11,69 +11,57 @@ - + -