From e48ad0a4fb578c8abcfc8ed61c8434ad8e8c9cca Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Tue, 30 Aug 2022 15:43:31 -0400 Subject: [PATCH] Implement basic search query --- src/features/search/MessageSearch.tsx | 45 ++++++++++++++++++++------- src/utils/string.ts | 2 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/features/search/MessageSearch.tsx b/src/features/search/MessageSearch.tsx index 0a24443..69df676 100644 --- a/src/features/search/MessageSearch.tsx +++ b/src/features/search/MessageSearch.tsx @@ -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 + } } }`; diff --git a/src/utils/string.ts b/src/utils/string.ts index 071cd79..bf1e40f 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -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(); }