signal-desktop/ts/state/smart/CompositionTextArea.tsx

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-10-04 23:17:15 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { useSelector } from 'react-redux';
import type { CompositionTextAreaProps } from '../../components/CompositionTextArea';
import { CompositionTextArea } from '../../components/CompositionTextArea';
import { getIntl, getPlatform } from '../selectors/user';
2022-10-04 23:17:15 +00:00
import { useActions as useEmojiActions } from '../ducks/emojis';
2023-08-09 00:53:06 +00:00
import { useItemsActions } from '../ducks/items';
2022-10-04 23:17:15 +00:00
import { getPreferredBadgeSelector } from '../selectors/badges';
import { useComposerActions } from '../ducks/composer';
import {
2023-04-18 01:16:41 +00:00
getIsFormattingFlagEnabled,
getIsFormattingSpoilersFlagEnabled,
} from '../selectors/composer';
2023-04-18 01:16:41 +00:00
import { getTextFormattingEnabled } from '../selectors/items';
2022-10-04 23:17:15 +00:00
export type SmartCompositionTextAreaProps = Pick<
CompositionTextAreaProps,
| 'bodyRanges'
2022-10-04 23:17:15 +00:00
| 'draftText'
| 'placeholder'
| 'onChange'
| 'onScroll'
| 'onSubmit'
| 'theme'
| 'maxLength'
| 'whenToShowRemainingCount'
| 'scrollerRef'
>;
2022-11-18 00:45:19 +00:00
export function SmartCompositionTextArea(
2022-10-04 23:17:15 +00:00
props: SmartCompositionTextAreaProps
2022-11-18 00:45:19 +00:00
): JSX.Element {
const i18n = useSelector(getIntl);
const platform = useSelector(getPlatform);
2022-10-04 23:17:15 +00:00
const { onUseEmoji: onPickEmoji } = useEmojiActions();
const { onSetSkinTone } = useItemsActions();
const { onTextTooLong } = useComposerActions();
2022-10-04 23:17:15 +00:00
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const isFormattingEnabled = useSelector(getTextFormattingEnabled);
const isFormattingFlagEnabled = useSelector(getIsFormattingFlagEnabled);
const isFormattingSpoilersFlagEnabled = useSelector(
getIsFormattingSpoilersFlagEnabled
);
2022-10-04 23:17:15 +00:00
return (
<CompositionTextArea
{...props}
getPreferredBadge={getPreferredBadge}
2022-10-04 23:17:15 +00:00
i18n={i18n}
isFormattingEnabled={isFormattingEnabled}
isFormattingFlagEnabled={isFormattingFlagEnabled}
isFormattingSpoilersFlagEnabled={isFormattingSpoilersFlagEnabled}
2022-10-04 23:17:15 +00:00
onPickEmoji={onPickEmoji}
onSetSkinTone={onSetSkinTone}
onTextTooLong={onTextTooLong}
platform={platform}
2022-10-04 23:17:15 +00:00
/>
);
2022-11-18 00:45:19 +00:00
}