Skip to content

Latest commit

 

History

History
219 lines (177 loc) · 5.94 KB

File metadata and controls

219 lines (177 loc) · 5.94 KB

EPUB/PDF Reader MVP - Implementation Complete

✅ Implementation Status

All MVP features have been successfully implemented:

Core Features

  • ✅ Upload .epub and .pdf files
  • ✅ Store files in IndexDB using localforage
  • ✅ Store document metadata separately
  • ✅ Display library grid with all documents
  • ✅ Open and read EPUB files with epubjs
  • ✅ Open and read PDF files with pdfjs-dist
  • ✅ Navigate pages in both readers
  • ✅ Track and save reading progress in NgRx
  • ✅ Delete documents from both IndexDB and state
  • ✅ Responsive layout (mobile/desktop)

Architecture

  • ✅ All components are standalone (no NgModule)
  • ✅ NgRx state management with Entity adapter
  • ✅ Proper separation of concerns (core, store, features)
  • ✅ Type-safe models and interfaces
  • ✅ Modern Angular 21+ patterns

Project Structure

src/app/
├── core/
│   ├── models/
│   │   └── document.model.ts          # Document interface
│   └── services/
│       ├── indexdb.service.ts         # IndexDB operations
│       ├── epub.service.ts            # EPUB metadata extraction
│       └── pdf.service.ts             # PDF metadata extraction
├── store/
│   └── documents/
│       ├── documents.actions.ts       # NgRx actions
│       ├── documents.reducer.ts       # NgRx reducer with Entity adapter
│       ├── documents.selectors.ts     # NgRx selectors
│       └── documents.effects.ts       # Side effects handling
├── features/
│   ├── upload/
│   │   └── upload.component.ts        # File upload component
│   ├── library/
│   │   └── library.component.ts       # Document library grid
│   └── reader/
│       ├── reader.component.ts        # Main reader container
│       ├── epub-reader/
│       │   └── epub-reader.component.ts
│       └── pdf-reader/
│           └── pdf-reader.component.ts
├── app.config.ts                      # App configuration with NgRx
├── app.routes.ts                      # Routing configuration
└── app.ts                             # Root component

How to Run

  1. Start the development server:

    npm start
  2. Open your browser: Navigate to http://localhost:4200

  3. Upload a document:

    • Click "Upload Document" button
    • Select a .epub or .pdf file
    • The document will be stored in IndexDB
  4. Read documents:

    • Click "Open" on any document card
    • Use Previous/Next buttons to navigate
    • Your reading progress is automatically saved

Key Technologies

  • Angular 21+: Modern standalone components
  • NgRx: State management with Entity adapter
  • localforage: IndexDB wrapper for file storage
  • epubjs: EPUB rendering
  • pdfjs-dist: PDF rendering

Component Details

Library Component

  • Displays all uploaded documents in a grid
  • Shows document metadata (title, type, size, last opened)
  • Handles document deletion with confirmation
  • Loads documents on initialization

Upload Component

  • Handles file selection
  • Dispatches upload action to NgRx store
  • Accepts .epub and .pdf files only

Reader Component

  • Routes to correct reader based on document type
  • Displays document title and back navigation
  • Acts as container for epub/pdf readers

EPUB Reader

  • Renders EPUB using epubjs library
  • Tracks current location
  • Saves reading progress automatically
  • Previous/Next navigation

PDF Reader

  • Renders PDF using pdfjs-dist
  • Canvas-based rendering
  • Zoom controls (50% - 200%)
  • Page tracking with progress saving

NgRx Store

State Shape

{
  documents: {
    ids: string[],
    entities: { [id: string]: Document },
    selectedDocumentId: string | null,
    loading: boolean,
    error: string | null
  }
}

Actions

  • uploadDocument - Upload new file
  • uploadDocumentSuccess - Upload completed
  • uploadDocumentFailure - Upload failed
  • loadDocuments - Load all documents
  • loadDocumentsSuccess - Documents loaded
  • deleteDocument - Delete document
  • deleteDocumentSuccess - Deletion completed
  • openDocument - Open document for reading
  • updateReadingProgress - Save current page

Effects

  • File upload processing
  • Metadata extraction
  • IndexDB operations
  • Progress tracking

Storage

IndexDB Stores

  1. documents - Stores the actual file blobs
  2. metadata - Stores document metadata

Data Persistence

  • Files are stored as Blobs in IndexDB
  • Metadata is stored separately for quick access
  • Reading progress is synced to metadata
  • All data persists across browser sessions

Browser Compatibility

Works in all modern browsers that support:

  • IndexDB
  • ES2015+
  • Canvas API
  • File API

Known Limitations

  1. Large Files: Very large PDFs may take time to load
  2. EPUB Formatting: Complex EPUB layouts may not render perfectly
  3. Browser Storage: Limited by browser IndexDB quota (usually 50MB+)

Future Enhancements

  • Search within documents
  • Bookmarks and highlights
  • Export reading progress
  • Dark mode
  • Table of contents navigation
  • Text selection and notes
  • Full-text search across library
  • Collections/categories
  • Reading statistics

Troubleshooting

PDF Worker Error

If you see PDF worker errors, the CDN link for pdf.worker.js is being used. For offline development, download the worker file and update the path in pdf-reader.component.ts.

Upload Not Working

  • Check browser console for errors
  • Verify IndexDB is enabled in browser
  • Check available storage quota

Documents Not Loading

  • Clear browser cache
  • Check browser console
  • Verify IndexDB data in DevTools

Development

Running Tests

npm test

Building for Production

npm run build

Redux DevTools

NgRx Store DevTools are enabled in development. Install the Redux DevTools browser extension to inspect state changes.

License

MIT