mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-07-14 18:15:56 -04:00
* feat: add filtering and sorting across library, explore, and upcoming Add comprehensive filtering and sorting to all list views on both web and mobile. Library (new dedicated page): - New /library route (web) with URL search param persistence - New Library tab (5th tab, mobile) with FlashList grid - Filters: status (multi-select), type, genre (library-only), user rating range, release year (decade presets + custom), content rating, available to stream - Sort by: title, date added, release date, popularity, user rating, TMDB rating - Text search within collection - Filter popover (web) / bottom sheet with Apply (mobile) - Remove old dashboard.library endpoint in favor of library.list Explore/Discover: - New Discover section on Explore page with inline filter controls - TMDB filters: genre (now optional), year range, min rating, sort order, original language, streaming provider - Watch provider list endpoint (WATCH_REGION env var, default "US") - Default to popular content when no filters selected Upcoming: - Type filter (All/Movies/TV Shows) and status filter (All/Watching/Watchlist) - Toggle chips on both web (URL params) and mobile - Backend: mediaType and statusFilter params on upcoming endpoint Navigation: - Library added to web nav bar (desktop + mobile tab bar) - Library added as 5th tab on mobile (between Home and Explore) - Dashboard library section simplified to compact preview with "See all" link Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add user streaming platform subscriptions and redesign filter UI Replace the denormalized availabilityOffers table with a normalized platforms + titleAvailability + userPlatforms schema. Users can now declare which streaming services they subscribe to, enabling personalized "On your services" availability display and filtered library/explore results. Backend: new platforms table seeded from TMDB provider data on startup, new API endpoints (platforms.list, account.platforms, account.updatePlatforms), title detail annotates availability with isUserSubscribed flag, library "on my services" filter checks user's subscribed platforms. Web UI: post-registration onboarding page for platform selection, streaming services settings section, title detail split into "On your services" / "Also available on", explore dropdown uses platforms table with active filter highlighting. Library filters redesigned from cluttered popover to clean collapsible inline strip with consolidated dropdowns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address race conditions, stale state, and edge cases in platforms feature - Fix debounced autosave race in streaming services settings: use ref for latest selection + counter guard so only the most recent save updates UI. Clean up timers on unmount. - Fix explore provider dropdown desyncing from query filter when switching Movie/TV type: reset selectedPlatformId alongside providerId. - Fix platformIdsExist rejecting duplicate valid IDs by deduplicating input before comparing against DB results. - Fix stale platform metadata: always upsert name/logo on TMDB refresh instead of skipping when platform already exists. - Fix invisible ratingMax filter: clear ratingMax when user changes ratingMin since the UI only exposes a single rating dropdown now. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: clear stale saved-state timer and preserve falsy filter values - Clear previous savedTimerRef timeout before scheduling a new one in streaming-services-section, preventing an older timer from hiding the "Saved" indicator too early on rapid successive saves - Replace `value || undefined` with explicit empty-value check in library filter handler so numeric 0 (e.g. ratingMin=0) is not incorrectly dropped Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add TanStack Form and migrate auth + change password forms Set up TanStack Form v1 composition layer with createFormHook, pre-bound field components (TextField, TextareaField, CheckboxField, SwitchField, SubmitButton), and migrate the two traditional submit-based forms: - AuthForm: replace 4 useState calls with useAppForm, use form.Field for each input while preserving motion animation layout - ChangePasswordDialog: replace 6 useState calls with useAppForm + Zod schema validation (cross-field password match, min length), per-field error display, form.reset() on dialog close Also adds @tanstack/react-form to the monorepo catalog and updates both web and native apps to reference it via catalog:. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
146 lines
5.0 KiB
TypeScript
146 lines
5.0 KiB
TypeScript
import { beforeAll, beforeEach, describe, expect, test } from "vitest";
|
|
|
|
import { clearAllTables, insertStatus, insertTitle, insertUser } from "@sofa/test/db";
|
|
|
|
import { getFilteredLibraryFeed, getLibraryGenresList } from "../src/library";
|
|
|
|
const defaultFilters = { sortBy: "added_at", sortDirection: "desc" as const, page: 1, limit: 20 };
|
|
|
|
beforeAll(() => clearAllTables());
|
|
beforeEach(() => clearAllTables());
|
|
|
|
// ── getFilteredLibraryFeed ─────────────────────────────────────────────
|
|
|
|
describe("getFilteredLibraryFeed", () => {
|
|
test("returns first page with correct pagination metadata", () => {
|
|
insertUser();
|
|
for (let i = 1; i <= 25; i++) {
|
|
insertTitle({ id: `m${i}`, tmdbId: i });
|
|
insertStatus("user-1", `m${i}`, "watchlist");
|
|
}
|
|
|
|
const result = getFilteredLibraryFeed("user-1", { ...defaultFilters });
|
|
expect(result.items).toHaveLength(20);
|
|
expect(result.page).toBe(1);
|
|
expect(result.totalResults).toBe(25);
|
|
expect(result.totalPages).toBe(2);
|
|
});
|
|
|
|
test("returns second page with remaining items", () => {
|
|
insertUser();
|
|
for (let i = 1; i <= 25; i++) {
|
|
insertTitle({ id: `m${i}`, tmdbId: i });
|
|
insertStatus("user-1", `m${i}`, "watchlist");
|
|
}
|
|
|
|
const result = getFilteredLibraryFeed("user-1", { ...defaultFilters, page: 2 });
|
|
expect(result.items).toHaveLength(5);
|
|
expect(result.page).toBe(2);
|
|
expect(result.totalResults).toBe(25);
|
|
expect(result.totalPages).toBe(2);
|
|
});
|
|
|
|
test("custom limit respected", () => {
|
|
insertUser();
|
|
for (let i = 1; i <= 10; i++) {
|
|
insertTitle({ id: `m${i}`, tmdbId: i });
|
|
insertStatus("user-1", `m${i}`, "watchlist");
|
|
}
|
|
|
|
const result = getFilteredLibraryFeed("user-1", { ...defaultFilters, limit: 5 });
|
|
expect(result.items).toHaveLength(5);
|
|
expect(result.totalPages).toBe(2);
|
|
expect(result.totalResults).toBe(10);
|
|
});
|
|
|
|
test("empty page beyond total returns empty items", () => {
|
|
insertUser();
|
|
for (let i = 1; i <= 5; i++) {
|
|
insertTitle({ id: `m${i}`, tmdbId: i });
|
|
insertStatus("user-1", `m${i}`, "watchlist");
|
|
}
|
|
|
|
const result = getFilteredLibraryFeed("user-1", { ...defaultFilters, page: 2 });
|
|
expect(result.items).toHaveLength(0);
|
|
expect(result.page).toBe(2);
|
|
});
|
|
|
|
test("pages are disjoint and cover all items", () => {
|
|
insertUser();
|
|
for (let i = 1; i <= 4; i++) {
|
|
insertTitle({ id: `m${i}`, tmdbId: i });
|
|
insertStatus("user-1", `m${i}`, "watchlist");
|
|
}
|
|
|
|
const page1 = getFilteredLibraryFeed("user-1", { ...defaultFilters, limit: 2 });
|
|
const page2 = getFilteredLibraryFeed("user-1", { ...defaultFilters, page: 2, limit: 2 });
|
|
|
|
expect(page1.items).toHaveLength(2);
|
|
expect(page2.items).toHaveLength(2);
|
|
|
|
const allTitleIds = new Set([
|
|
...page1.items.map((i) => i.titleId),
|
|
...page2.items.map((i) => i.titleId),
|
|
]);
|
|
expect(allTitleIds.size).toBe(4);
|
|
});
|
|
|
|
test("filters by type", () => {
|
|
insertUser();
|
|
insertTitle({ id: "m1", tmdbId: 1, type: "movie" });
|
|
insertTitle({ id: "t1", tmdbId: 2, type: "tv" });
|
|
insertStatus("user-1", "m1", "watchlist");
|
|
insertStatus("user-1", "t1", "watchlist");
|
|
|
|
const movies = getFilteredLibraryFeed("user-1", { ...defaultFilters, type: "movie" });
|
|
expect(movies.items).toHaveLength(1);
|
|
expect(movies.items[0]!.type).toBe("movie");
|
|
|
|
const tv = getFilteredLibraryFeed("user-1", { ...defaultFilters, type: "tv" });
|
|
expect(tv.items).toHaveLength(1);
|
|
expect(tv.items[0]!.type).toBe("tv");
|
|
});
|
|
|
|
test("filters by search text", () => {
|
|
insertUser();
|
|
insertTitle({ id: "m1", tmdbId: 1, title: "The Matrix" });
|
|
insertTitle({ id: "m2", tmdbId: 2, title: "Inception" });
|
|
insertStatus("user-1", "m1", "watchlist");
|
|
insertStatus("user-1", "m2", "watchlist");
|
|
|
|
const result = getFilteredLibraryFeed("user-1", { ...defaultFilters, search: "matrix" });
|
|
expect(result.items).toHaveLength(1);
|
|
expect(result.items[0]!.title).toBe("The Matrix");
|
|
});
|
|
|
|
test("filters by status", () => {
|
|
insertUser();
|
|
insertTitle({ id: "m1", tmdbId: 1 });
|
|
insertTitle({ id: "m2", tmdbId: 2 });
|
|
insertStatus("user-1", "m1", "watchlist");
|
|
insertStatus("user-1", "m2", "completed");
|
|
|
|
const watchlist = getFilteredLibraryFeed("user-1", {
|
|
...defaultFilters,
|
|
statuses: ["in_watchlist"],
|
|
});
|
|
expect(watchlist.items).toHaveLength(1);
|
|
|
|
const completed = getFilteredLibraryFeed("user-1", {
|
|
...defaultFilters,
|
|
statuses: ["completed"],
|
|
});
|
|
expect(completed.items).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
// ── getLibraryGenresList ──────────────────────────────────────────────
|
|
|
|
describe("getLibraryGenresList", () => {
|
|
test("returns empty array when user has no titles", () => {
|
|
insertUser();
|
|
const genres = getLibraryGenresList("user-1");
|
|
expect(genres).toEqual([]);
|
|
});
|
|
});
|