From e39c6e5321550951b8cc6196a9fd962772ca15b2 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 5 Sep 2019 08:59:21 -0700 Subject: [PATCH] Don't search conversations if searching within conversation --- app/sql.js | 2 +- ts/components/MainHeader.tsx | 4 ++-- ts/state/ducks/search.ts | 41 ++++++++++++------------------------ 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/app/sql.js b/app/sql.js index e628e31889..ffe263faac 100644 --- a/app/sql.js +++ b/app/sql.js @@ -1718,7 +1718,7 @@ async function searchConversations(query, { limit } = {}) { name LIKE $name OR profileName LIKE $profileName ) - ORDER BY id ASC + ORDER BY active_at DESC LIMIT $limit`, { $id: `%${query}%`, diff --git a/ts/components/MainHeader.tsx b/ts/components/MainHeader.tsx index bff57b17a9..d300d64937 100644 --- a/ts/components/MainHeader.tsx +++ b/ts/components/MainHeader.tsx @@ -76,7 +76,7 @@ export class MainHeader extends React.Component { searchConversationId, } = this.props; - if (searchDiscussions) { + if (searchDiscussions && !searchConversationId) { searchDiscussions(searchTerm, { noteToSelf: i18n('noteToSelf').toLowerCase(), ourNumber, @@ -89,7 +89,7 @@ export class MainHeader extends React.Component { regionCode, }); } - }, 50); + }, 200); public updateSearch = (event: React.FormEvent) => { const { diff --git a/ts/state/ducks/search.ts b/ts/state/ducks/search.ts index d65388f7f1..96c05cd965 100644 --- a/ts/state/ducks/search.ts +++ b/ts/state/ducks/search.ts @@ -67,14 +67,6 @@ type SearchDiscussionsResultsKickoffActionType = { payload: Promise; }; -type SearchMessagesResultsPendingActionType = { - type: 'SEARCH_MESSAGES_RESULTS_PENDING'; - payload: SearchMessagesResultsPayloadType; -}; -type SearchDiscussionsResultsPendingActionType = { - type: 'SEARCH_DISCUSSIONS_RESULTS_PENDING'; - payload: SearchDiscussionsResultsPayloadType; -}; type SearchMessagesResultsFulfilledActionType = { type: 'SEARCH_MESSAGES_RESULTS_FULFILLED'; payload: SearchMessagesResultsPayloadType; @@ -108,8 +100,6 @@ type SearchInConversationActionType = { export type SEARCH_TYPES = | SearchMessagesResultsKickoffActionType | SearchDiscussionsResultsKickoffActionType - | SearchMessagesResultsPendingActionType - | SearchDiscussionsResultsPendingActionType | SearchMessagesResultsFulfilledActionType | SearchDiscussionsResultsFulfilledActionType | UpdateSearchTermActionType @@ -327,9 +317,22 @@ export function reducer( const { payload } = action; const { query } = payload; + const hasQuery = Boolean(query && query.length >= 2); + const isWithinConversation = Boolean(state.searchConversationId); + return { ...state, query, + messagesLoading: hasQuery, + ...(hasQuery + ? { + messageIds: [], + messageLookup: {}, + discussionsLoading: !isWithinConversation, + contacts: [], + conversations: [], + } + : {}), }; } @@ -357,24 +360,6 @@ export function reducer( }; } - if (action.type === 'SEARCH_MESSAGES_RESULTS_PENDING') { - return { - ...state, - messageIds: [], - messageLookup: {}, - messagesLoading: true, - }; - } - - if (action.type === 'SEARCH_DISCUSSIONS_RESULTS_PENDING') { - return { - ...state, - contacts: [], - conversations: [], - discussionsLoading: true, - }; - } - if (action.type === 'SEARCH_MESSAGES_RESULTS_FULFILLED') { const { payload } = action; const { messages, normalizedPhoneNumber, query } = payload;