-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2926: Fallback language in search function #3024
base: main
Are you sure you want to change the base?
Changes from all commits
04f8710
f4cd441
78170ac
d111ff7
eb6cf41
0245b3f
0696cb9
5b6bf61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import React, { ReactElement, useMemo } from 'react' | ||
|
||
import { SearchRouteType } from 'shared' | ||
import { CategoriesMapModel, EventModel, PoiModel } from 'shared/api' | ||
import { formatPossibleSearchResults } from 'shared/hooks/useSearch' | ||
import { config } from 'translations' | ||
|
||
import { NavigationProps, RouteProps } from '../constants/NavigationTypes' | ||
import useCityAppContext from '../hooks/useCityAppContext' | ||
|
@@ -13,18 +16,24 @@ | |
route: RouteProps<SearchRouteType> | ||
} | ||
|
||
const useMemoizeResults = ( | ||
categories?: CategoriesMapModel | null, | ||
events?: EventModel[] | null, | ||
pois?: PoiModel[] | null, | ||
) => useMemo(() => formatPossibleSearchResults(categories, events, pois), [categories, events, pois]) | ||
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 Do we really have to memoize this? Doesn't really look calculation intense at all 🙈 |
||
|
||
const SearchModalContainer = ({ navigation, route }: SearchModalContainerProps): ReactElement | null => { | ||
const { cityCode, languageCode } = useCityAppContext() | ||
const initialSearchText = route.params.searchText ?? '' | ||
const { data, ...response } = useLoadCityContent({ cityCode, languageCode }) | ||
const { data: fallbackData } = useLoadCityContent({ cityCode, languageCode: config.sourceLanguage }) | ||
|
||
const allPossibleResults = useMemoizeResults(data?.categories, data?.events, data?.pois) | ||
|
||
const allPossibleResults = useMemo( | ||
() => [ | ||
...(data?.categories.toArray().filter(category => !category.isRoot()) || []), | ||
...(data?.events || []), | ||
...(data?.pois || []), | ||
], | ||
[data?.categories, data?.events, data?.pois], | ||
const allPossibleFallbackResults = useMemoizeResults( | ||
fallbackData?.categories, | ||
fallbackData?.events, | ||
fallbackData?.pois, | ||
) | ||
|
||
return ( | ||
|
@@ -34,6 +43,7 @@ | |
cityCode={cityCode} | ||
closeModal={navigation.goBack} | ||
allPossibleResults={allPossibleResults} | ||
allPossibleFallbackResults={allPossibleFallbackResults} | ||
languageCode={languageCode} | ||
initialSearchText={initialSearchText} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
ExtendedPageModel, | ||
useLoadFromEndpoint, | ||
} from 'shared/api' | ||
import { formatPossibleSearchResults } from 'shared/hooks/useSearch' | ||
|
||
type UseAllPossibleSearchResultsProps = { | ||
city: string | ||
|
@@ -27,19 +28,19 @@ | |
}: UseAllPossibleSearchResultsProps): UseAllPossibleSearchResultsReturn => { | ||
const params = { city, language } | ||
|
||
const { data: categories, ...categoriesReturn } = useLoadFromEndpoint(createCategoriesEndpoint, cmsApiBaseUrl, params) | ||
const { data: events, ...eventsReturn } = useLoadFromEndpoint(createEventsEndpoint, cmsApiBaseUrl, params) | ||
const { data: pois, ...poisReturn } = useLoadFromEndpoint(createPOIsEndpoint, cmsApiBaseUrl, params) | ||
const categories = useLoadFromEndpoint(createCategoriesEndpoint, cmsApiBaseUrl, params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 In theory we could perhaps add a parameter Probably only really works well for web though, so not sure if its a good idea. |
||
const events = useLoadFromEndpoint(createEventsEndpoint, cmsApiBaseUrl, params) | ||
const pois = useLoadFromEndpoint(createPOIsEndpoint, cmsApiBaseUrl, params) | ||
|
||
const allPossibleResults = useMemo( | ||
() => [...(categories?.toArray().filter(category => !category.isRoot()) || []), ...(events || []), ...(pois || [])], | ||
[categories, events, pois], | ||
() => formatPossibleSearchResults(categories.data, events.data, pois.data), | ||
[categories.data, events.data, pois.data], | ||
) | ||
Comment on lines
35
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 Same as for native |
||
|
||
return { | ||
data: allPossibleResults, | ||
loading: categoriesReturn.loading || eventsReturn.loading || poisReturn.loading, | ||
error: categoriesReturn.error || eventsReturn.error || poisReturn.error, | ||
loading: categories.loading || events.loading || pois.loading, | ||
error: categories.error || events.error || pois.error, | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { useLocation, useNavigate } from 'react-router-dom' | |
import styled from 'styled-components' | ||
|
||
import { parseHTML, pathnameFromRouteInformation, SEARCH_ROUTE, useSearch } from 'shared' | ||
import { config } from 'translations' | ||
|
||
import { CityRouteProps } from '../CityContentSwitcher' | ||
import CityContentLayout, { CityContentLayoutProps } from '../components/CityContentLayout' | ||
|
@@ -45,8 +46,16 @@ const SearchPage = ({ city, cityCode, languageCode, pathname }: CityRouteProps): | |
language: languageCode, | ||
cmsApiBaseUrl, | ||
}) | ||
const mainResults = useSearch(allPossibleResults, query) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 I think something like |
||
|
||
const results = useSearch(allPossibleResults, query) | ||
const { data: allPossibleFallbackResults } = useAllPossibleSearchResults({ | ||
city: cityCode, | ||
language: config.sourceLanguage, | ||
cmsApiBaseUrl, | ||
}) | ||
const fallbackResults = useSearch(allPossibleFallbackResults, query) | ||
|
||
const results = mainResults?.length === 0 ? fallbackResults : mainResults | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 See native above |
||
|
||
if (!city) { | ||
return null | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Hmmm.... I think minisearch often returns search results even if there are no direct matches in the content. What is the reason to not always returning both (main results first, fallback concatenated afterwards)?