NuvioStreaming/src/contexts/TraktContext.tsx
tapframe 237c1fae3d Enhance Trakt integration with support for watchlist, collection, and ratings
This update expands the Trakt integration by adding functionality to manage watchlist items, collections, and user ratings. New interfaces for TraktWatchlistItem, TraktCollectionItem, and TraktRatingItem have been introduced, along with corresponding methods in the TraktService to fetch this data. The useTraktIntegration hook has been updated to load all collections, and the LibraryScreen now displays these new categories, improving the overall user experience and content organization.
2025-06-20 00:07:46 +05:30

53 lines
No EOL
1.8 KiB
TypeScript

import React, { createContext, useContext, ReactNode } from 'react';
import { useTraktIntegration } from '../hooks/useTraktIntegration';
import {
TraktUser,
TraktWatchedItem,
TraktWatchlistItem,
TraktCollectionItem,
TraktRatingItem,
TraktPlaybackItem
} from '../services/traktService';
interface TraktContextProps {
isAuthenticated: boolean;
isLoading: boolean;
userProfile: TraktUser | null;
watchedMovies: TraktWatchedItem[];
watchedShows: TraktWatchedItem[];
watchlistMovies: TraktWatchlistItem[];
watchlistShows: TraktWatchlistItem[];
collectionMovies: TraktCollectionItem[];
collectionShows: TraktCollectionItem[];
continueWatching: TraktPlaybackItem[];
ratedContent: TraktRatingItem[];
checkAuthStatus: () => Promise<void>;
refreshAuthStatus: () => Promise<void>;
loadWatchedItems: () => Promise<void>;
loadAllCollections: () => Promise<void>;
isMovieWatched: (imdbId: string) => Promise<boolean>;
isEpisodeWatched: (imdbId: string, season: number, episode: number) => Promise<boolean>;
markMovieAsWatched: (imdbId: string, watchedAt?: Date) => Promise<boolean>;
markEpisodeAsWatched: (imdbId: string, season: number, episode: number, watchedAt?: Date) => Promise<boolean>;
forceSyncTraktProgress?: () => Promise<boolean>;
}
const TraktContext = createContext<TraktContextProps | undefined>(undefined);
export function TraktProvider({ children }: { children: ReactNode }) {
const traktIntegration = useTraktIntegration();
return (
<TraktContext.Provider value={traktIntegration}>
{children}
</TraktContext.Provider>
);
}
export function useTraktContext() {
const context = useContext(TraktContext);
if (context === undefined) {
throw new Error('useTraktContext must be used within a TraktProvider');
}
return context;
}