Move left pane entirely to React
This commit is contained in:
parent
bf904ddd12
commit
b3ac1373fa
142 changed files with 5016 additions and 3428 deletions
93
ts/state/selectors/search.ts
Normal file
93
ts/state/selectors/search.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
import { compact } from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
import { StateType } from '../reducer';
|
||||
import { SearchStateType } from '../ducks/search';
|
||||
|
||||
import {
|
||||
getConversationLookup,
|
||||
getSelectedConversation,
|
||||
} from './conversations';
|
||||
import { ConversationLookupType } from '../ducks/conversations';
|
||||
|
||||
export const getSearch = (state: StateType): SearchStateType => state.search;
|
||||
|
||||
export const getQuery = createSelector(
|
||||
getSearch,
|
||||
(state: SearchStateType): string => state.query
|
||||
);
|
||||
|
||||
export const getSelectedMessage = createSelector(
|
||||
getSearch,
|
||||
(state: SearchStateType): string | undefined => state.selectedMessage
|
||||
);
|
||||
|
||||
export const isSearching = createSelector(
|
||||
getSearch,
|
||||
(state: SearchStateType) => {
|
||||
const { query } = state;
|
||||
|
||||
return query && query.trim().length > 1;
|
||||
}
|
||||
);
|
||||
|
||||
export const getSearchResults = createSelector(
|
||||
[
|
||||
getSearch,
|
||||
getConversationLookup,
|
||||
getSelectedConversation,
|
||||
getSelectedMessage,
|
||||
],
|
||||
(
|
||||
state: SearchStateType,
|
||||
lookup: ConversationLookupType,
|
||||
selectedConversation?: string,
|
||||
selectedMessage?: string
|
||||
) => {
|
||||
return {
|
||||
contacts: compact(
|
||||
state.contacts.map(id => {
|
||||
const value = lookup[id];
|
||||
|
||||
if (value && id === selectedConversation) {
|
||||
return {
|
||||
...value,
|
||||
isSelected: true,
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
),
|
||||
conversations: compact(
|
||||
state.conversations.map(id => {
|
||||
const value = lookup[id];
|
||||
|
||||
if (value && id === selectedConversation) {
|
||||
return {
|
||||
...value,
|
||||
isSelected: true,
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
),
|
||||
hideMessagesHeader: false,
|
||||
messages: state.messages.map(message => {
|
||||
if (message.id === selectedMessage) {
|
||||
return {
|
||||
...message,
|
||||
isSelected: true,
|
||||
};
|
||||
}
|
||||
|
||||
return message;
|
||||
}),
|
||||
searchTerm: state.query,
|
||||
showStartNewConversation: Boolean(
|
||||
state.normalizedPhoneNumber && !lookup[state.normalizedPhoneNumber]
|
||||
),
|
||||
};
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue