From 8d9182eb440fed5f1b68736c00d5faff5baf775f Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Mon, 21 Nov 2022 12:21:02 -0500 Subject: [PATCH] Add max character count to Chat composer --- app/soapbox/components/ui/hstack/hstack.tsx | 1 + .../chats/components/chat-composer.tsx | 28 +++++++++++++------ .../normalizers/__tests__/instance.test.ts | 3 ++ app/soapbox/normalizers/instance.ts | 3 ++ .../reducers/__tests__/instance.test.ts | 3 ++ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/soapbox/components/ui/hstack/hstack.tsx b/app/soapbox/components/ui/hstack/hstack.tsx index 996ccd64d..eee5b3706 100644 --- a/app/soapbox/components/ui/hstack/hstack.tsx +++ b/app/soapbox/components/ui/hstack/hstack.tsx @@ -14,6 +14,7 @@ const alignItemsOptions = { bottom: 'items-end', center: 'items-center', start: 'items-start', + stretch: 'items-stretch', }; const spaces = { diff --git a/app/soapbox/features/chats/components/chat-composer.tsx b/app/soapbox/features/chats/components/chat-composer.tsx index d5510f9fd..e39d48e2c 100644 --- a/app/soapbox/features/chats/components/chat-composer.tsx +++ b/app/soapbox/features/chats/components/chat-composer.tsx @@ -40,8 +40,12 @@ const ChatComposer = React.forwardRef const isBlocked = useAppSelector((state) => state.getIn(['relationships', chat?.account?.id, 'blocked_by'])); const isBlocking = useAppSelector((state) => state.getIn(['relationships', chat?.account?.id, 'blocking'])); + const maxCharacterCount = useAppSelector((state) => state.instance.getIn(['configuration', 'chats', 'max_characters']) as number); - const isSubmitDisabled = disabled || value.length === 0; + const isOverCharacterLimit = maxCharacterCount && value?.length > maxCharacterCount; + const isSubmitDisabled = disabled || isOverCharacterLimit || value.length === 0; + + const overLimitText = maxCharacterCount ? maxCharacterCount - value?.length : ''; const handleUnblockUser = () => { dispatch(openModal('CONFIRM', { @@ -75,7 +79,7 @@ const ChatComposer = React.forwardRef return (
- +