diff --git a/lib/utils/text-utils.js b/lib/utils/text-utils.js index 176747879..573536fc6 100644 --- a/lib/utils/text-utils.js +++ b/lib/utils/text-utils.js @@ -1,47 +1,47 @@ // @flow function pluralize( nouns: $ReadOnlyArray, maxNumberOfNouns: number = 3, ): string { if (nouns.length === 0) { return ''; } else if (nouns.length === 1) { return nouns[0]; } else if (maxNumberOfNouns === 1) { return `${nouns.length} ${nouns.length > 1 ? 'users' : 'user'}`; } const comma = maxNumberOfNouns > 2 && nouns.length > 2 ? ',' : ''; if (nouns.length <= maxNumberOfNouns) { - const prefix = nouns.slice(0, nouns.length - 1).join(', '); + const prefix = nouns.slice(0, -1).join(', '); return `${prefix}${comma} and ${nouns[nouns.length - 1]}`; } else { const prefix = nouns.slice(0, maxNumberOfNouns - 1).join(', '); return `${prefix}${comma} and ${ nouns.length - maxNumberOfNouns + 1 } others`; } } function trimText(text: string, maxLength: number): string { if (text.length <= maxLength) { return text; } return text.substr(0, maxLength - 3) + '...'; } function pluralizeAndTrim( nouns: $ReadOnlyArray, maxLength: number, ): string { for (let maxNumberOfNouns = 3; maxNumberOfNouns >= 2; --maxNumberOfNouns) { const text = pluralize(nouns, maxNumberOfNouns); if (text.length <= maxLength) { return text; } } return pluralize(nouns, 1); } export { pluralize, trimText, pluralizeAndTrim }; diff --git a/web/modals/modal-provider.react.js b/web/modals/modal-provider.react.js index a86ad9280..2e6cb9429 100644 --- a/web/modals/modal-provider.react.js +++ b/web/modals/modal-provider.react.js @@ -1,65 +1,65 @@ // @flow import invariant from 'invariant'; import * as React from 'react'; import { getUUID } from 'lib/utils/uuid'; type Props = { +children: React.Node, }; type ModalContextType = { +modals: $ReadOnlyArray<[React.Node, string]>, +pushModal: React.Node => void, +popModal: () => void, +clearModals: () => void, }; const ModalContext: React.Context = React.createContext( { modals: [], pushModal: () => {}, popModal: () => {}, clearModals: () => {}, }, ); function ModalProvider(props: Props): React.Node { const { children } = props; const [modals, setModals] = React.useState< $ReadOnlyArray<[React.Node, string]>, >([]); const popModal = React.useCallback( - () => setModals(oldModals => oldModals.slice(0, oldModals.length - 1)), + () => setModals(oldModals => oldModals.slice(0, -1)), [], ); const pushModal = React.useCallback(newModal => { const key = getUUID(); setModals(oldModals => [...oldModals, [newModal, key]]); }, []); const clearModals = React.useCallback(() => setModals([]), []); const value = React.useMemo( () => ({ modals, pushModal, popModal, clearModals, }), [modals, pushModal, popModal, clearModals], ); return ( {children} ); } function useModalContext(): ModalContextType { const context = React.useContext(ModalContext); invariant(context, 'ModalContext not found'); return context; } export { ModalProvider, useModalContext };