import React, { FunctionComponent, useEffect, useState } from 'react'; import { appRouter } from '../appRouter'; import globalize from '../../scripts/globalize'; import ServerConnections from '../ServerConnections'; import '../../elements/emby-button/emby-button'; // There seems to be some compatibility issues here between // React and our legacy web components, so we need to inject // them as an html string for now =/ const createSuggestionLink = ({name, href}) => ({ __html: `${name}` }); type SearchSuggestionsProps = { serverId?: string; parentId?: string; } const SearchSuggestions: FunctionComponent = ({ serverId = window.ApiClient.serverId(), parentId }: SearchSuggestionsProps) => { const [ suggestions, setSuggestions ] = useState([]); useEffect(() => { const apiClient = ServerConnections.getApiClient(serverId); apiClient.getItems(apiClient.getCurrentUserId(), { SortBy: 'IsFavoriteOrLiked,Random', IncludeItemTypes: 'Movie,Series,MusicArtist', Limit: 20, Recursive: true, ImageTypeLimit: 0, EnableImages: false, ParentId: parentId, EnableTotalRecordCount: false }).then(result => setSuggestions(result.Items)); }, [parentId, serverId]); return ( {globalize.translate('Suggestions')} {suggestions.map(item => ( ))} ); }; export default SearchSuggestions;