-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40903 from software-mansion-labs/kicu/search-v1/s…
…earch-widget [Search v1] Create Search widget
- Loading branch information
Showing
19 changed files
with
221 additions
and
144 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/components/SelectionList/TemporaryTransactionListItem.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import Text from '@components/Text'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import type {SearchTransaction} from '@src/types/onyx/SearchResults'; | ||
|
||
// NOTE: This is a completely temporary mock item so that something can be displayed in SearchWidget | ||
// This should be removed and implement properly in: https://github.com/Expensify/App/issues/39877 | ||
function TransactionListItem({item}: {item: SearchTransaction}) { | ||
const styles = useThemeStyles(); | ||
return ( | ||
<View style={[styles.pt8]}> | ||
<Text>Item: {item.transactionID}</Text> | ||
</View> | ||
); | ||
} | ||
|
||
export default TransactionListItem; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type SearchParams = { | ||
query: string; | ||
hash: number; | ||
}; | ||
|
||
export default SearchParams; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import TransactionListItem from '@components/SelectionList/TemporaryTransactionListItem'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import type {SearchTransaction} from '@src/types/onyx/SearchResults'; | ||
import * as UserUtils from './UserUtils'; | ||
|
||
function getTransactionsSections(data: OnyxTypes.SearchResults['data']): SearchTransaction[] { | ||
return Object.entries(data) | ||
.filter(([key]) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) | ||
.map(([, value]) => value); | ||
} | ||
|
||
const searchTypeToItemMap = { | ||
transaction: { | ||
listItem: TransactionListItem, | ||
getSections: getTransactionsSections, | ||
}, | ||
}; | ||
|
||
/** | ||
* TODO: in future make this function generic and return specific item component based on type | ||
* For now only 1 search item type exists in the app so this function is simplified | ||
*/ | ||
function getListItem(): typeof TransactionListItem { | ||
return searchTypeToItemMap.transaction.listItem; | ||
} | ||
|
||
function getSections(data: OnyxTypes.SearchResults['data']): SearchTransaction[] { | ||
return searchTypeToItemMap.transaction.getSections(data); | ||
} | ||
|
||
function getQueryHash(query: string): number { | ||
return UserUtils.hashText(query, 2 ** 32); | ||
} | ||
|
||
export {getQueryHash, getListItem, getSections}; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import {READ_COMMANDS} from '@libs/API/types'; | ||
import * as SearchUtils from '@libs/SearchUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
let isNetworkOffline = false; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NETWORK, | ||
callback: (value) => { | ||
isNetworkOffline = value?.isOffline ?? false; | ||
}, | ||
}); | ||
|
||
function search(query: string) { | ||
if (isNetworkOffline) { | ||
return; | ||
} | ||
|
||
const hash = SearchUtils.getQueryHash(query); | ||
API.read(READ_COMMANDS.SEARCH, {query, hash}); | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
search, | ||
}; |
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
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
Oops, something went wrong.