Skip to content

Commit

Permalink
CR: update
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss committed Apr 1, 2023
1 parent 962d76d commit 07fbfc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/Nfts/Nfts.tsx
Expand Up @@ -6,7 +6,7 @@ import {SafeAreaView} from 'react-native-safe-area-context'
import {Icon, Spacer} from '../components'
import {useSearch} from '../Search/SearchContext'
import {useSelectedWallet} from '../SelectedWallet'
import {useNfts} from '../yoroi-wallets'
import {useNfts, YoroiNft} from '../yoroi-wallets'
import {filterNfts} from './filterNfts'
import {ImageGallery, SkeletonGallery} from './ImageGallery'
import {useNavigateTo} from './navigation'
Expand All @@ -25,9 +25,11 @@ export const Nfts = () => {
})

const {search: nftsSearchTerm} = useSearch()
const nftsSearchResult = filterNfts(nftsSearchTerm, nfts).sort((nftA, nftB) => nftA.name.localeCompare(nftB.name))
const sortedNfts = sortNfts(nfts)
const nftsSearchResult = filterNfts(nftsSearchTerm, sortedNfts)

const handleNftSelect = (index: number) => navigateTo.nftDetails(nftsSearchResult[index].id)
const hasEmptySearchResult = nftsSearchTerm.length > 0 && nftsSearchResult.length === 0

const onRefresh = React.useCallback(() => {
setIsManualRefreshing(true)
Expand All @@ -50,7 +52,7 @@ export const Nfts = () => {
)
}

if (nftsSearchTerm.length > 0 && nftsSearchResult.length === 0) {
if (hasEmptySearchResult) {
return (
<ScreenWrapper>
<ScrollView
Expand Down Expand Up @@ -178,6 +180,8 @@ function LoadingScreen({nftsCount}: {nftsCount: number}) {
)
}

const sortNfts = (nfts: YoroiNft[]): YoroiNft[] => nfts.sort((nftA, nftB) => nftA.name.localeCompare(nftB.name))

const styles = StyleSheet.create({
safeAreaView: {
flex: 1,
Expand Down
8 changes: 3 additions & 5 deletions src/Nfts/filterNfts.ts
@@ -1,10 +1,8 @@
import {YoroiNft} from '../yoroi-wallets'

export const filterNfts = (nftsSearchTerm: string, nfts: YoroiNft[]): YoroiNft[] => {
const searchTermLowerCase = nftsSearchTerm.toLowerCase()
export const filterNfts = (searchTerm: string, nfts: YoroiNft[]): YoroiNft[] => {
const searchTermLowerCase = searchTerm.toLowerCase()
const filteredNfts =
searchTermLowerCase.length > 0 && nfts.length > 0
? nfts.filter((nft) => nft.name.toLowerCase().includes(searchTermLowerCase))
: nfts
searchTermLowerCase.length > 0 ? nfts.filter((nft) => nft.name.toLowerCase().includes(searchTermLowerCase)) : nfts
return filteredNfts
}

0 comments on commit 07fbfc8

Please sign in to comment.