Skip to content

Conversation

@mehdiess8
Copy link

Delete All Chats Feature Implementation

Overview

This PR implements a "Delete All Chats" feature that allows users to permanently delete all their chat history with a single action. The feature includes a confirmation dialog to prevent accidental deletions and proper cleanup of both frontend state and database records.

Implementation Details

Database Changes

  • Added a new deleteAllChats function in db/chats.ts that performs a single DELETE query targeting all chats belonging to a specific user.

UI Components

  • Added a new DeleteAllChats component in components/sidebar/items/chat/delete-all-chats.tsx
  • Integrated the component into the profile settings panel with a trash icon trigger
  • Implemented a confirmation dialog using Shadcn UI's Dialog component for better UX
  • Added proper TypeScript types and props validation

State Management

  • Properly cleans up all related state after deletion:
    • Clears chat list (setChats([]))
    • Clears chat messages (setChatMessages([]))
    • Resets selected chat (setSelectedChat(null))
    • Creates a new chat automatically (handleNewChat())
  • Uses React Context to manage global state updates

Security Considerations

  • Utilizes Supabase RLS policies to ensure users can only delete their own chats
  • Uses the correct user_id from auth system for proper authorization
  • Implements proper error handling and user feedback

UX Improvements

  • Added a confirmation dialog to prevent accidental deletions
  • Provides immediate feedback via toast notifications
  • Maintains a clean state by entering "new chat" mode after deletion

Testing Instructions

  1. Log in to your account
  2. Create multiple chats with different content
  3. Click on your profile picture to open settings
  4. Click the trash icon
  5. Confirm deletion in the dialog
  6. Verify that:
    • All chats are removed from the sidebar
    • A new empty chat is created
    • The chats remain deleted after page refresh
    • Other users' chats are unaffected

Screenshots

delete-all-chats.mp4

Technical Considerations

  • Uses a single DELETE query instead of multiple queries for better performance
  • Follows the project's existing patterns for state management and UI components

Related Issues

Addresses #1657

Breaking Changes

None. This is a new feature that doesn't affect existing functionality.

Future Improvements

  • Add ability to delete chats by date range
  • Add bulk selection for partial deletion
  • Consider adding a grace period for undoing deletions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants