Overview
TheLibraryWithFilters model provides a filtered and sorted view of the user’s library. It supports filtering by content type, sorting by various criteria, and pagination. The model is generic over a filter type that determines which library items are included.
Structure
Fields
Currently selected filters and sort options
Available filter and sort options
Filtered, sorted, and paginated library items
Phantom data for the filter type parameter
Selected
Represents the current selection state:LibraryRequest
Content type filter (“movie”, “series”, etc.).
None means all types.Sort order for library items (default:
LastWatched)Current page number (starts at 1)
Sort
Available sorting options:Sort Behavior
LastWatched
LastWatched
Sorts by
state.last_watched in descending order. Most recently watched items appear first.Source: src/models/library_with_filters.rs:69Name
Name
Sorts alphabetically by item name (case-insensitive), A to Z.Source:
src/models/library_with_filters.rs:89NameReverse
NameReverse
Sorts alphabetically by item name (case-insensitive), Z to A.Source:
src/models/library_with_filters.rs:90TimesWatched
TimesWatched
Sorts by
state.times_watched in descending order. Most watched items appear first.Source: src/models/library_with_filters.rs:70Watched
Watched
Watched items first (by
watched() status), then unwatched. Within each group, sorted by last_watched descending, with ctime as fallback.Source: src/models/library_with_filters.rs:73NotWatched
NotWatched
Unwatched items first, then watched. Within each group, sorted by
last_watched ascending, with ctime as fallback.Source: src/models/library_with_filters.rs:81Selectable
Provides available options:Available content types found in the filtered library
All available sort options with selection state
Request for next page if more items are available
LibraryFilter
The generic parameterF must implement the LibraryFilter trait:
Built-in Filters
ContinueWatchingFilter
Includes items that are in progress or have notifications:NotRemovedFilter
Includes all items that have not been marked as removed:Constructor
new()
Creates a new library browser instance:Update Implementation
ImplementsUpdateWithCtx<E> to handle library operations:
Supported Messages
Action::Load::LibraryWithFilters
Action::Load::LibraryWithFilters
Loads the library with specified filters:
- Updates selected request
- Applies type and sort filters
- Paginates results
- Updates selectable options
src/models/library_with_filters.rs:173Action::Unload
Action::Unload
Clears all library filter state:
- Resets selected to None
- Clears catalog
- Recomputes selectable options
src/models/library_with_filters.rs:191Action::LibraryWithFilters::LoadNextPage
Action::LibraryWithFilters::LoadNextPage
Loads the next page of results:
- Increments page number
- Extends catalog with additional items
- Updates next_page availability
src/models/library_with_filters.rs:209Internal::LibraryChanged
Internal::LibraryChanged
Recomputes filtered catalog when library is updated:
- Reapplies current filters
- Updates selectable types
- Adjusts pagination
src/models/library_with_filters.rs:235Pagination
Library pagination works differently from catalog pagination:Unlike catalog browsing, library filtering happens locally and instantly. All filtering and sorting is done in-memory.
Type Selection
Types are derived from the filtered library:- Filter library items using the filter predicate
- Extract unique types from filtered items
- Sort types by
TYPE_PRIORITIES(movie, series, etc.) - Add “All Types” option (type = None) at the beginning
Usage Example
Performance Considerations
Testing
The module includes comprehensive tests for sort behavior:- Watched vs. not watched ordering
- Series handling with
times_watchedandflagged_watched - Last watched timestamps
- Creation time fallbacks
src/models/library_with_filters.rs:371
See Also
- LibraryBucket - Library data structure
- LibraryItem - Individual library items
- NotificationsBucket - Notifications for library items
