pl-fe: we don't really need this component
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -1,92 +0,0 @@
|
||||
import clsx from 'clsx';
|
||||
import React, { useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import AutosuggestAccountInput from 'pl-fe/components/autosuggest-account-input';
|
||||
|
||||
import SvgIcon from './ui/svg-icon';
|
||||
|
||||
const messages = defineMessages({
|
||||
placeholder: { id: 'account_search.placeholder', defaultMessage: 'Search for an account' },
|
||||
});
|
||||
|
||||
interface IAccountSearch {
|
||||
/** Callback when a searched account is chosen. */
|
||||
onSelected: (accountId: string) => void;
|
||||
/** Override the default placeholder of the input. */
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
/** Input to search for accounts. */
|
||||
const AccountSearch: React.FC<IAccountSearch> = ({ onSelected, ...rest }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const isEmpty = (): boolean => !(value.length > 0);
|
||||
|
||||
const clearState = () => {
|
||||
setValue('');
|
||||
};
|
||||
|
||||
const handleChange: React.ChangeEventHandler<HTMLInputElement> = ({ target }) => {
|
||||
setValue(target.value);
|
||||
};
|
||||
|
||||
const handleSelected = (accountId: string) => {
|
||||
clearState();
|
||||
onSelected(accountId);
|
||||
};
|
||||
|
||||
const handleClear: React.MouseEventHandler = e => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!isEmpty()) {
|
||||
setValue('');
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown: React.KeyboardEventHandler = e => {
|
||||
if (e.key === 'Escape') {
|
||||
document.querySelector('.ui')?.parentElement?.focus();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='w-full'>
|
||||
<label className='sr-only'>{intl.formatMessage(messages.placeholder)}</label>
|
||||
|
||||
<div className='relative'>
|
||||
<AutosuggestAccountInput
|
||||
className='rounded-full'
|
||||
placeholder={intl.formatMessage(messages.placeholder)}
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
onSelected={handleSelected}
|
||||
onKeyDown={handleKeyDown}
|
||||
{...rest}
|
||||
/>
|
||||
|
||||
<div
|
||||
role='button'
|
||||
tabIndex={0}
|
||||
className='absolute inset-y-0 flex cursor-pointer items-center px-3 ltr:right-0 rtl:left-0'
|
||||
onClick={handleClear}
|
||||
>
|
||||
<SvgIcon
|
||||
src={require('@phosphor-icons/core/regular/magnifying-glass.svg')}
|
||||
className={clsx('size-4 text-gray-400', { hidden: !isEmpty() })}
|
||||
/>
|
||||
|
||||
<SvgIcon
|
||||
src={require('@phosphor-icons/core/regular/x.svg')}
|
||||
className={clsx('size-4 text-gray-400', { hidden: isEmpty() })}
|
||||
aria-label={intl.formatMessage(messages.placeholder)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { AccountSearch as default };
|
||||
@ -99,7 +99,6 @@
|
||||
"account_moderation_modal.roles.user": "User",
|
||||
"account_note.header": "Note",
|
||||
"account_note.placeholder": "Click to add a note",
|
||||
"account_search.placeholder": "Search for an account",
|
||||
"admin.announcements.action": "Create announcement",
|
||||
"admin.announcements.all_day": "All day",
|
||||
"admin.announcements.delete": "Delete",
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { directComposeById } from 'pl-fe/actions/compose';
|
||||
import { mountConversations, unmountConversations, expandConversations } from 'pl-fe/actions/conversations';
|
||||
import { useDirectStream } from 'pl-fe/api/hooks/streaming/use-direct-stream';
|
||||
import AccountSearch from 'pl-fe/components/account-search';
|
||||
import Column from 'pl-fe/components/ui/column';
|
||||
import ConversationsList from 'pl-fe/features/conversations/components/conversations-list';
|
||||
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
|
||||
@ -29,17 +27,8 @@ const ConversationsTimeline = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleSuggestion = (accountId: string) => {
|
||||
dispatch(directComposeById(accountId));
|
||||
};
|
||||
|
||||
return (
|
||||
<Column label={intl.formatMessage(messages.title)}>
|
||||
<AccountSearch
|
||||
placeholder={intl.formatMessage(messages.searchPlaceholder)}
|
||||
onSelected={handleSuggestion}
|
||||
/>
|
||||
|
||||
<ConversationsList />
|
||||
</Column>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user