From 82250c23dc7854cbf5b1c21f68288192c7653bf6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 17 Oct 2022 10:13:54 -0500 Subject: [PATCH 1/2] Chats: search accounts only among people who follow you (TruthSocial) --- app/soapbox/components/account_search.tsx | 3 ++- app/soapbox/components/autosuggest_account_input.tsx | 5 ++++- .../chats/components/chat-page/components/chat-page-new.tsx | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/soapbox/components/account_search.tsx b/app/soapbox/components/account_search.tsx index cdc526b9b..dad699f0d 100644 --- a/app/soapbox/components/account_search.tsx +++ b/app/soapbox/components/account_search.tsx @@ -3,7 +3,6 @@ import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input'; -import Icon from 'soapbox/components/icon'; import SvgIcon from './ui/icon/svg-icon'; import { InputThemes } from './ui/input/input'; @@ -25,6 +24,8 @@ interface IAccountSearch { hidePortal?: boolean, theme?: InputThemes, showButtons?: boolean, + /** Search only among people who follow you (TruthSocial). */ + followers?: boolean, } /** Input to search for accounts. */ diff --git a/app/soapbox/components/autosuggest_account_input.tsx b/app/soapbox/components/autosuggest_account_input.tsx index f7dc890cd..a69b449c7 100644 --- a/app/soapbox/components/autosuggest_account_input.tsx +++ b/app/soapbox/components/autosuggest_account_input.tsx @@ -22,6 +22,8 @@ interface IAutosuggestAccountInput { menu?: Menu, onKeyDown?: React.KeyboardEventHandler, theme?: InputThemes, + /** Search only among people who follow you (TruthSocial). */ + followers?: boolean, } const AutosuggestAccountInput: React.FC = ({ @@ -29,6 +31,7 @@ const AutosuggestAccountInput: React.FC = ({ onSelected, value = '', limit = 4, + followers = false, ...rest }) => { const dispatch = useAppDispatch(); @@ -45,7 +48,7 @@ const AutosuggestAccountInput: React.FC = ({ }; const handleAccountSearch = useCallback(throttle(q => { - const params = { q, limit, resolve: false }; + const params = { q, limit, followers, resolve: false }; dispatch(accountSearch(params, controller.current.signal)) .then((accounts: { id: string }[]) => { diff --git a/app/soapbox/features/chats/components/chat-page/components/chat-page-new.tsx b/app/soapbox/features/chats/components/chat-page/components/chat-page-new.tsx index 3251dea96..62dda22dd 100644 --- a/app/soapbox/features/chats/components/chat-page/components/chat-page-new.tsx +++ b/app/soapbox/features/chats/components/chat-page/components/chat-page-new.tsx @@ -39,6 +39,7 @@ const ChatPageNew: React.FC = () => { showButtons={false} autoFocus className='mb-0.5' + followers /> From ca2aad2de022299cfbef656924d958b4b551f7ad Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 17 Oct 2022 10:50:33 -0500 Subject: [PATCH 2/2] Chats: focus textarea when navigating between chats (janky) --- .../features/chats/components/chat-composer.tsx | 2 +- .../components/chat-page/components/chat-page-main.tsx | 10 ++++++++-- .../chats/components/chat-widget/chat-window.tsx | 4 ++-- app/soapbox/features/chats/components/chat.tsx | 10 ++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-composer.tsx b/app/soapbox/features/chats/components/chat-composer.tsx index 5784396b6..2ad75e51a 100644 --- a/app/soapbox/features/chats/components/chat-composer.tsx +++ b/app/soapbox/features/chats/components/chat-composer.tsx @@ -17,7 +17,7 @@ interface IChatComposer extends Pick(({ +const ChatComposer = React.forwardRef(({ onKeyDown, onChange, value, diff --git a/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx b/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx index a2b32723c..eef4725c3 100644 --- a/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx +++ b/app/soapbox/features/chats/components/chat-page/components/chat-page-main.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { blockAccount } from 'soapbox/actions/accounts'; @@ -32,6 +32,8 @@ const ChatPageMain = () => { const intl = useIntl(); const account = useOwnAccount(); + const inputRef = useRef(null); + const { chat, setChat } = useChatContext(); const { isSilenced, handleSilence, fetchChatSilence } = useChatSilence(chat); const { deleteChat } = useChatActions(chat?.id as string); @@ -162,7 +164,11 @@ const ChatPageMain = () => {
- +
); diff --git a/app/soapbox/features/chats/components/chat-widget/chat-window.tsx b/app/soapbox/features/chats/components/chat-widget/chat-window.tsx index f3bc84576..3510011d4 100644 --- a/app/soapbox/features/chats/components/chat-widget/chat-window.tsx +++ b/app/soapbox/features/chats/components/chat-widget/chat-window.tsx @@ -26,7 +26,7 @@ const LinkWrapper = ({ enabled, to, children }: { enabled: boolean, to: string, const ChatWindow = () => { const { chat, setChat, isOpen, isEditing, needsAcceptance, setEditing, setSearching, toggleChatPane } = useChatContext(); - const inputRef = useRef(); + const inputRef = useRef(null); const closeChat = () => setChat(null); @@ -93,7 +93,7 @@ const ChatWindow = () => { /> - + ); diff --git a/app/soapbox/features/chats/components/chat.tsx b/app/soapbox/features/chats/components/chat.tsx index 686c840fd..6933b9828 100644 --- a/app/soapbox/features/chats/components/chat.tsx +++ b/app/soapbox/features/chats/components/chat.tsx @@ -1,6 +1,6 @@ import { useMutation } from '@tanstack/react-query'; import classNames from 'clsx'; -import React, { MutableRefObject, useState } from 'react'; +import React, { MutableRefObject, useEffect, useState } from 'react'; import { useIntl } from 'react-intl'; import { uploadMedia } from 'soapbox/actions/media'; @@ -20,7 +20,7 @@ const fileKeyGen = (): number => Math.floor((Math.random() * 0x10000)); interface ChatInterface { chat: IChat, autosize?: boolean, - inputRef?: MutableRefObject, + inputRef?: MutableRefObject, className?: string, } @@ -203,6 +203,12 @@ const Chat: React.FC = ({ chat, autosize, inputRef, className }) // ); }; + useEffect(() => { + if (inputRef?.current) { + inputRef.current.focus(); + } + }, [chat.id, inputRef?.current]); + return (