Finish in-redux conversation lookups, getPropsForSearchResult moved

This commit is contained in:
Scott Nonnenberg 2021-01-06 07:41:43 -08:00
parent 7fe40dbf83
commit cbc6c29479
18 changed files with 901 additions and 146 deletions

View file

@ -1,13 +1,17 @@
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { fromPairs, map } from 'lodash';
export function makeLookup<T>(
items: Array<T>,
key: keyof T
): { [key: string]: T } {
const pairs = map(items, item => [item[key], item]);
return fromPairs(pairs);
): Record<string, T> {
return (items || []).reduce((lookup, item) => {
if (item && item[key]) {
// The force cast is necessary if we want the keyof T above, and the flexibility
// to pass anything in. And of course we're modifying a parameter!
// eslint-disable-next-line no-param-reassign
lookup[String(item[key])] = item;
}
return lookup;
}, {} as Record<string, T>);
}