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>
274 lines
6.1 KiB
TypeScript
274 lines
6.1 KiB
TypeScript
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import Database from "better-sqlite3";
|
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
|
|
|
import * as schema from "@sofa/db/schema";
|
|
|
|
const {
|
|
user,
|
|
titles,
|
|
seasons,
|
|
episodes,
|
|
userMovieWatches,
|
|
userEpisodeWatches,
|
|
userTitleStatus,
|
|
userRatings,
|
|
platforms,
|
|
titleAvailability,
|
|
userPlatforms,
|
|
titleRecommendations,
|
|
integrations,
|
|
} = schema;
|
|
|
|
export const testClient = new Database(":memory:");
|
|
testClient.pragma("foreign_keys = ON");
|
|
export const testDb = drizzle({ client: testClient, schema });
|
|
|
|
export function applyMigrations() {
|
|
const dbPkgDir = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
"..",
|
|
"..",
|
|
"db",
|
|
"drizzle",
|
|
);
|
|
migrate(testDb, { migrationsFolder: dbPkgDir });
|
|
}
|
|
|
|
export function clearAllTables() {
|
|
const tables = testClient
|
|
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '__drizzle%'")
|
|
.all() as { name: string }[];
|
|
testClient.pragma("foreign_keys = OFF");
|
|
for (const { name } of tables) {
|
|
testClient.exec(`DELETE FROM "${name}"`);
|
|
}
|
|
testClient.pragma("foreign_keys = ON");
|
|
}
|
|
|
|
const now = new Date();
|
|
|
|
export function insertUser(id = "user-1") {
|
|
testDb
|
|
.insert(user)
|
|
.values({
|
|
id,
|
|
name: "Test User",
|
|
email: `${id}@test.com`,
|
|
emailVerified: true,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
})
|
|
.run();
|
|
return id;
|
|
}
|
|
|
|
export function insertTitle(
|
|
overrides: {
|
|
id?: string;
|
|
tmdbId?: number;
|
|
tvdbId?: number;
|
|
type?: "movie" | "tv";
|
|
title?: string;
|
|
releaseDate?: string;
|
|
posterPath?: string;
|
|
status?: string;
|
|
} = {},
|
|
) {
|
|
const id = overrides.id ?? "title-1";
|
|
testDb
|
|
.insert(titles)
|
|
.values({
|
|
id,
|
|
tmdbId: overrides.tmdbId ?? 12345,
|
|
tvdbId: overrides.tvdbId,
|
|
type: overrides.type ?? "movie",
|
|
title: overrides.title ?? "Test Movie",
|
|
releaseDate: overrides.releaseDate,
|
|
posterPath: overrides.posterPath,
|
|
status: overrides.status,
|
|
})
|
|
.run();
|
|
return id;
|
|
}
|
|
|
|
export function insertTvShow(
|
|
titleId = "tv-1",
|
|
tmdbId = 99999,
|
|
seasonCount = 1,
|
|
epsPerSeason = 3,
|
|
options: { title?: string; airDates?: string[]; status?: string } = {},
|
|
) {
|
|
insertTitle({
|
|
id: titleId,
|
|
tmdbId,
|
|
type: "tv",
|
|
title: options.title ?? "Test Show",
|
|
status: options.status,
|
|
});
|
|
const episodeIds: string[] = [];
|
|
let airDateIdx = 0;
|
|
for (let s = 1; s <= seasonCount; s++) {
|
|
const seasonId = `${titleId}-s${s}`;
|
|
testDb.insert(seasons).values({ id: seasonId, titleId, seasonNumber: s }).run();
|
|
for (let e = 1; e <= epsPerSeason; e++) {
|
|
const epId = `${titleId}-s${s}e${e}`;
|
|
testDb
|
|
.insert(episodes)
|
|
.values({
|
|
id: epId,
|
|
seasonId,
|
|
episodeNumber: e,
|
|
name: `S${s}E${e}`,
|
|
airDate: options.airDates?.[airDateIdx],
|
|
})
|
|
.run();
|
|
episodeIds.push(epId);
|
|
airDateIdx++;
|
|
}
|
|
}
|
|
return { titleId, episodeIds };
|
|
}
|
|
|
|
export function insertMovieWatch(userId: string, titleId: string, watchedAt?: Date) {
|
|
testDb
|
|
.insert(userMovieWatches)
|
|
.values({
|
|
userId,
|
|
titleId,
|
|
watchedAt: watchedAt ?? new Date(),
|
|
source: "manual",
|
|
})
|
|
.run();
|
|
}
|
|
|
|
export function insertEpisodeWatch(userId: string, episodeId: string, watchedAt?: Date) {
|
|
testDb
|
|
.insert(userEpisodeWatches)
|
|
.values({
|
|
userId,
|
|
episodeId,
|
|
watchedAt: watchedAt ?? new Date(),
|
|
source: "manual",
|
|
})
|
|
.run();
|
|
}
|
|
|
|
export function insertStatus(
|
|
userId: string,
|
|
titleId: string,
|
|
status: "watchlist" | "in_progress" | "completed",
|
|
) {
|
|
const timestamp = new Date();
|
|
testDb
|
|
.insert(userTitleStatus)
|
|
.values({ userId, titleId, status, addedAt: timestamp, updatedAt: timestamp })
|
|
.run();
|
|
}
|
|
|
|
export function insertRating(userId: string, titleId: string, ratingStars: number) {
|
|
testDb.insert(userRatings).values({ userId, titleId, ratingStars, ratedAt: new Date() }).run();
|
|
}
|
|
|
|
export function insertPlatform(
|
|
overrides: {
|
|
id?: string;
|
|
name?: string;
|
|
tmdbProviderId?: number;
|
|
logoPath?: string;
|
|
urlTemplate?: string;
|
|
displayOrder?: number;
|
|
} = {},
|
|
) {
|
|
const id = overrides.id ?? "platform-1";
|
|
testDb
|
|
.insert(platforms)
|
|
.values({
|
|
id,
|
|
name: overrides.name ?? "Netflix",
|
|
tmdbProviderId: overrides.tmdbProviderId ?? 8,
|
|
logoPath: overrides.logoPath ?? "/logo.png",
|
|
urlTemplate: overrides.urlTemplate ?? "https://www.netflix.com/search?q={title}",
|
|
displayOrder: overrides.displayOrder ?? 1,
|
|
})
|
|
.run();
|
|
return id;
|
|
}
|
|
|
|
export function insertTitleAvailability(
|
|
titleId: string,
|
|
platformId: string,
|
|
overrides: {
|
|
offerType?: "flatrate" | "rent" | "buy" | "free" | "ads";
|
|
region?: string;
|
|
} = {},
|
|
) {
|
|
testDb
|
|
.insert(titleAvailability)
|
|
.values({
|
|
titleId,
|
|
platformId,
|
|
offerType: overrides.offerType ?? "flatrate",
|
|
region: overrides.region ?? "US",
|
|
lastFetchedAt: new Date(),
|
|
})
|
|
.run();
|
|
}
|
|
|
|
export function insertUserPlatform(userId: string, platformId: string) {
|
|
testDb.insert(userPlatforms).values({ userId, platformId }).run();
|
|
}
|
|
|
|
export function insertIntegration(userId: string, provider: string, token = "test-token") {
|
|
const type = provider === "sonarr" || provider === "radarr" ? "list" : "webhook";
|
|
return testDb
|
|
.insert(integrations)
|
|
.values({
|
|
userId,
|
|
provider,
|
|
type,
|
|
token,
|
|
enabled: true,
|
|
createdAt: new Date(),
|
|
})
|
|
.returning()
|
|
.get();
|
|
}
|
|
|
|
export function insertRecommendation(
|
|
titleId: string,
|
|
recommendedTitleId: string,
|
|
overrides: {
|
|
source?: "tmdb_recommendations" | "tmdb_similar";
|
|
rank?: number;
|
|
} = {},
|
|
) {
|
|
testDb
|
|
.insert(titleRecommendations)
|
|
.values({
|
|
titleId,
|
|
recommendedTitleId,
|
|
source: overrides.source ?? "tmdb_recommendations",
|
|
rank: overrides.rank ?? 1,
|
|
})
|
|
.run();
|
|
}
|
|
|
|
export {
|
|
and,
|
|
count,
|
|
desc,
|
|
eq,
|
|
gte,
|
|
inArray,
|
|
isNotNull,
|
|
isNull,
|
|
lt,
|
|
notInArray,
|
|
or,
|
|
sql,
|
|
} from "drizzle-orm";
|