);
}
+ override getSearchInput({
+ clearConversationSearch,
+ clearSearch,
+ i18n,
+ updateSearchTerm,
+ }: Readonly<{
+ clearConversationSearch: () => unknown;
+ clearSearch: () => unknown;
+ i18n: LocalizerType;
+ updateSearchTerm: (searchTerm: string) => unknown;
+ }>): ReactChild {
+ return (
+
+ );
+ }
+
override getPreRowsNode({
i18n,
- }: Readonly<{ i18n: LocalizerType }>): null | ReactChild {
+ }: Readonly<{
+ i18n: LocalizerType;
+ }>): ReactChild | null {
if (this.getRowCount() === 0) {
return (
diff --git a/ts/components/leftPane/LeftPaneSearchHelper.tsx b/ts/components/leftPane/LeftPaneSearchHelper.tsx
index affa8afd1655..fe0a4a899b33 100644
--- a/ts/components/leftPane/LeftPaneSearchHelper.tsx
+++ b/ts/components/leftPane/LeftPaneSearchHelper.tsx
@@ -1,4 +1,4 @@
-// Copyright 2021 Signal Messenger, LLC
+// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReactChild } from 'react';
@@ -11,6 +11,8 @@ import type { Row } from '../ConversationList';
import { RowType } from '../ConversationList';
import type { PropsData as ConversationListItemPropsType } from '../conversationList/ConversationListItem';
import { handleKeydownForSearch } from './handleKeydownForSearch';
+import type { ConversationType } from '../../state/ducks/conversations';
+import { LeftPaneMainSearchInput } from '../LeftPaneMainSearchInput';
import { Intl } from '../Intl';
import { Emojify } from '../conversation/Emojify';
@@ -37,6 +39,9 @@ export type LeftPaneSearchPropsType = {
searchConversationName?: string;
primarySendsSms: boolean;
searchTerm: string;
+ startSearchCounter: number;
+ searchDisabled: boolean;
+ searchConversation: undefined | ConversationType;
};
const searchResultKeys: Array<
@@ -61,30 +66,70 @@ export class LeftPaneSearchHelper extends LeftPaneHelper) {
super();
- this.conversationResults = conversationResults;
this.contactResults = contactResults;
+ this.conversationResults = conversationResults;
this.messageResults = messageResults;
- this.searchConversationName = searchConversationName;
this.primarySendsSms = primarySendsSms;
+ this.searchConversation = searchConversation;
+ this.searchConversationName = searchConversationName;
+ this.searchDisabled = searchDisabled;
this.searchTerm = searchTerm;
+ this.startSearchCounter = startSearchCounter;
+ }
+
+ override getSearchInput({
+ clearConversationSearch,
+ clearSearch,
+ i18n,
+ updateSearchTerm,
+ }: Readonly<{
+ clearConversationSearch: () => unknown;
+ clearSearch: () => unknown;
+ i18n: LocalizerType;
+ updateSearchTerm: (searchTerm: string) => unknown;
+ }>): ReactChild {
+ return (
+
+ );
}
override getPreRowsNode({
i18n,
- }: Readonly<{ i18n: LocalizerType }>): null | ReactChild {
+ }: Readonly<{
+ i18n: LocalizerType;
+ }>): ReactChild | null {
const mightHaveSearchResults = this.allResults().some(
searchResult => searchResult.isLoading || searchResult.results.length
);
+
if (mightHaveSearchResults) {
return null;
}
diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts
index 518ddac486a1..f15bc80630a2 100644
--- a/ts/state/selectors/conversations.ts
+++ b/ts/state/selectors/conversations.ts
@@ -1,4 +1,4 @@
-// Copyright 2019-2021 Signal Messenger, LLC
+// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import memoizee from 'memoizee';
@@ -133,25 +133,6 @@ export const getSelectedConversationId = createSelector(
}
);
-export const getSelectedConversation = createSelector(
- getSelectedConversationId,
- getConversationLookup,
- (
- selectedConversationId: string | undefined,
- conversationLookup: ConversationLookupType
- ): undefined | ConversationType => {
- if (!selectedConversationId) {
- return undefined;
- }
- const conversation = getOwn(conversationLookup, selectedConversationId);
- assert(
- conversation,
- 'getSelectedConversation: could not find selected conversation in lookup; returning undefined'
- );
- return conversation;
- }
-);
-
type SelectedMessageType = {
id: string;
counter: number;
diff --git a/ts/state/selectors/search.ts b/ts/state/selectors/search.ts
index f226b8cadc0a..ce5d72125b84 100644
--- a/ts/state/selectors/search.ts
+++ b/ts/state/selectors/search.ts
@@ -1,4 +1,4 @@
-// Copyright 2019-2021 Signal Messenger, LLC
+// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import memoizee from 'memoizee';
@@ -95,7 +95,14 @@ export const getSearchResults = createSelector(
state: SearchStateType,
searchConversationName,
conversationLookup: ConversationLookupType
- ): Omit => {
+ ): Pick<
+ LeftPaneSearchPropsType,
+ | 'conversationResults'
+ | 'contactResults'
+ | 'messageResults'
+ | 'searchConversationName'
+ | 'searchTerm'
+ > => {
const {
contactIds,
conversationIds,
diff --git a/ts/state/smart/LeftPane.tsx b/ts/state/smart/LeftPane.tsx
index b97a23857a73..701155036cfe 100644
--- a/ts/state/smart/LeftPane.tsx
+++ b/ts/state/smart/LeftPane.tsx
@@ -118,12 +118,18 @@ const getModeSpecificProps = (
return {
mode: LeftPaneMode.Search,
primarySendsSms,
+ searchConversation: getSearchConversation(state),
+ searchDisabled: state.network.challengeStatus !== 'idle',
+ startSearchCounter: getStartSearchCounter(state),
...getSearchResults(state),
};
}
return {
mode: LeftPaneMode.Inbox,
isAboutToSearchInAConversation: getIsSearchingInAConversation(state),
+ searchConversation: getSearchConversation(state),
+ searchDisabled: state.network.challengeStatus !== 'idle',
+ searchTerm: getQuery(state),
startSearchCounter: getStartSearchCounter(state),
...getLeftPaneLists(state),
};
diff --git a/ts/state/smart/MainHeader.tsx b/ts/state/smart/MainHeader.tsx
index 0c8b1e47fbb6..1e4aab908538 100644
--- a/ts/state/smart/MainHeader.tsx
+++ b/ts/state/smart/MainHeader.tsx
@@ -1,4 +1,4 @@
-// Copyright 2019-2021 Signal Messenger, LLC
+// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
@@ -8,11 +8,6 @@ import { MainHeader } from '../../components/MainHeader';
import type { StateType } from '../reducer';
import { getPreferredBadgeSelector } from '../selectors/badges';
-import {
- getQuery,
- getSearchConversation,
- getStartSearchCounter,
-} from '../selectors/search';
import {
getIntl,
getRegionCode,
@@ -21,18 +16,13 @@ import {
getUserNumber,
getUserUuid,
} from '../selectors/user';
-import { getMe, getSelectedConversation } from '../selectors/conversations';
+import { getMe } from '../selectors/conversations';
const mapStateToProps = (state: StateType) => {
const me = getMe(state);
return {
- disabled: state.network.challengeStatus !== 'idle',
hasPendingUpdate: Boolean(state.updates.didSnooze),
- searchTerm: getQuery(state),
- searchConversation: getSearchConversation(state),
- selectedConversation: getSelectedConversation(state),
- startSearchCounter: getStartSearchCounter(state),
regionCode: getRegionCode(state),
ourConversationId: getUserConversationId(state),
ourNumber: getUserNumber(state),
diff --git a/ts/test-both/state/selectors/conversations_test.ts b/ts/test-both/state/selectors/conversations_test.ts
index 4471fb9b86ff..734f8872b844 100644
--- a/ts/test-both/state/selectors/conversations_test.ts
+++ b/ts/test-both/state/selectors/conversations_test.ts
@@ -1,4 +1,4 @@
-// Copyright 2019-2021 Signal Messenger, LLC
+// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
@@ -39,7 +39,6 @@ import {
getNumberOfMessagesPendingBecauseOfVerification,
getPlaceholderContact,
getRecommendedGroupSizeModalState,
- getSelectedConversation,
getSelectedConversationId,
hasGroupCreationError,
isCreatingGroup,
@@ -1744,36 +1743,6 @@ describe('both/state/selectors/conversations', () => {
});
});
- describe('#getSelectedConversation', () => {
- it('returns undefined if no conversation is selected', () => {
- const state = {
- ...getEmptyRootState(),
- conversations: {
- ...getEmptyState(),
- conversationLookup: {
- abc123: makeConversation('abc123'),
- },
- },
- };
- assert.isUndefined(getSelectedConversation(state));
- });
-
- it('returns the selected conversation', () => {
- const conversation = makeConversation('abc123');
- const state = {
- ...getEmptyRootState(),
- conversations: {
- ...getEmptyState(),
- conversationLookup: {
- abc123: conversation,
- },
- selectedConversationId: 'abc123',
- },
- };
- assert.strictEqual(getSelectedConversation(state), conversation);
- });
- });
-
describe('#getContactNameColorSelector', () => {
it('returns the right color order sorted by UUID ASC', () => {
const group = makeConversation('group');
diff --git a/ts/test-node/components/leftPane/LeftPaneInboxHelper_test.tsx b/ts/test-node/components/leftPane/LeftPaneInboxHelper_test.tsx
index 024292d47e28..8512416b7728 100644
--- a/ts/test-node/components/leftPane/LeftPaneInboxHelper_test.tsx
+++ b/ts/test-node/components/leftPane/LeftPaneInboxHelper_test.tsx
@@ -1,4 +1,4 @@
-// Copyright 2021 Signal Messenger, LLC
+// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
@@ -12,10 +12,13 @@ import { LeftPaneInboxHelper } from '../../../components/leftPane/LeftPaneInboxH
describe('LeftPaneInboxHelper', () => {
const defaultProps: LeftPaneInboxPropsType = {
- conversations: [],
- pinnedConversations: [],
archivedConversations: [],
+ conversations: [],
isAboutToSearchInAConversation: false,
+ pinnedConversations: [],
+ searchConversation: undefined,
+ searchDisabled: false,
+ searchTerm: '',
startSearchCounter: 0,
};
diff --git a/ts/test-node/components/leftPane/LeftPaneSearchHelper_test.ts b/ts/test-node/components/leftPane/LeftPaneSearchHelper_test.ts
index a8c7e5f0dbb1..3cf81a8ce7a6 100644
--- a/ts/test-node/components/leftPane/LeftPaneSearchHelper_test.ts
+++ b/ts/test-node/components/leftPane/LeftPaneSearchHelper_test.ts
@@ -1,4 +1,4 @@
-// Copyright 2021 Signal Messenger, LLC
+// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
@@ -23,6 +23,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isUndefined(
@@ -44,6 +47,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}).getRowCount(),
100
);
@@ -57,6 +63,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}).getRowCount(),
100
);
@@ -67,6 +76,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}).getRowCount(),
100
);
@@ -79,6 +91,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.strictEqual(helper.getRowCount(), 0);
@@ -94,6 +109,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.strictEqual(helper.getRowCount(), 5);
@@ -109,6 +127,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
new LeftPaneSearchHelper({
conversationResults: {
@@ -119,6 +140,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
new LeftPaneSearchHelper({
conversationResults: { isLoading: true },
@@ -126,6 +150,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
];
@@ -159,6 +186,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: messages },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.deepEqual(helper.getRow(0), {
@@ -208,6 +238,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: messages },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.deepEqual(helper.getRow(0), {
@@ -248,6 +281,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: messages },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.deepEqual(helper.getRow(0), {
@@ -290,6 +326,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.deepEqual(helper.getRow(0), {
@@ -324,6 +363,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
new LeftPaneSearchHelper({
conversationResults: {
@@ -334,6 +376,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
new LeftPaneSearchHelper({
conversationResults: { isLoading: true },
@@ -341,6 +386,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
}),
];
@@ -362,6 +410,9 @@ describe('LeftPaneSearchHelper', () => {
},
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isTrue(helper.isScrollable());
});
@@ -381,6 +432,9 @@ describe('LeftPaneSearchHelper', () => {
},
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isFalse(
@@ -396,6 +450,9 @@ describe('LeftPaneSearchHelper', () => {
},
searchTerm: 'bar',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
})
);
});
@@ -407,6 +464,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isFalse(
@@ -419,6 +479,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'bar',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
})
);
});
@@ -430,6 +493,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isTrue(
@@ -442,6 +508,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [fakeMessage()] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
})
);
});
@@ -456,6 +525,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: false, results: [] },
searchTerm: 'foo',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
});
assert.isTrue(
@@ -468,6 +540,9 @@ describe('LeftPaneSearchHelper', () => {
messageResults: { isLoading: true },
searchTerm: 'bar',
primarySendsSms: false,
+ searchConversation: undefined,
+ searchDisabled: false,
+ startSearchCounter: 0,
})
);
});
diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json
index c1a1f5cf764a..4cb8c232ca58 100644
--- a/ts/util/lint/exceptions.json
+++ b/ts/util/lint/exceptions.json
@@ -7488,20 +7488,11 @@
"updated": "2021-10-11T21:21:08.188Z"
},
{
- "rule": "React-createRef",
- "path": "ts/components/MainHeader.js",
- "line": " this.inputRef = react_1.default.createRef();",
+ "rule": "React-useRef",
+ "path": "ts/components/LeftPaneMainSearchInput.tsx",
+ "line": " const inputRef = useRef(null);",
"reasonCategory": "usageTrusted",
- "updated": "2020-02-14T20:02:37.507Z",
- "reasonDetail": "Used only to set focus"
- },
- {
- "rule": "React-createRef",
- "path": "ts/components/MainHeader.tsx",
- "line": " this.inputRef = React.createRef();",
- "reasonCategory": "usageTrusted",
- "updated": "2020-02-14T20:02:37.507Z",
- "reasonDetail": "Used only to set focus"
+ "updated": "2022-01-26T23:11:05.369Z"
},
{
"rule": "React-useRef",
@@ -8411,4 +8402,4 @@
"reasonCategory": "usageTrusted",
"updated": "2021-09-17T21:02:59.414Z"
}
-]
\ No newline at end of file
+]