mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
127 lines
4.1 KiB
TypeScript
127 lines
4.1 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
|
import {
|
|
type QueryFunction,
|
|
type QueryKey,
|
|
useQuery,
|
|
} from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { ScrollView, View, type ViewProps } from "react-native";
|
|
import { Text } from "@/components/common/Text";
|
|
import MoviePoster from "@/components/posters/MoviePoster";
|
|
import ContinueWatchingPoster from "../ContinueWatchingPoster";
|
|
import { TouchableItemRouter } from "../common/TouchableItemRouter";
|
|
import { ItemCardText } from "../ItemCardText";
|
|
import SeriesPoster from "../posters/SeriesPoster";
|
|
|
|
interface Props extends ViewProps {
|
|
title?: string | null;
|
|
orientation?: "horizontal" | "vertical";
|
|
disabled?: boolean;
|
|
queryKey: QueryKey;
|
|
queryFn: QueryFunction<BaseItemDto[]>;
|
|
hideIfEmpty?: boolean;
|
|
}
|
|
|
|
export const ScrollingCollectionList: React.FC<Props> = ({
|
|
title,
|
|
orientation = "vertical",
|
|
disabled = false,
|
|
queryFn,
|
|
queryKey,
|
|
hideIfEmpty = false,
|
|
...props
|
|
}) => {
|
|
const { data, isLoading } = useQuery({
|
|
queryKey: queryKey,
|
|
queryFn,
|
|
staleTime: 0,
|
|
refetchOnMount: true,
|
|
refetchOnWindowFocus: true,
|
|
refetchOnReconnect: true,
|
|
});
|
|
|
|
const { t } = useTranslation();
|
|
|
|
if (hideIfEmpty === true && data?.length === 0) return null;
|
|
if (disabled || !title) return null;
|
|
|
|
return (
|
|
<View {...props}>
|
|
<Text className='px-4 text-lg font-bold mb-2 text-neutral-100'>
|
|
{title}
|
|
</Text>
|
|
{isLoading === false && data?.length === 0 && (
|
|
<View className='px-4'>
|
|
<Text className='text-neutral-500'>{t("home.no_items")}</Text>
|
|
</View>
|
|
)}
|
|
{isLoading ? (
|
|
<View
|
|
className={`
|
|
flex flex-row gap-2 px-4
|
|
`}
|
|
>
|
|
{[1, 2, 3].map((i) => (
|
|
<View className='w-44' key={i}>
|
|
<View className='bg-neutral-900 h-24 w-full rounded-md mb-1' />
|
|
<View className='rounded-md overflow-hidden mb-1 self-start'>
|
|
<Text
|
|
className='text-neutral-900 bg-neutral-900 rounded-md'
|
|
numberOfLines={1}
|
|
>
|
|
Nisi mollit voluptate amet.
|
|
</Text>
|
|
</View>
|
|
<View className='rounded-md overflow-hidden self-start mb-1'>
|
|
<Text
|
|
className='text-neutral-900 bg-neutral-900 text-xs rounded-md '
|
|
numberOfLines={1}
|
|
>
|
|
Lorem ipsum
|
|
</Text>
|
|
</View>
|
|
</View>
|
|
))}
|
|
</View>
|
|
) : (
|
|
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
|
|
<View className='px-4 flex flex-row'>
|
|
{data?.map((item) => (
|
|
<TouchableItemRouter
|
|
item={item}
|
|
key={item.Id}
|
|
className={`mr-2
|
|
${orientation === "horizontal" ? "w-44" : "w-28"}
|
|
`}
|
|
>
|
|
{item.Type === "Episode" && orientation === "horizontal" && (
|
|
<ContinueWatchingPoster item={item} />
|
|
)}
|
|
{item.Type === "Episode" && orientation === "vertical" && (
|
|
<SeriesPoster item={item} />
|
|
)}
|
|
{item.Type === "Movie" && orientation === "horizontal" && (
|
|
<ContinueWatchingPoster item={item} />
|
|
)}
|
|
{item.Type === "Movie" && orientation === "vertical" && (
|
|
<MoviePoster item={item} />
|
|
)}
|
|
{item.Type === "Series" && orientation === "vertical" && (
|
|
<SeriesPoster item={item} />
|
|
)}
|
|
{item.Type === "Series" && orientation === "horizontal" && (
|
|
<ContinueWatchingPoster item={item} />
|
|
)}
|
|
{item.Type === "Program" && (
|
|
<ContinueWatchingPoster item={item} />
|
|
)}
|
|
<ItemCardText item={item} />
|
|
</TouchableItemRouter>
|
|
))}
|
|
</View>
|
|
</ScrollView>
|
|
)}
|
|
</View>
|
|
);
|
|
};
|