Files
streamyfin/components/search/SearchItemWrapper.tsx
Alex ca92f61900 refactor: Feature/offline mode rework (#859)
Co-authored-by: lostb1t <coding-mosses0z@icloud.com>
Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com>
Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com>
Co-authored-by: Gauvino <uruknarb20@gmail.com>
Co-authored-by: storm1er <le.storm1er@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com>
Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com>
Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
2025-08-15 21:34:22 +02:00

48 lines
1.3 KiB
TypeScript

import { FlashList } from "@shopify/flash-list";
import { useAtom } from "jotai";
import type React from "react";
import type { PropsWithChildren } from "react";
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
import { Text } from "../common/Text";
type SearchItemWrapperProps<T> = {
items?: T[];
renderItem: (item: any) => React.ReactNode;
header?: string;
onEndReached?: (() => void) | null | undefined;
};
export const SearchItemWrapper = <T,>({
items,
renderItem,
header,
onEndReached,
}: PropsWithChildren<SearchItemWrapperProps<T>>) => {
const [_api] = useAtom(apiAtom);
const [_user] = useAtom(userAtom);
if (!items || items.length === 0) return null;
return (
<>
<Text className='font-bold text-lg px-4 mb-2'>{header}</Text>
<FlashList
horizontal
contentContainerStyle={{
paddingHorizontal: 16,
paddingBottom: 8,
}}
showsHorizontalScrollIndicator={false}
keyExtractor={(_, index) => index.toString()}
estimatedItemSize={250}
/*@ts-expect-error */
data={items}
onEndReachedThreshold={1}
onEndReached={onEndReached}
//@ts-expect-error
renderItem={({ item }) => (item ? renderItem(item) : null)}
/>
</>
);
};