import React from 'react';
import { Searching, SearchResultGrid } from './SearchResultGrid';
import { SearchResultTabs } from './SearchResultTabs';
import { SearchStatus } from './SearchStatus';
import type { ISearchResultSet } from '../infrastructure/infrastructureSearch.service';
import type { SearchResultType } from './searchResultType';
import './searchResults.less';
export interface ISearchResultsProps {
selectedTab: string;
resultSets: ISearchResultSet[];
isSearching: boolean;
}
export interface ISearchResultsState {
active: SearchResultType;
}
const NoResults = () => (
No results found for the specified search query
);
export class SearchResults extends React.Component {
public state = { active: null as any };
public componentWillReceiveProps(newProps: ISearchResultsProps): void {
const { resultSets, selectedTab } = newProps;
const active: SearchResultType = resultSets.map((x) => x.type).find((type) => type.id === selectedTab);
this.setState({ active });
}
public render() {
const { resultSets, isSearching } = this.props;
const { active } = this.state;
const activeResultSet = active && resultSets.find((resultSet) => resultSet.type === active);
const noResults = resultSets.every((r) => r.status === SearchStatus.FINISHED && r.results.length === 0);
return (
{activeResultSet && }
{!activeResultSet && isSearching && }
{noResults && !active && }
);
}
}