native/src/routes/SearchModalContainer.tsx
import React, { ReactElement, useMemo } from 'react'
import { SearchRouteType } from 'shared'
import { NavigationProps, RouteProps } from '../constants/NavigationTypes'
import useCityAppContext from '../hooks/useCityAppContext'
import useLoadCityContent from '../hooks/useLoadCityContent'
import LoadingErrorHandler from './LoadingErrorHandler'
import SearchModal from './SearchModal'
export type SearchModalContainerProps = {
navigation: NavigationProps<SearchRouteType>
route: RouteProps<SearchRouteType>
}
const SearchModalContainer = ({ navigation, route }: SearchModalContainerProps): ReactElement | null => {
const { cityCode, languageCode } = useCityAppContext()
const initialSearchText = route.params.searchText ?? ''
const { data, ...response } = useLoadCityContent({ cityCode, languageCode })
const allPossibleResults = useMemo(
() => [
...(data?.categories.toArray().filter(category => !category.isRoot()) || []),
...(data?.events || []),
...(data?.pois || []),
],
[data?.categories, data?.events, data?.pois],
)
return (
<LoadingErrorHandler {...response}>
{data && (
<SearchModal
cityCode={cityCode}
closeModal={navigation.goBack}
allPossibleResults={allPossibleResults}
languageCode={languageCode}
initialSearchText={initialSearchText}
/>
)}
</LoadingErrorHandler>
)
}
export default SearchModalContainer