// Saved "smart views": per-user named snapshots of a module's filters, scoped by `source` // ("feed" | "plex"). Only touches core's req; `filters` is an opaque JSON blob (each module casts it // to its own filter shape), so this stays independent of feed.ts / plex.ts. import { req } from "./core"; // A module's saved filter snapshot. `filters` is opaque here — the feed reads it as FeedFilters, Plex // as PlexFilters; `source` is implicit (the caller queries per source). export interface SavedView { id: number; name: string; filters: Record; position: number; is_default: boolean; } // The module a view belongs to. "feed" is the default so existing callers keep working. type ViewSource = "feed" | "plex"; export const savedViewsApi = { savedViews: (source: ViewSource = "feed"): Promise => req(`/api/saved-views?source=${source}`), createView: ( name: string, filters: Record, source: ViewSource = "feed", ): Promise => req("/api/saved-views", { method: "POST", body: JSON.stringify({ name, filters, source }), }), updateView: ( id: number, patch: Partial<{ name: string; filters: Record; is_default: boolean }>, ): Promise => req(`/api/saved-views/${id}`, { method: "PATCH", body: JSON.stringify(patch) }), deleteView: (id: number): Promise<{ deleted: number }> => req(`/api/saved-views/${id}`, { method: "DELETE" }), reorderViews: (ids: number[]): Promise<{ ok: boolean }> => req("/api/saved-views/reorder", { method: "POST", body: JSON.stringify({ ids }) }), };