ChatPageNew: display disabled ChatComposer and "To:" label

This commit is contained in:
Alex Gleason 2022-10-04 19:10:58 -04:00
parent 4bab81bd7c
commit 19382c3ab9
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 54 additions and 24 deletions

View file

@ -6,6 +6,7 @@ import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_inpu
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import SvgIcon from './ui/icon/svg-icon'; import SvgIcon from './ui/icon/svg-icon';
import { InputThemes } from './ui/input/input';
const messages = defineMessages({ const messages = defineMessages({
placeholder: { id: 'account_search.placeholder', defaultMessage: 'Search for an account' }, placeholder: { id: 'account_search.placeholder', defaultMessage: 'Search for an account' },
@ -22,10 +23,12 @@ interface IAccountSearch {
className?: string, className?: string,
autoFocus?: boolean, autoFocus?: boolean,
hidePortal?: boolean, hidePortal?: boolean,
theme?: InputThemes,
showButtons?: boolean,
} }
/** Input to search for accounts. */ /** Input to search for accounts. */
const AccountSearch: React.FC<IAccountSearch> = ({ onSelected, className, ...rest }) => { const AccountSearch: React.FC<IAccountSearch> = ({ onSelected, className, showButtons = true, ...rest }) => {
const intl = useIntl(); const intl = useIntl();
const [value, setValue] = useState(''); const [value, setValue] = useState('');
@ -76,23 +79,25 @@ const AccountSearch: React.FC<IAccountSearch> = ({ onSelected, className, ...res
{...rest} {...rest}
/> />
<div {showButtons && (
role='button' <div
tabIndex={0} role='button'
className='absolute inset-y-0 right-0 px-3 flex items-center cursor-pointer' tabIndex={0}
onClick={handleClear} className='absolute inset-y-0 right-0 px-3 flex items-center cursor-pointer'
> onClick={handleClear}
<SvgIcon >
src={require('@tabler/icons/search.svg')} <SvgIcon
className={classNames('h-4 w-4 text-gray-400', { hidden: !isEmpty() })} src={require('@tabler/icons/search.svg')}
/> className={classNames('h-4 w-4 text-gray-400', { hidden: !isEmpty() })}
/>
<SvgIcon <SvgIcon
src={require('@tabler/icons/x.svg')} src={require('@tabler/icons/x.svg')}
className={classNames('h-4 w-4 text-gray-400', { hidden: isEmpty() })} className={classNames('h-4 w-4 text-gray-400', { hidden: isEmpty() })}
aria-label={intl.formatMessage(messages.placeholder)} aria-label={intl.formatMessage(messages.placeholder)}
/> />
</div> </div>
)}
</div> </div>
</div> </div>
); );

View file

@ -10,7 +10,7 @@ const messages = defineMessages({
retry: { id: 'chat.retry', defaultMessage: 'Retry?' }, retry: { id: 'chat.retry', defaultMessage: 'Retry?' },
}); });
interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onKeyDown' | 'onChange'> { interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onKeyDown' | 'onChange' | 'disabled'> {
value: string, value: string,
onSubmit: () => void, onSubmit: () => void,
hasErrorSubmittingMessage?: boolean, hasErrorSubmittingMessage?: boolean,
@ -23,10 +23,11 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement, IChatComposer>(({
value, value,
onSubmit, onSubmit,
hasErrorSubmittingMessage = false, hasErrorSubmittingMessage = false,
disabled = false,
}, ref) => { }, ref) => {
const intl = useIntl(); const intl = useIntl();
const isSubmitDisabled = value.length === 0; const isSubmitDisabled = disabled || value.length === 0;
return ( return (
<div className='mt-auto pt-4 px-4 shadow-3xl'> <div className='mt-auto pt-4 px-4 shadow-3xl'>
@ -42,6 +43,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement, IChatComposer>(({
isResizeable={false} isResizeable={false}
autoGrow autoGrow
maxRows={5} maxRows={5}
disabled={disabled}
/> />
</Stack> </Stack>

View file

@ -1,10 +1,13 @@
import React from 'react'; import React from 'react';
import { FormattedMessage } from 'react-intl';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import AccountSearch from 'soapbox/components/account_search'; import AccountSearch from 'soapbox/components/account_search';
import { CardTitle, Stack } from 'soapbox/components/ui'; import { CardTitle, HStack, Stack, Text } from 'soapbox/components/ui';
import { useChats } from 'soapbox/queries/chats'; import { useChats } from 'soapbox/queries/chats';
import ChatComposer from '../../chat-composer';
interface IChatPageNew { interface IChatPageNew {
} }
@ -19,11 +22,31 @@ const ChatPageNew: React.FC<IChatPageNew> = () => {
}; };
return ( return (
<Stack className='h-full p-6 space-y-8'> <Stack className='h-full'>
<CardTitle title='New Message' /> <Stack className='flex-grow p-6 space-y-8'>
<CardTitle title='New Message' />
<AccountSearch <HStack space={2} alignItems='center'>
onSelected={handleAccountSelected} <Text>
<FormattedMessage
id='chats.new.to'
defaultMessage='To:'
/>
</Text>
<AccountSearch
onSelected={handleAccountSelected}
theme='transparent'
showButtons={false}
autoFocus
/>
</HStack>
</Stack>
<ChatComposer
value=''
onSubmit={() => {}}
disabled
/> />
</Stack> </Stack>
); );