From 0b4fc431725ba7b3dab44e8b602ab7560c4b81b1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 20 Jul 2022 15:32:25 -0500 Subject: [PATCH] Chats: break out Pane into a UI component --- .../features/chats/components/chat-panes.tsx | 9 +++--- .../features/chats/components/chat-window.tsx | 9 ++---- .../features/chats/components/ui/index.ts | 2 ++ .../features/chats/components/ui/pane.tsx | 32 +++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 app/soapbox/features/chats/components/ui/index.ts create mode 100644 app/soapbox/features/chats/components/ui/pane.tsx diff --git a/app/soapbox/features/chats/components/chat-panes.tsx b/app/soapbox/features/chats/components/chat-panes.tsx index 6ed873139..7bd8cd9d5 100644 --- a/app/soapbox/features/chats/components/chat-panes.tsx +++ b/app/soapbox/features/chats/components/chat-panes.tsx @@ -15,6 +15,7 @@ import { Chat } from 'soapbox/types/entities'; import ChatList from './chat-list'; import ChatWindow from './chat-window'; +import { Pane, WindowState } from './ui'; const messages = defineMessages({ searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Start a chat with…' }, @@ -43,7 +44,7 @@ const ChatPanes = () => { const history = useHistory(); const panes = useAppSelector((state) => normalizeChatPanes(state)); - const mainWindowState = useSettings().getIn(['chats', 'mainWindow']); + const mainWindowState = useSettings().getIn(['chats', 'mainWindow']) as WindowState; const unreadCount = useAppSelector((state) => getChatsUnreadCount(state)); const handleClickChat = ((chat: Chat) => { @@ -61,7 +62,7 @@ const ChatPanes = () => { const open = mainWindowState === 'open'; const mainWindowPane = ( -
+
{unreadCount > 0 && (
@@ -87,7 +88,7 @@ const ChatPanes = () => { )}
-
+
); return ( @@ -95,7 +96,7 @@ const ChatPanes = () => { {mainWindowPane} {panes.map((pane, i) => ( = ({ idx, chatId, windowState }) => { if (!chat) return null; const account = chat.account as unknown as AccountEntity; - - const right = (285 * (idx + 1)) + 20; const unreadCount = chat.unread; const unreadIcon = ( @@ -91,7 +88,7 @@ const ChatWindow: React.FC = ({ idx, chatId, windowState }) => { ); return ( -
+ {unreadCount > 0 ? unreadIcon : avatar }
-
+ ); }; diff --git a/app/soapbox/features/chats/components/ui/index.ts b/app/soapbox/features/chats/components/ui/index.ts new file mode 100644 index 000000000..e028d7509 --- /dev/null +++ b/app/soapbox/features/chats/components/ui/index.ts @@ -0,0 +1,2 @@ +export { Pane } from './pane'; +export type { WindowState } from './pane'; diff --git a/app/soapbox/features/chats/components/ui/pane.tsx b/app/soapbox/features/chats/components/ui/pane.tsx new file mode 100644 index 000000000..b04ff3d29 --- /dev/null +++ b/app/soapbox/features/chats/components/ui/pane.tsx @@ -0,0 +1,32 @@ +import classNames from 'classnames'; +import React from 'react'; + +/** Chat pane state. */ +export type WindowState = 'open' | 'minimized'; + +interface IPane { + /** Whether the pane is open or minimized. */ + windowState: WindowState, + /** Positions the pane on the screen, with 0 at the right. */ + index: number, + /** Children to display in the pane. */ + children: React.ReactNode, + /** Whether this is the main chat pane. */ + main?: boolean, +} + +/** Chat pane UI component for desktop. */ +const Pane: React.FC = ({ windowState, index, children, main = false }) => { + const right = (285 * index) + 20; + + return ( +
+ {children} +
+ ); +}; + +export { Pane };