Implement basic search query

pull/1/head
J M Rossy 2 years ago
parent e551e01bc0
commit e48ad0a4fb
  1. 45
      src/features/search/MessageSearch.tsx
  2. 2
      src/utils/string.ts

@ -158,7 +158,9 @@ export function MessageSearch() {
}
imgSrc={ShrugIcon}
imgAlt="No results"
text="Sorry, no results found. Please try a different address or hash."
text={`Sorry, no results found. Please try ${
hasInput ? 'a different address or hash' : 'again later'
}.`}
imgWidth={110}
/>
{/* Search error state */}
@ -217,7 +219,7 @@ function getChainOptionList(): Array<{ value: string; display: string }> {
}
const latestMessagesQuery = `
query MessageDetails {
query LatestMessages {
message(order_by: {timestamp: desc}, limit: 8) {
destination
id
@ -241,18 +243,37 @@ query MessageDetails {
}
}`;
// TODO
const searchMessagesQuery = `
query searchMessages ($search: String!) {
messages (search: $search, order_by: {origintimesent: desc}, limit: 8) {
query SearchMessages ($search: bpchar!) {
message(
where: {
_or: [
{sender: {_eq: $search}},
{recipient: {_eq: $search}},
{transaction: {hash: {_eq: $search}}},
{delivered_message: {transaction: {hash: {_eq: $search}}}},
]
},
order_by: {timestamp: desc},
limit: 40) {
destination
id
status
sender
origin
recipient
body
originchainid
origintimesent
destinationchainid
destinationtimesent
sender
timestamp
delivered_message {
id
tx_id
inbox_address
}
message_states {
block_height
block_timestamp
error_msg
estimated_gas_cost
id
processable
}
}
}`;

@ -9,5 +9,5 @@ export function toTitleCase(str: string) {
const alphanumericRgex = /[^a-zA-Z0-9]/gi;
export function sanitizeString(str: string) {
if (!str || typeof str !== 'string') return '';
return str.replaceAll(alphanumericRgex, '');
return str.replaceAll(alphanumericRgex, '').toLowerCase();
}

Loading…
Cancel
Save