import React from 'react' import SearchResults from './SearchResults' import LoadingAnimation from '../Loading/LoadingAnimation' import ErrorLoadingData from '../Errors/ErrorLoadingData' import fetchFreeBlockSearchResults from '../../api/fetchFreeBlockSearchResults' import GridWrapper from '../Grid/GridWrapper' import GridItem from '../Grid/GridItem' import { Link, useRouteMatch } from 'react-router-dom' import styles from './SearchWrapper.module.scss' import MainHeading from '../Titles/MainHeading' const SearchWrapper = ({ searchParams, onSearchSubmitted }) => { const { url } = useRouteMatch() const { loading, data, error } = fetchFreeBlockSearchResults(searchParams) const aggregations = !loading && !error && data && data.meta ? data.meta : {} if (loading) return if (error) return if (!data || !data.meta) return const currentCategoryName = searchParams.category ? aggregations.categories.reduce((i, k) => { return k.key === searchParams.category ? k.value : i }, '') : null return ( <>
All Categories
{aggregations.categories.map(category => (
{category.value}
))}
{!searchParams.category ? ( {aggregations.categories.map(category => ( {category.value} ))} ) : ( )} ) } export default SearchWrapper