From 1a4a6382d3d094fe437a44083c934bd03fb0de57 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 22 Sep 2022 14:34:07 -0500 Subject: [PATCH 01/11] Make account.chats_onboarded true by default for backwards-compatibility --- app/soapbox/normalizers/account.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index 64c5365db..63ad77c48 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -27,7 +27,7 @@ export const AccountRecord = ImmutableRecord({ avatar_static: '', birthday: '', bot: false, - chats_onboarded: false, + chats_onboarded: true, created_at: '', discoverable: false, display_name: '', From 2e728d99f9460f1e52461a57f181197464f7fed3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 22 Sep 2022 14:36:46 -0500 Subject: [PATCH 02/11] ChatWidget: remove 'direct' streaming (it uses the 'user' stream) --- .../features/chats/components/chat-widget.tsx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-widget.tsx b/app/soapbox/features/chats/components/chat-widget.tsx index c403274ed..bd72f1e02 100644 --- a/app/soapbox/features/chats/components/chat-widget.tsx +++ b/app/soapbox/features/chats/components/chat-widget.tsx @@ -1,26 +1,16 @@ -import React, { useEffect } from 'react'; +import React from 'react'; -import { connectDirectStream } from 'soapbox/actions/streaming'; import { ChatProvider } from 'soapbox/contexts/chat-context'; -import { useAppDispatch, useOwnAccount } from 'soapbox/hooks'; +import { useOwnAccount } from 'soapbox/hooks'; import ChatPane from './chat-pane/chat-pane'; const ChatWidget = () => { const account = useOwnAccount(); - const dispatch = useAppDispatch(); const path = location.pathname; const shouldHideWidget = Boolean(path.match(/^\/chats/)); - useEffect(() => { - const disconnect = dispatch(connectDirectStream()); - - return (() => { - disconnect(); - }); - }, []); - if (!account?.chats_onboarded || shouldHideWidget) { return null; } From 46d309ae4580e9a5d1a866a1a2f2f86560979073 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 22 Sep 2022 14:58:31 -0500 Subject: [PATCH 03/11] ChatListItem: restrict height of last_message content --- app/soapbox/features/chats/components/chat-list-item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/features/chats/components/chat-list-item.tsx b/app/soapbox/features/chats/components/chat-list-item.tsx index e600f9859..5b9571870 100644 --- a/app/soapbox/features/chats/components/chat-list-item.tsx +++ b/app/soapbox/features/chats/components/chat-list-item.tsx @@ -38,7 +38,7 @@ const ChatListItem: React.FC = ({ chat, chatSilence, onC weight='medium' theme='muted' truncate - className='w-full truncate-child pointer-events-none' + className='w-full h-5 truncate-child pointer-events-none' data-testid='chat-last-message' dangerouslySetInnerHTML={{ __html: chat.last_message?.content }} /> From fa919c217ba83d48e49d099a5ad697448b63b6e3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 22 Sep 2022 15:24:11 -0500 Subject: [PATCH 04/11] Create ChatSearchInput component --- .../chats/components/chat-pane/chat-pane.tsx | 26 ++-------- .../chats/components/chat-search-input.tsx | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 app/soapbox/features/chats/components/chat-search-input.tsx 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 ( + +