New Features Added¶
✅ SHA256 Hash & Duplicate Detection¶
What It Does¶
- Calculates SHA256 hash of each EPUB file during import
- Stores hash in database for future comparison
- Prevents importing the same book twice
How It Works¶
- When you import an EPUB, the app calculates its SHA256 hash
- Checks if a book with the same hash already exists
- If duplicate found, shows error: "This book is already in your library: [Title] by [Author]"
- If unique, imports the book normally
Technical Details¶
- Hash calculated using Web Crypto API (
crypto.subtle.digest) - Database schema upgraded to version 2 with
fileHashindex - Hash stored as hex string (64 characters)
Console Output¶
Starting EPUB import for: book.epub
Calculating file hash...
File hash: a1b2c3d4e5f6...
Duplicate book found: Book Title
Error: This book is already in your library: "Book Title" by Author Name
✅ Context Menu with Delete Functionality¶
What It Does¶
- Adds "..." menu button to each book card
- Appears on hover over book cover
- Delete button with two-click confirmation
- Deletes book and all associated annotations
How It Works¶
1. Hover to Reveal¶
- Move mouse over any book card
- "..." button appears in top-right corner
2. First Click - Delete Button¶
- Click "..." to open menu
- Click "Delete" button (normal appearance)
3. Second Click - Confirmation¶
- Button turns RED with text "Click again to confirm"
- Click again to permanently delete
- Click outside menu to cancel
4. Deletion Process¶
- Deletes all highlights for the book
- Deletes all notes for the book
- Deletes the book itself
- Library automatically refreshes
Visual Design¶
- Menu button: Three vertical dots (⋮)
- Appears only on hover (smooth fade-in)
- Delete button: Trash icon + text
- Confirmation state: Red background
- Closes automatically after deletion or when clicking outside
Safety Features¶
- Two-click confirmation prevents accidental deletion
- Clear visual feedback (red color) for destructive action
- Can cancel by clicking outside menu
- All associated data (highlights, notes) also deleted
Updated Database Schema¶
Version 2 Changes¶
interface Book {
// ... existing fields ...
fileHash: string; // NEW: SHA256 hash for duplicate detection
}
Database Indexes¶
Usage Examples¶
Import Duplicate Book¶
1. Import "Book.epub" → Success
2. Import same "Book.epub" again → Error message
3. Alert: "This book is already in your library: [Title] by [Author]"
Delete a Book¶
1. Hover over book card
2. Click "..." button
3. Click "Delete"
4. Button turns red: "Click again to confirm"
5. Click again → Book deleted
Cancel Delete¶
Files Modified¶
New Files¶
/frontend/src/lib/crypto.ts- SHA256 hash calculation/frontend/src/components/Library/BookCardMenu.tsx- Context menu component
Modified Files¶
/frontend/src/lib/db.ts- Added fileHash field and v2 schema/frontend/src/services/epubService.ts- Hash calculation and duplicate check/frontend/src/components/Library/BookCard.tsx- Added menu button/frontend/src/components/Library/BookGrid.tsx- Added delete handler/frontend/src/components/Library/ImportButton.tsx- Better error messages
Testing¶
Test Duplicate Detection¶
- Import any EPUB file
- Try importing the same file again
- Should see error message with book title and author
- Book should NOT be imported twice
Test Delete Functionality¶
- Import a book
- Hover over the book card
- Click "..." button (should appear in top-right)
- Click "Delete" (normal appearance)
- Click "Delete" again (red, "Click again to confirm")
- Book should disappear from library
Test Delete Cancellation¶
- Hover over book card
- Click "..." button
- Click "Delete" once
- Click outside the menu
- Menu should close, book should remain
Benefits¶
Duplicate Detection¶
- ✅ Prevents wasting storage space
- ✅ Keeps library organized
- ✅ Clear error messages
- ✅ Works even if filename is different
Delete Functionality¶
- ✅ Easy to remove unwanted books
- ✅ Two-click confirmation prevents accidents
- ✅ Cleans up all associated data
- ✅ Visual feedback for safety
Next Steps¶
These features are now live! The dev server should automatically reload with the changes.
Try it out: 1. Import a book twice to test duplicate detection 2. Hover over a book and try the delete menu