diff --git a/app/routes.py b/app/routes.py index 7a7750c..085d77b 100644 --- a/app/routes.py +++ b/app/routes.py @@ -15,14 +15,8 @@ def index(): # Get folders for the current authenticated user folders = Folder.query.filter_by(user_id=current_user.id).all() - # Separate folders by type - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - return render_template('index.html', - folders=folders, - tidy_folders=tidy_folders, - destination_folders=destination_folders) + folders=folders) @main.route('/api/folders/new', methods=['GET']) @login_required @@ -82,16 +76,9 @@ def add_folder(): # Get updated list of folders for the current user folders = Folder.query.filter_by(user_id=current_user.id).all() - # Get updated lists of folders by type - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - - # Return both sections - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - - response = make_response(tidy_section + destination_section) + response = make_response(render_template('partials/folders_list.html', folders=folders)) response.headers['HX-Trigger'] = 'close-modal' + response.headers["HX-Target"] = 'folder-list' response.status_code = 201 return response @@ -102,13 +89,6 @@ def add_folder(): # Return error in modal errors = {'general': 'An unexpected error occurred. Please try again.'} # Get updated lists of folders by type for error fallback - folders = Folder.query.filter_by(user_id=current_user.id).all() - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - - # Return both sections as fallback - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) response = make_response(render_template('partials/folder_modal.html', errors=errors, name=name, rule_text=rule_text, priority=priority)) response.headers['HX-Retarget'] = '#folder-modal' @@ -134,18 +114,8 @@ def delete_folder(folder_id): db.session.delete(folder) db.session.commit() - # Get updated list of folders for the current user folders = Folder.query.filter_by(user_id=current_user.id).all() - - # Get updated lists of folders by type - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - - # Return both sections - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - - return tidy_section + destination_section + return render_template('partials/folders_list.html', folders=folders) except Exception as e: # Print unhandled exceptions to the console as required @@ -153,14 +123,8 @@ def delete_folder(folder_id): db.session.rollback() # Return the folders list unchanged folders = Folder.query.filter_by(user_id=current_user.id).all() - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - # Return both sections - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - - return tidy_section + destination_section + return render_template('partials/folders_list.html', folders=folders) @main.route('/api/folders//toggle', methods=['PUT']) @login_required @@ -245,15 +209,6 @@ def update_folder(folder_id): # If there are validation errors, return the modal with errors if errors: - # Get updated lists of folders by type for error fallback - folders = Folder.query.filter_by(user_id=current_user.id).all() - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - - # Return both sections as fallback - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - response = make_response(render_template('partials/folder_modal.html', folder=folder, errors=errors, name=name, rule_text=rule_text, priority=priority)) response.headers['HX-Retarget'] = '#folder-modal' response.headers['HX-Reswap'] = 'outerHTML' @@ -275,15 +230,9 @@ def update_folder(folder_id): # Get updated list of folders for the current user folders = Folder.query.filter_by(user_id=current_user.id).all() - # Get updated lists of folders by type - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - # Return both sections - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - - response = make_response(tidy_section + destination_section) + section = render_template('partials/folders_list.html', folders=folders) + response = make_response(section) response.headers['HX-Trigger'] = 'close-modal' return response @@ -422,7 +371,6 @@ def sync_imap_folders(): # Process each unique folder synced_count = 0 - print("HELLOOO") processed_emails_service = ProcessedEmailsService(current_user) for imap_folder in unique_folders: @@ -474,14 +422,8 @@ def sync_imap_folders(): # Get updated list of folders folders = Folder.query.filter_by(user_id=current_user.id).all() - tidy_folders = [folder for folder in folders if folder.folder_type == 'tidy'] - destination_folders = [folder for folder in folders if folder.folder_type == 'destination'] - # Return both sections - tidy_section = render_template('partials/folders_to_tidy_section.html', tidy_folders=tidy_folders) - destination_section = render_template('partials/destination_folders_section.html', destination_folders=destination_folders) - - return tidy_section + destination_section + return render_template('partials/folders_list.html', folders=folders) except Exception as e: logging.exception("Error syncing IMAP folders: %s", e) @@ -511,11 +453,14 @@ def get_folders(): # Get all folders folders = Folder.query.filter_by(user_id=current_user.id).all() - # Check if we need to return a specific section if folder_type == 'tidy': - return render_template('partials/folders_to_tidy_section.html', tidy_folders=folders) + response = make_response(render_template('partials/folders_to_tidy_section.html', folders=folders)) + response["HX-Retarget"] = "#folders-to-tidy" + return response elif folder_type == 'destination': - return render_template('partials/destination_folders_section.html', destination_folders=folders) + response = make_response(render_template('partials/destination_folders_section.html', folders=folders)) + response["HX-Retarget"] = "#destination-folders" + return response else: return render_template('partials/folders_list.html', folders=folders) diff --git a/app/templates/base.html b/app/templates/base.html index e303d43..b5eb412 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -26,9 +26,14 @@ .fade-in-htmx.htmx-added { opacity: 0; } + + .htmx-added .fade-in-htmx { + opacity: 0; + } + .fade-in-htmx { opacity: 1; - transition: opacity 1s ease-out; + transition: opacity 300ms ease-out; } /* Fade out transition for HTMX */ .fade-out-htmx.htmx-swapping { diff --git a/app/templates/index.html b/app/templates/index.html index ae06c67..5cf5708 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -21,57 +21,41 @@

Email Folders

Create and manage your email organization rules

-
- -
- - - -
-

Welcome to Email Organizer!

-

Organize your emails automatically with AI-powered rules. Create folders and set up rules to categorize incoming emails.

-
- +
{% if current_user.imap_config %}
- -
-
- + +
+
+
{% else %}
- +
{% endif %} +
+ + + {% if not current_user.imap_config %} + {% include "partials/welcome_section.html" %} + {% endif %}
@@ -80,16 +64,16 @@
Total Folders
-
{{ tidy_folders|length }}
+
{{ folders|selectattr('folder_type', 'equalto', 'tidy')|list|length }}
Folders to Tidy
-
{{ destination_folders|length }}
+
{{ folders|selectattr('folder_type', 'equalto', 'destination')|list|length }}
Destination Folders
- {{ tidy_folders|sum(attribute='pending_count') }} + {{ folders|selectattr('folder_type', 'equalto', 'tidy')|sum(attribute='pending_count') }}
Pending Emails
@@ -102,16 +86,13 @@
- - - + + +
-
- {% include 'partials/folders_to_tidy_section.html' %} - {% include 'partials/destination_folders_section.html' %} -
+ {% include 'partials/folders_list.html' %} diff --git a/app/templates/partials/destination_folders_section.html b/app/templates/partials/destination_folders_section.html index a48da3d..12c3b2f 100644 --- a/app/templates/partials/destination_folders_section.html +++ b/app/templates/partials/destination_folders_section.html @@ -1,18 +1,26 @@ -
+
-

Destination Folders

+

+ + + Destination Folders

Folders where emails are organized and stored

- +
+ +
- {% for folder in destination_folders %} + {% for folder in folders|selectattr('folder_type', 'equalto', 'destination') %} {% include 'partials/folder_card_destination.html' %} {% else %}
@@ -32,4 +40,4 @@
{% endfor %}
-
\ No newline at end of file +
diff --git a/app/templates/partials/folder_card_destination.html b/app/templates/partials/folder_card_destination.html index a82159e..2a86ac3 100644 --- a/app/templates/partials/folder_card_destination.html +++ b/app/templates/partials/folder_card_destination.html @@ -16,8 +16,8 @@ - -
-

Need help setting up your first folder?

- View tutorial -
- - {% endfor %} - +
+ {% include 'partials/folders_to_tidy_section.html' %} + {% include 'partials/destination_folders_section.html' %} +
\ No newline at end of file diff --git a/app/templates/partials/folders_to_tidy_section.html b/app/templates/partials/folders_to_tidy_section.html index 9738593..5ae445c 100644 --- a/app/templates/partials/folders_to_tidy_section.html +++ b/app/templates/partials/folders_to_tidy_section.html @@ -1,31 +1,33 @@ -
-
+
+
-

Folders to Tidy

-

Folders containing emails that need to be processed

+

+ + Emails to organize +

+

+ Folders that need a little Marie Kondo +

-
-
- {% for folder in tidy_folders %} +
+ {% for folder in folders|selectattr('folder_type', 'equalto', 'tidy') %} {% include 'partials/folder_card_tidy.html' %} {% else %}
- +
-

No folders to tidy yet

-

Add your first folder to start organizing your emails.

+

Your email transformation area is empty!

+

Let's bring in some folders to organize and watch the magic happen.

diff --git a/app/templates/partials/imap_config_modal.html b/app/templates/partials/imap_config_modal.html index 28f4b70..bdae6bf 100644 --- a/app/templates/partials/imap_config_modal.html +++ b/app/templates/partials/imap_config_modal.html @@ -80,7 +80,7 @@ {% if success %}
- diff --git a/app/templates/partials/welcome_section.html b/app/templates/partials/welcome_section.html new file mode 100644 index 0000000..2675f49 --- /dev/null +++ b/app/templates/partials/welcome_section.html @@ -0,0 +1,21 @@ + +
+
+ +

Welcome to Email Organizer! 🎉

+
+

Ready to tame your email chaos? Let's get your email folders synchronized so we can start organizing your emails with AI-powered rules!

+
+ +
+ + Connect your email account to get started +
+
+
\ No newline at end of file