import * as React from 'react'; import { connectHits, InstantSearch } from 'react-instantsearch-dom'; import styled from 'styled-components'; import { FeatureLink } from 'ts/components/docs/tools/feature_link'; import { Resource } from 'ts/components/docs/resource/resource'; import { Filters } from 'ts/components/docs/sidebar/filters'; import { Heading } from 'ts/components/text'; import { Columns } from 'ts/components/docs/layout/columns'; import { ContentWrapper } from 'ts/components/docs/layout/content_wrapper'; import { DocsPageLayout } from 'ts/components/docs/layout/docs_page_layout'; import { Separator } from 'ts/components/docs/separator'; import { searchClient, searchIndices } from 'ts/utils/algolia_search'; interface IHitsProps { hits: IHit[]; } interface IHit { description: string; difficulty: string; id: number | string; isCommunity?: boolean; isFeatured?: boolean; objectID: string; tags?: string[]; textContent: string; title: string; type?: string; url: string; _highlightResult: any; _snippetResult: any; } export const DocsTools: React.FC = () => { return ( ); }; function getUniqueContentTypes(hits: IHit[]): string[] { const contentTypes: string[] = []; // @ts-ignore for (const hit of hits) { if (!contentTypes.includes(hit.type)) { contentTypes.push(hit.type); } } return contentTypes; } const Hits: React.FC = ({ hits }) => { const contentTypes = getUniqueContentTypes(hits); const featuredTools = hits.filter((hit: IHit) => hit.isFeatured); return ( <> {featuredTools.length > 0 && ( Featured Tools {featuredTools.map((hit: IHit, index: number) => ( ))} )} {contentTypes.map(type => { const filteredHits = hits.filter((hit: any) => hit.type === type); return ( {type} {filteredHits.map((hit: any, index: number) => ( ))} ); })} ); }; const CustomHits = connectHits(Hits); const FeaturedToolsWrapper = styled.div` margin-bottom: 50px; `; const ResourcesWrapper = styled.div` margin-bottom: 40px; `; const filters = [ { attribute: 'type', heading: 'Type' }, { attribute: 'tags', heading: 'Developer Persona' }, { attribute: 'difficulty', heading: 'Level' }, { attribute: 'isCommunity', heading: 'Community Maintained', customLabel: 'Include Community Maintained' }, ];