"use client" import { LoadingSpinner } from "@scandic-hotels/design-system/LoadingSpinner" import { ShowMoreButton } from "@scandic-hotels/design-system/ShowMoreButton" import { trpc } from "@scandic-hotels/trpc/client" import Grids from "@/components/TempDesignSystem/Grids" import useLang from "@/hooks/useLang" import ListContainer from "../ListContainer" import OldStayCard from "../OldStayCard" import type { PreviousStaysClientProps, PreviousStaysNonNullResponseObject, } from "@/types/components/myPages/stays/previous" export function ClientPreviousStays({ initialPreviousStays, }: PreviousStaysClientProps) { const lang = useLang() const { data, isFetching, fetchNextPage, hasNextPage, isLoading } = trpc.user.stays.previous.useInfiniteQuery( { limit: 6, lang, }, { getNextPageParam: (lastPage) => { return lastPage?.nextCursor }, initialData: { pageParams: [undefined, 1], pages: [initialPreviousStays], }, } ) if (isLoading) { return } function loadMoreData() { if (hasNextPage) { fetchNextPage() } } const stays = data.pages .filter((page): page is PreviousStaysNonNullResponseObject => !!page?.data) .flatMap((page) => page.data) return ( {stays.map((stay) => ( ))} {hasNextPage ? ( ) : null} ) }