diff --git a/app/soapbox/features/chats/components/chat-pane/chat-pane.tsx b/app/soapbox/features/chats/components/chat-pane/chat-pane.tsx index 6efb92f66..02d3a0e2b 100644 --- a/app/soapbox/features/chats/components/chat-pane/chat-pane.tsx +++ b/app/soapbox/features/chats/components/chat-pane/chat-pane.tsx @@ -1,14 +1,14 @@ import sumBy from 'lodash/sumBy'; import React, { useState } from 'react'; -import { defineMessages, useIntl } from 'react-intl'; -import { Icon, Input, Stack } from 'soapbox/components/ui'; +import { Stack } from 'soapbox/components/ui'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useDebounce } from 'soapbox/hooks'; import { IChat, useChats } from 'soapbox/queries/chats'; import ChatList from '../chat-list'; import ChatPaneHeader from '../chat-pane-header'; +import ChatSearchInput from '../chat-search-input'; import ChatSearch from '../chat-search/chat-search'; import EmptyResultsBlankslate from '../chat-search/empty-results-blankslate'; import ChatWindow from '../chat-window'; @@ -16,12 +16,7 @@ import { Pane } from '../ui'; import Blankslate from './blankslate'; -const messages = defineMessages({ - searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Search inbox' }, -}); - const ChatPane = () => { - const intl = useIntl(); const debounce = useDebounce; const [value, setValue] = useState(); @@ -50,23 +45,10 @@ const ChatPane = () => { return (
- setValue(event.target.value)} - isSearch - append={ - - } + onClear={clearValue} />
diff --git a/app/soapbox/features/chats/components/chat-search-input.tsx b/app/soapbox/features/chats/components/chat-search-input.tsx new file mode 100644 index 000000000..0611354ea --- /dev/null +++ b/app/soapbox/features/chats/components/chat-search-input.tsx @@ -0,0 +1,49 @@ +import React from 'react'; +import { defineMessages, useIntl } from 'react-intl'; + +import { Icon, Input } from 'soapbox/components/ui'; +import { useDebounce } from 'soapbox/hooks'; + +const messages = defineMessages({ + searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Search inbox' }, +}); + +interface IChatSearchInput { + /** Search term. */ + value: string, + /** Callback when the search value changes. */ + onChange: React.ChangeEventHandler, + /** Callback when the input is cleared. */ + onClear: React.MouseEventHandler, +} + +/** Search input for filtering chats. */ +const ChatSearchInput: React.FC = ({ value, onChange, onClear }) => { + const intl = useIntl(); + + const debouncedValue = useDebounce(value, 300); + const hasSearchValue = Number(debouncedValue?.length) > 0; + + return ( + +