Move left pane entirely to React
This commit is contained in:
parent
bf904ddd12
commit
b3ac1373fa
142 changed files with 5016 additions and 3428 deletions
24
ts/util/cleanSearchTerm.ts
Normal file
24
ts/util/cleanSearchTerm.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
export function cleanSearchTerm(searchTerm: string) {
|
||||
const lowercase = searchTerm.toLowerCase();
|
||||
const withoutSpecialCharacters = lowercase.replace(
|
||||
/([!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~])/g,
|
||||
' '
|
||||
);
|
||||
const whiteSpaceNormalized = withoutSpecialCharacters.replace(/\s+/g, ' ');
|
||||
const byToken = whiteSpaceNormalized.split(' ');
|
||||
const withoutSpecialTokens = byToken.filter(
|
||||
token =>
|
||||
token &&
|
||||
token !== 'and' &&
|
||||
token !== 'or' &&
|
||||
token !== 'not' &&
|
||||
token !== ')' &&
|
||||
token !== '(' &&
|
||||
token !== '+' &&
|
||||
token !== ',' &&
|
||||
token !== 'near'
|
||||
);
|
||||
const withWildcards = withoutSpecialTokens.map(token => `${token}*`);
|
||||
|
||||
return withWildcards.join(' ').trim();
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import moment from 'moment';
|
||||
import { Localizer } from '../types/Util';
|
||||
import { LocalizerType } from '../types/Util';
|
||||
|
||||
const getExtendedFormats = (i18n: Localizer) => ({
|
||||
const getExtendedFormats = (i18n: LocalizerType) => ({
|
||||
y: 'lll',
|
||||
M: `${i18n('timestampFormat_M') || 'MMM D'} LT`,
|
||||
d: 'ddd LT',
|
||||
});
|
||||
const getShortFormats = (i18n: Localizer) => ({
|
||||
const getShortFormats = (i18n: LocalizerType) => ({
|
||||
y: 'll',
|
||||
M: i18n('timestampFormat_M') || 'MMM D',
|
||||
d: 'ddd',
|
||||
|
@ -28,7 +28,7 @@ function isYear(timestamp: moment.Moment) {
|
|||
|
||||
export function formatRelativeTime(
|
||||
rawTimestamp: number | Date,
|
||||
options: { extended: boolean; i18n: Localizer }
|
||||
options: { extended?: boolean; i18n: LocalizerType }
|
||||
) {
|
||||
const { extended, i18n } = options;
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@ function removeNonInitials(name: string) {
|
|||
return name.replace(BAD_CHARACTERS, '').replace(WHITESPACE, ' ');
|
||||
}
|
||||
|
||||
export function getInitials(name?: string): string | null {
|
||||
export function getInitials(name?: string): string | undefined {
|
||||
if (!name) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const cleaned = removeNonInitials(name);
|
||||
const parts = cleaned.split(' ');
|
||||
const initials = parts.map(part => part.trim()[0]);
|
||||
if (!initials.length) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
return initials.slice(0, 2).join('');
|
||||
|
|
|
@ -3,11 +3,13 @@ import { arrayBufferToObjectURL } from './arrayBufferToObjectURL';
|
|||
import { isFileDangerous } from './isFileDangerous';
|
||||
import { missingCaseError } from './missingCaseError';
|
||||
import { migrateColor } from './migrateColor';
|
||||
import { makeLookup } from './makeLookup';
|
||||
|
||||
export {
|
||||
arrayBufferToObjectURL,
|
||||
GoogleChrome,
|
||||
isFileDangerous,
|
||||
makeLookup,
|
||||
migrateColor,
|
||||
missingCaseError,
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -73,6 +73,10 @@ const excludedFiles = [
|
|||
'^libtextsecure/test/*',
|
||||
'^test/*',
|
||||
|
||||
// Modules we trust
|
||||
'^node_modules/react/*',
|
||||
'^node_modules/react-dom/*',
|
||||
|
||||
// Modules used only in test/development scenarios
|
||||
'^node_modules/@types/*',
|
||||
'^node_modules/ajv/*',
|
||||
|
@ -226,6 +230,7 @@ forEach(allSourceFiles, file => {
|
|||
|
||||
const exception = exceptionsLookup[exceptionKey];
|
||||
if (exception && (!exception.line || exception.line === line)) {
|
||||
// tslint:disable-next-line no-dynamic-delete
|
||||
delete exceptionsLookup[exceptionKey];
|
||||
|
||||
return;
|
||||
|
|
|
@ -130,6 +130,7 @@
|
|||
"expression": "\\bcreateRef\\(",
|
||||
"reason": "Potential XSS",
|
||||
"excludedModules": [
|
||||
"node_modules/react/",
|
||||
"node_modules/react-dom",
|
||||
"node_modules/tslint-microsoft-contrib",
|
||||
"node_modules/react-error-overlay",
|
||||
|
|
|
@ -46,10 +46,10 @@ export const REASONS = [
|
|||
|
||||
export type RuleType = {
|
||||
name: string;
|
||||
expression: string | null;
|
||||
expression?: string;
|
||||
reason: string;
|
||||
regex: RegExp;
|
||||
excludedModules: Array<string> | null;
|
||||
excludedModules?: Array<string>;
|
||||
};
|
||||
|
||||
export type ExceptionType = {
|
||||
|
|
12
ts/util/makeLookup.ts
Normal file
12
ts/util/makeLookup.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { fromPairs, map } from 'lodash';
|
||||
|
||||
export function makeLookup<T>(
|
||||
items: Array<T>,
|
||||
key: string
|
||||
): { [key: string]: T } {
|
||||
// Yep, we can't index into item without knowing what it is. True. But we want to.
|
||||
// @ts-ignore
|
||||
const pairs = map(items, item => [item[key], item]);
|
||||
|
||||
return fromPairs(pairs);
|
||||
}
|
23
ts/util/timer.ts
Normal file
23
ts/util/timer.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { padStart } from 'lodash';
|
||||
|
||||
export function getIncrement(length: number): number {
|
||||
if (length < 0) {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
return Math.ceil(length / 12);
|
||||
}
|
||||
|
||||
export function getTimerBucket(expiration: number, length: number): string {
|
||||
const delta = expiration - Date.now();
|
||||
if (delta < 0) {
|
||||
return '00';
|
||||
}
|
||||
if (delta > length) {
|
||||
return '60';
|
||||
}
|
||||
|
||||
const bucket = Math.round(delta / length * 12);
|
||||
|
||||
return padStart(String(bucket * 5), 2, '0');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue