Skip to main content

Overview

EpiNeko’s library management system allows users to organize their anime collection across different viewing statuses. The library is built on top of Supabase with row-level security, ensuring each user’s data is private and secure.

Add to Library

Save anime to your collection with a single click

Update Status

Change viewing status as you progress through series

Track Progress

Monitor episodes watched and completion percentage

Remove Items

Clean up your library by removing unwanted entries

Library Item Structure

Each item in your library contains comprehensive information about the anime and your viewing progress:

Core Functions

Adding to Library

Add a new anime to your personal collection using the addToLibrary function:
The user_id is automatically populated from the authenticated user’s session. Users must be logged in to add items to their library.
Implementation Details (src/services/library.ts:16-30):
  • Retrieves the current user from Supabase Auth
  • Inserts the item into the user_library table
  • Returns the created item with all fields populated
  • Throws an error if the user is not authenticated

Updating Library Items

Change the status or progress of an existing library item:
Function Signature (src/services/library.ts:46-61):

Removing from Library

Remove an anime from your library completely:
Implementation (src/services/library.ts:32-44):
  • Deletes the item matching both user_id and anime_id_jikan
  • Ensures users can only remove their own items
  • No error thrown if item doesn’t exist

Retrieving Library Data

Fetch your entire library or a specific item:
Returns all items ordered by updated_at descending (src/services/library.ts:63-72).

UI Components

LibraryButton Component

The LibraryButton component provides a complete interface for managing library items with status dropdown:
1

Initial State

When not in library, displays ”+ AÑADIR A MI LISTA” button
2

Added State

After adding, shows ”✓ EN MI LISTA” and a status dropdown appears
3

Status Selection

Users can change between watching, completed, plan to watch, and dropped
4

Removal

Clicking the main button when in library removes the item
Status Labels (src/components/anime/LibraryButton.tsx:73-78):
  • 📺 VIENDO (watching)
  • ✅ COMPLETADO (completed)
  • ⏳ PENDIENTE (plan_to_watch)
  • ❌ ABANDONADO (dropped)

Library Page

The library page displays all items in a responsive grid layout:
  • Responsive grid (2-6 columns based on screen size)
  • Loading skeletons during data fetch
  • Empty state with call-to-action
  • Direct links to anime detail pages
  • Sorted by most recently updated

Database Schema

The library is backed by a PostgreSQL table with row-level security:
The unique constraint on (user_id, anime_id_jikan) prevents duplicate entries. Attempting to add the same anime twice will result in a database error.
Security Policies (supabase/migrations/20260218_initial_schema.sql:65-75):
  • Users can only view, insert, update, and delete their own library items
  • All operations are protected by auth.uid() = user_id checks
  • Row-level security is enabled on the table

Error Handling

All library functions properly handle authentication and database errors:

Best Practices

Optimistic Updates

Update the UI immediately before API calls complete for better UX

Error Rollback

Revert optimistic updates if operations fail

Check Before Add

Use getLibraryItem to check if an anime is already in the library before attempting to add it

Partial Updates

Only include changed fields in updateLibraryItem calls to minimize data transfer