From 6459096b58664b533c03bb27a4d127ea57042fd8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 17 Jun 2022 14:39:53 -0500 Subject: [PATCH] ChatWindow: convert to TSX --- app/soapbox/components/hover_ref_wrapper.tsx | 2 +- .../features/chats/components/chat_window.js | Bin 3624 -> 0 bytes .../features/chats/components/chat_window.tsx | 113 ++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) delete mode 100644 app/soapbox/features/chats/components/chat_window.js create mode 100644 app/soapbox/features/chats/components/chat_window.tsx diff --git a/app/soapbox/components/hover_ref_wrapper.tsx b/app/soapbox/components/hover_ref_wrapper.tsx index bf4e253f21..2090543cca 100644 --- a/app/soapbox/components/hover_ref_wrapper.tsx +++ b/app/soapbox/components/hover_ref_wrapper.tsx @@ -15,7 +15,7 @@ const showProfileHoverCard = debounce((dispatch, ref, accountId) => { interface IHoverRefWrapper { accountId: string, - inline: boolean, + inline?: boolean, className?: string, } diff --git a/app/soapbox/features/chats/components/chat_window.js b/app/soapbox/features/chats/components/chat_window.js deleted file mode 100644 index e525e3432396ba4ab71f77a932bb200615058d24..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3624 zcmbtXZExE)5dNNDaRq`(USqipFraXvENQlG9=2gfGW5eRB#K1aTqRPaD94%L|GqoE zNR*Ro1LhBcL_YU^_mJjQEtQ5}m8@?bYu3P0$qJ$xzo(iOqLTw|F;^_hwcA(pK5Q+j zs@2(j$@cXa+?4z6De2u)JIJ<*T}reim>Ag!Vd{!4KdG#)**^%b33#j6^7g?(2OSH{ z!-rODDPFeA5p#QQK!achm$DU@h(0^dc--<(pvpe8@0q3yJrQbHiPexQNJj@NrZ4iK zM&3fJd5P)BbMjy$QShcNv&WBL#1jivsL`2b=#;M;IrBkoUGRx1$t~81AQ*O|fxP}X ztFKA$Mp9=tkU~6x^bAbZ4GLW~ais?DqKqe~1^dG3d7{HOa|9hwBPJIW7v+=_NGHI+h{O~dc-;t zg=M`I=n+!Lx-f*nqlZC{Z`gS{KWxBt`NK-&Li zQ6lvTnisJ$QHH^oP#UI9MPr<93!Vc@kl%64l1)~&49DHf#}LOt)U8HBrzlt%q{nFF zwEJDjD%@tJ&4k%l%DioiED?^MxM7vl1V!&eZa7w`t&As@ei zy>@+1tzD#(pLDzYoECh8Hy9+;U$Tm&QKhEGuq@ejD)1&2ojDl5sXzD4>6>J)g|(uFeDldQ7K>UC>$RA|6POC7SQR zlzR?$hn;!b)!RGR1tIL0i1gjwuCee;1qA{KYXWER77zEJ=5ug0*!4BVXzl$j>;S7? zb6v6sq_`}3{yFW;aPHHtVauUPVVQ`p&pT}L3#>`(avx67WaP%o`r*?~($9x&&W2Ic zhzxGCjmpzb*>gLN&duKvHKVI+Z+eiuNoSRm?AjDep&?TD~9J(T6{$ Hb_ah0XS9b7 diff --git a/app/soapbox/features/chats/components/chat_window.tsx b/app/soapbox/features/chats/components/chat_window.tsx new file mode 100644 index 0000000000..aecdca1801 --- /dev/null +++ b/app/soapbox/features/chats/components/chat_window.tsx @@ -0,0 +1,113 @@ +import React, { useEffect, useRef } from 'react'; +import { Link } from 'react-router-dom'; + +import { + closeChat, + toggleChat, +} from 'soapbox/actions/chats'; +import Avatar from 'soapbox/components/avatar'; +import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper'; +import IconButton from 'soapbox/components/icon_button'; +import { Counter } from 'soapbox/components/ui'; +import { useAppSelector, useAppDispatch } from 'soapbox/hooks'; +import { makeGetChat } from 'soapbox/selectors'; +import { getAcct } from 'soapbox/utils/accounts'; +import { displayFqn as getDisplayFqn } from 'soapbox/utils/state'; + +import ChatBox from './chat_box'; + +import type { Account as AccountEntity } from 'soapbox/types/entities'; + +type WindowState = 'open' | 'minimized'; + +const getChat = makeGetChat(); + +interface IChatWindow { + /** Position of the chat window on the screen, where 0 is rightmost. */ + idx: number, + /** ID of the chat entity. */ + chatId: string, + /** Whether the window is open or minimized. */ + windowState: WindowState, +} + +/** Floating desktop chat window. */ +const ChatWindow: React.FC = ({ idx, chatId, windowState }) => { + const dispatch = useAppDispatch(); + + const displayFqn = useAppSelector(getDisplayFqn); + + const chat = useAppSelector(state => { + const chat = state.chats.items.get(chatId); + return chat ? getChat(state, chat.toJS() as any) : undefined; + }); + + const inputElem = useRef(null); + + const handleChatClose = (chatId: string) => { + return () => { + dispatch(closeChat(chatId)); + }; + }; + + const handleChatToggle = (chatId: string) => { + return () => { + dispatch(toggleChat(chatId)); + }; + }; + + const handleInputRef = (el: HTMLTextAreaElement) => { + inputElem.current = el; + focusInput(); + }; + + const focusInput = () => { + inputElem.current?.focus(); + }; + + useEffect(() => { + focusInput(); + }, [windowState === 'open']); + + if (!chat) return null; + const account = chat.account as unknown as AccountEntity; + + const right = (285 * (idx + 1)) + 20; + const unreadCount = chat.unread; + + const unreadIcon = ( +
+ +
+ ); + + const avatar = ( + + + + + + ); + + return ( +
+
+ {unreadCount > 0 ? unreadIcon : avatar } + +
+ +
+
+
+ +
+
+ ); +}; + +export default ChatWindow;