diff --git a/app/(auth)/(tabs)/index.tsx b/app/(auth)/(tabs)/index.tsx index 926d1b8b..bd6df979 100644 --- a/app/(auth)/(tabs)/index.tsx +++ b/app/(auth)/(tabs)/index.tsx @@ -3,11 +3,18 @@ import { Text } from "@/components/common/Text"; import ContinueWatchingPoster from "@/components/ContinueWatchingPoster"; import { ItemCardText } from "@/components/ItemCardText"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; -import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { + BaseItemDto, + ItemFields, + ItemFilter, +} from "@jellyfin/sdk/lib/generated-client/models"; +import { + getChannelsApi, getItemsApi, getSuggestionsApi, getTvShowsApi, + getUserApi, + getUserLibraryApi, } from "@jellyfin/sdk/lib/utils/api"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { useRouter } from "expo-router"; @@ -23,6 +30,7 @@ import { import NetInfo, { NetInfoState } from "@react-native-community/netinfo"; import { Button } from "@/components/Button"; import { Ionicons } from "@expo/vector-icons"; +import MoviePoster from "@/components/MoviePoster"; export default function index() { const router = useRouter(); @@ -97,6 +105,52 @@ export default function index() { staleTime: 0, }); + const movieCollectionId = useMemo(() => { + return collections?.find((c) => c.CollectionType === "movies")?.Id; + }, [collections]); + + const tvShowCollectionId = useMemo(() => { + return collections?.find((c) => c.CollectionType === "tvshows")?.Id; + }, [collections]); + + const { data: recentlyAddedInMovies } = useQuery({ + queryKey: ["recentlyAddedInMovies", user?.Id, movieCollectionId], + queryFn: async () => + (api && + ( + await getUserLibraryApi(api).getLatestMedia({ + userId: user?.Id, + limit: 50, + fields: ["PrimaryImageAspectRatio", "Path"], + imageTypeLimit: 1, + enableImageTypes: ["Primary", "Backdrop", "Thumb"], + parentId: movieCollectionId, + }) + ).data) || + [], + enabled: !!api && !!user?.Id && !!movieCollectionId, + staleTime: 60, + }); + + const { data: recentlyAddedInTVShows } = useQuery({ + queryKey: ["recentlyAddedInTVShows", user?.Id, tvShowCollectionId], + queryFn: async () => + (api && + ( + await getUserLibraryApi(api).getLatestMedia({ + userId: user?.Id, + limit: 50, + fields: ["PrimaryImageAspectRatio", "Path"], + imageTypeLimit: 1, + enableImageTypes: ["Primary", "Backdrop", "Thumb"], + parentId: tvShowCollectionId, + }) + ).data) || + [], + enabled: !!api && !!user?.Id && !!tvShowCollectionId, + staleTime: 60, + }); + const { data: suggestions } = useQuery({ queryKey: ["suggestions", user?.Id], queryFn: async () => @@ -118,6 +172,7 @@ export default function index() { await queryClient.refetchQueries({ queryKey: ["resumeItems", user?.Id] }); await queryClient.refetchQueries({ queryKey: ["items", user?.Id] }); await queryClient.refetchQueries({ queryKey: ["suggestions", user?.Id] }); + await queryClient.refetchQueries({ queryKey: ["recentlyAddedInMovies"] }); setLoading(false); }, [queryClient, user?.Id]); @@ -125,7 +180,9 @@ export default function index() { useEffect(() => { const unsubscribe = NetInfo.addEventListener((state) => { - setIsConnected(state.isConnected); + if (state.isConnected == false || state.isInternetReachable === false) + setIsConnected(false); + else setIsConnected(true); }); NetInfo.fetch().then((state) => { @@ -184,69 +241,124 @@ export default function index() { } > - - Continue Watching - - data={data} - renderItem={(item, index) => ( - router.push(`/items/${item.Id}/page`)} - className="flex flex-col w-48" - > - + + + + Continue Watching + + + data={data} + renderItem={(item, index) => ( + router.push(`/items/${item.Id}/page`)} + className="flex flex-col w-48" + > + + + + + + )} + /> + + + + Next Up + + data={nextUpData} + renderItem={(item, index) => ( + router.push(`/items/${item.Id}/page`)} + className="flex flex-col w-48" + > + + + + + + )} + /> + + + + + Recently Added in Movies + + + data={recentlyAddedInMovies} + renderItem={(item, index) => ( + router.push(`/items/${item.Id}/page`)} + className="flex flex-col w-32" + > + + + + + + )} + /> + + + + + Recently Added in TV-Shows + + + data={recentlyAddedInTVShows} + renderItem={(item, index) => ( + router.push(`/series/${item.Id}/page`)} + className="flex flex-col w-32" + > + + + + + + )} + /> + + + + Collections + + data={collections} + renderItem={(item, index) => ( + router.push(`/collections/${item.Id}/page`)} + className="flex flex-col w-48" + > + + + + + + )} + /> + + + + Suggestions + + data={suggestions} + renderItem={(item, index) => ( + router.push(`/items/${item.Id}/page`)} + className="flex flex-col w-48" + > - - - )} - /> - Next Up - - data={nextUpData} - renderItem={(item, index) => ( - router.push(`/items/${item.Id}/page`)} - className="flex flex-col w-48" - > - - - - - - )} - /> - Collections - - data={collections} - renderItem={(item, index) => ( - router.push(`/collections/${item.Id}/page`)} - className="flex flex-col w-48" - > - - - - - - )} - /> - Suggestions - - data={suggestions} - renderItem={(item, index) => ( - router.push(`/items/${item.Id}/page`)} - className="flex flex-col w-48" - > - - - - )} - /> + + )} + /> + );