From 4bb992fc67fd6e2ff9928be0528ac8a66efca502 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 12 Jun 2023 00:50:55 +0900 Subject: [PATCH] Add header props on infinite lists --- front/packages/ui/src/details/season.tsx | 7 +- front/packages/ui/src/details/show.tsx | 80 ++++++++++---------- front/packages/ui/src/fetch-infinite.tsx | 10 ++- front/packages/ui/src/fetch-infinite.web.tsx | 9 ++- 4 files changed, 58 insertions(+), 48 deletions(-) diff --git a/front/packages/ui/src/details/season.tsx b/front/packages/ui/src/details/season.tsx index 09fcdf2a..3ee692f1 100644 --- a/front/packages/ui/src/details/season.tsx +++ b/front/packages/ui/src/details/season.tsx @@ -27,14 +27,16 @@ import { episodeDisplayNumber, EpisodeLine } from "./episode"; import { useTranslation } from "react-i18next"; import { ComponentType } from "react"; -export const EpisodeList = ({ +export const EpisodeList = ({ slug, season, Header, + headerProps, }: { slug: string; season: string | number; - Header: ComponentType<{ children: JSX.Element }>; + Header: ComponentType; + headerProps: Props }) => { const { t } = useTranslation(); @@ -46,6 +48,7 @@ export const EpisodeList = ({ empty={t("show.episode-none")} divider Header={Header} + headerProps={headerProps} > {(item) => ( { const { css } = useYoshiki(); @@ -42,6 +42,44 @@ const SvgWave = (props: SvgProps) => { ); }; +const ShowHeader = forwardRef(function _ShowHeader({ children, slug, ...props }, ref) { + const { css, theme } = useYoshiki(); + + return ( + theme.background }, + Platform.OS === "web" && { + flexGrow: 1, + flexShrink: 1, + // @ts-ignore Web only property + overflow: "auto" as any, + // @ts-ignore Web only property + overflowX: "hidden", + // @ts-ignore Web only property + overflowY: "overlay", + }, + ], + props, + )} + > + {/* TODO: Remove the slug quickfix for the play button */} +
+ {/* */} + + {/* */} + + {children} + + + ); + }); + const query = (slug: string): QueryIdentifier => ({ parser: ShowP, path: ["shows", slug], @@ -51,49 +89,11 @@ const query = (slug: string): QueryIdentifier => ({ }); export const ShowDetails: QueryPage<{ slug: string; season: string }> = ({ slug, season }) => { - const { css, theme } = useYoshiki(); - - const ShowHeader = forwardRef(function _ShowHeader({ children, ...props }, ref) { - return ( - theme.background }, - Platform.OS === "web" && { - flexGrow: 1, - flexShrink: 1, - // @ts-ignore Web only property - overflow: "auto" as any, - // @ts-ignore Web only property - overflowX: "hidden", - // @ts-ignore Web only property - overflowY: "overlay", - }, - ], - props, - )} - > - {/* TODO: Remove the slug quickfix for the play button */} -
- {/* */} - - {/* */} - - {children} - - - ); - }); - return ( {({ css, theme }) => ( - + )} diff --git a/front/packages/ui/src/fetch-infinite.tsx b/front/packages/ui/src/fetch-infinite.tsx index 28b00826..7200d5f2 100644 --- a/front/packages/ui/src/fetch-infinite.tsx +++ b/front/packages/ui/src/fetch-infinite.tsx @@ -21,10 +21,10 @@ import { Page, QueryIdentifier, useInfiniteFetch } from "@kyoo/models"; import { useBreakpointMap, HR } from "@kyoo/primitives"; import { FlashList } from "@shopify/flash-list"; -import { ComponentType, ReactElement } from "react"; +import { ComponentType, isValidElement, ReactElement } from "react"; import { EmptyView, ErrorView, Layout, WithLoading } from "./fetch"; -export const InfiniteFetch = ({ +export const InfiniteFetch = ({ query, placeholderCount = 15, suspense = false, @@ -34,6 +34,7 @@ export const InfiniteFetch = ({ empty, divider = false, Header, + headerProps, ...props }: { query: QueryIdentifier; @@ -47,7 +48,8 @@ export const InfiniteFetch = ({ empty?: string | JSX.Element; suspense?: boolean; divider?: boolean | ComponentType; - Header?: ComponentType<{ children: JSX.Element }> | ReactElement; + Header?: ComponentType | ReactElement; + headerProps?: Props }): JSX.Element | null => { if (!query.infinite) console.warn("A non infinite query was passed to an InfiniteFetch."); @@ -71,6 +73,8 @@ export const InfiniteFetch = ({ (_, i) => ({ id: `gen${i}`, isLoading: true } as Data), ); + // @ts-ignore + if (headerProps && !isValidElement(Header)) Header =
return ( children({ isLoading: false, ...item } as any, index)} diff --git a/front/packages/ui/src/fetch-infinite.web.tsx b/front/packages/ui/src/fetch-infinite.web.tsx index f46fa169..72bc6262 100644 --- a/front/packages/ui/src/fetch-infinite.web.tsx +++ b/front/packages/ui/src/fetch-infinite.web.tsx @@ -24,7 +24,7 @@ import { ComponentType, Fragment, isValidElement, ReactElement, useRef } from "r import { Stylable, useYoshiki } from "yoshiki"; import { EmptyView, ErrorView, Layout, WithLoading } from "./fetch"; -const InfiniteScroll = ({ +const InfiniteScroll = ({ children, loader, layout = "vertical", @@ -32,6 +32,7 @@ const InfiniteScroll = ({ hasMore = true, isFetching, Header, + headerProps, ...props }: { children?: ReactElement | (ReactElement | null)[] | null; @@ -40,7 +41,8 @@ const InfiniteScroll = ({ loadMore: () => void; hasMore: boolean; isFetching: boolean; - Header: ComponentType<{ children: JSX.Element }> | ReactElement | undefined; + Header?: ComponentType | ReactElement; + headerProps?: Props } & Stylable) => { const ref = useRef(null); const { css } = useYoshiki(); @@ -89,7 +91,8 @@ const InfiniteScroll = ({ ); if (!Header) return list({ ...scrollProps, ...props }); - if (!isValidElement(Header)) return
{list(props)}
; + // @ts-ignore + if (!isValidElement(Header)) return
{list(props)}
; return ( <> {Header}