import { Medium, TranslatedHint, } from '@memori.ai/memori-api-client/dist/types'; import React, { useEffect, useState, memo } from 'react'; import Button from '../ui/Button'; import MediaItemWidget, { Props as MediaItemProps } from './MediaItemWidget'; import { Transition } from '@headlessui/react'; import cx from 'classnames'; import { useTranslation } from 'react-i18next'; export interface Props { hints?: TranslatedHint[]; links?: Medium[]; media?: (Medium & { type?: string })[]; simulateUserPrompt?: (item: string, translatedItem?: string) => void; sessionID?: string; baseUrl?: string; apiUrl?: string; translateTo?: string; customMediaRenderer?: MediaItemProps['customMediaRenderer']; fromUser?: boolean; } const MediaWidget: React.FC = ({ hints = [], links = [], media = [], simulateUserPrompt = () => {}, sessionID, baseUrl, apiUrl, translateTo, customMediaRenderer, fromUser = false, }: Props) => { const { t } = useTranslation(); const [showHints, setShowHints] = useState(true); const [hintsPagination, setHintsPagination] = useState(6); useEffect(() => { setShowHints(true); }, [hints]); return (
{(media?.length > 0 || links?.length > 0) && ( )} {hints?.length > 0 && showHints && ( <> {hints.slice(0, hintsPagination).map((item, index) => ( ))} {hints.length > hintsPagination && (
)} )}
); }; export default memo(MediaWidget);