NuvioStreaming/src/contexts/TraktContext.tsx
tapframe cdec184c14 Integrate Trakt support into watch progress management
This update enhances the watch progress functionality by incorporating Trakt integration across various components. Key changes include the addition of Trakt-related properties in the watch progress state, improved synchronization logic, and enhanced UI elements to reflect Trakt sync status. The useTraktIntegration and useWatchProgress hooks have been updated to manage Trakt authentication and playback progress more effectively, ensuring a seamless user experience when tracking viewing history across devices.
2025-06-19 22:56:04 +05:30

39 lines
No EOL
1.4 KiB
TypeScript

import React, { createContext, useContext, ReactNode } from 'react';
import { useTraktIntegration } from '../hooks/useTraktIntegration';
import { TraktUser, TraktWatchedItem } from '../services/traktService';
interface TraktContextProps {
isAuthenticated: boolean;
isLoading: boolean;
userProfile: TraktUser | null;
watchedMovies: TraktWatchedItem[];
watchedShows: TraktWatchedItem[];
checkAuthStatus: () => Promise<void>;
refreshAuthStatus: () => Promise<void>;
loadWatchedItems: () => 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;
}