-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global Search: - Only show MainNet results by default; the rest only upon request. - Group results by network and not scopes. - Inside network sections, sort results by paratime. Scoped search: - Filter out other paratimes earlier in the process, and simplify data flow - Before redirecting, also consider other results Generel: - Remove some unnecessary variables in conditions Just write the calculations inside the expressions, it makes it easier to understand.
- Loading branch information
Showing
4 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
63 changes: 51 additions & 12 deletions
63
src/app/pages/SearchResultsPage/GlobalSearchResultsView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,73 @@ | ||
import { FC } from 'react' | ||
import { FC, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { getFilterForScope, getKeyForScope, getNameForScope } from '../../../types/searchScope' | ||
import { RouteUtils } from '../../utils/route-utils' | ||
import { SearchResults } from './hooks' | ||
import { NoResults } from './NoResults' | ||
import { NoResultsOnMainnet, NoResultsWhatsoever } from './NoResults' | ||
import { SearchResultsList } from './SearchResultsList' | ||
import { AllTokenPrices } from '../../../coin-gecko/api' | ||
import { | ||
getFilterForNetwork, | ||
getNetworkNames, | ||
isNotMainnet, | ||
isNotOnMainnet, | ||
isOnMainnet, | ||
Network, | ||
} from '../../../types/network' | ||
import { HideMoreResults, ShowMoreResults } from './notifications' | ||
import { getThemesForNetworks } from '../../../styles/theme' | ||
import { orderByLayer } from '../../../types/layers' | ||
import { useRedirectIfSingleResult } from './useRedirectIfSingleResult' | ||
|
||
export const GlobalSearchResultsView: FC<{ searchResults: SearchResults; tokenPrices: AllTokenPrices }> = ({ | ||
searchResults, | ||
tokenPrices, | ||
}) => { | ||
const { t } = useTranslation() | ||
const [othersOpen, setOthersOpen] = useState(false) | ||
useRedirectIfSingleResult(undefined, searchResults) | ||
|
||
return searchResults.length === 0 ? ( | ||
<NoResults /> | ||
) : ( | ||
const themes = getThemesForNetworks() | ||
const networkNames = getNetworkNames(t) | ||
const otherNetworks = RouteUtils.getEnabledNetworks().filter(isNotMainnet) | ||
const notificationTheme = themes[Network.testnet] | ||
const mainnetResults = searchResults.filter(isOnMainnet).sort(orderByLayer) | ||
const otherResults = searchResults.filter(isNotOnMainnet).sort(orderByLayer) | ||
|
||
return ( | ||
<> | ||
{RouteUtils.getEnabledSearchScopes().map(scope => ( | ||
{!mainnetResults.length && (otherResults.length ? <NoResultsOnMainnet /> : <NoResultsWhatsoever />)} | ||
{ | ||
<SearchResultsList | ||
key={getKeyForScope(scope)} | ||
title={getNameForScope(t, scope)} | ||
searchResults={searchResults.filter(getFilterForScope(scope))} | ||
networkForTheme={scope.network} | ||
key={Network.mainnet} | ||
title={networkNames[Network.mainnet]} | ||
searchResults={mainnetResults} | ||
networkForTheme={Network.mainnet} | ||
tokenPrices={tokenPrices} | ||
/> | ||
))} | ||
} | ||
{otherResults.length !== 0 && | ||
(othersOpen ? ( | ||
<> | ||
<HideMoreResults theme={notificationTheme} onHide={() => setOthersOpen(false)} /> | ||
{otherNetworks.map(net => ( | ||
<SearchResultsList | ||
key={net} | ||
title={networkNames[net]} | ||
searchResults={otherResults.filter(getFilterForNetwork(net))} | ||
networkForTheme={net} | ||
tokenPrices={tokenPrices} | ||
/> | ||
))} | ||
</> | ||
) : ( | ||
<ShowMoreResults | ||
theme={notificationTheme} | ||
hasWantedResults={!!mainnetResults.length} | ||
otherResultsCount={otherResults.length} | ||
onShow={() => setOthersOpen(true)} | ||
/> | ||
))} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters