From d163a4c5fd62bf68bbface9ab3463d942b1e607d Mon Sep 17 00:00:00 2001 From: William Wang Date: Mon, 23 Oct 2023 14:36:29 -0400 Subject: [PATCH] [web] Create new chat button creates chat in GENESIS community only Summary: Reopening after previous commit failed build. Just required a `git pull --rebase`. Changed create chat button when in non-GENESIS community to begin create channel experience. Create `onClickSubChannel` which pushes `ComposeSubchannelModal` when `communityID` does not equal `genesis.id`. Added conditional to change `"Create new chat"` to '"Create new channel"' when in non-GENESIS community. Test Plan: Verified working on local web, `flow` ran successfully Reviewers: ashoat Reviewed By: ashoat Subscribers: tomek Differential Revision: https://phab.comm.dev/D9567 --- web/chat/chat-thread-list.react.js | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/web/chat/chat-thread-list.react.js b/web/chat/chat-thread-list.react.js index 2869db638f..c6733d7c33 100644 --- a/web/chat/chat-thread-list.react.js +++ b/web/chat/chat-thread-list.react.js @@ -6,7 +6,10 @@ import * as React from 'react'; import AutoSizer from 'react-virtualized-auto-sizer'; import { VariableSizeList } from 'react-window'; +import { useModalContext } from 'lib/components/modal-provider.react.js'; +import genesis from 'lib/facts/genesis.js'; import type { ChatThreadItem } from 'lib/selectors/chat-selectors.js'; +import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { emptyItemText } from 'lib/shared/thread-utils.js'; import ChatThreadListItem from './chat-thread-list-item.react.js'; @@ -15,6 +18,7 @@ import css from './chat-thread-list.css'; import { ThreadListContext } from './thread-list-provider.js'; import BackgroundIllustration from '../assets/background-illustration.react.js'; import Button from '../components/button.react.js'; +import ComposeSubchannelModal from '../modals/threads/create/compose-subchannel-modal.react.js'; import { useSelector } from '../redux/redux-utils.js'; import { useOnClickNewThread } from '../selectors/thread-selectors.js'; @@ -68,6 +72,37 @@ function ChatThreadList(): React.Node { const communityID = useSelector(state => state.communityPickerStore.chat); + const communityThreadInfo = useSelector(state => { + if (!communityID) { + return null; + } + return threadInfoSelector(state)[communityID]; + }); + + const { pushModal, popModal } = useModalContext(); + + const onClickCreateSubchannel = React.useCallback(() => { + if (!communityThreadInfo) { + return null; + } + return pushModal( + , + ); + }, [popModal, pushModal, communityThreadInfo]); + + const isChatCreation = !communityID || communityID === genesis.id; + + const onClickCreate = isChatCreation + ? onClickNewThread + : onClickCreateSubchannel; + + const createButtonText = isChatCreation + ? 'Create new chat' + : 'Create new channel'; + const threadListContainerRef = React.useRef(); const threads = React.useMemo( @@ -132,9 +167,9 @@ function ChatThreadList(): React.Node {