bigbuffet-rw/app/soapbox/features/chats/components/chat-widget.tsx

36 lines
794 B
TypeScript
Raw Normal View History

2022-08-25 12:56:53 -07:00
import React, { useEffect } from 'react';
2022-08-16 10:38:17 -07:00
2022-08-25 12:56:53 -07:00
import { connectDirectStream } from 'soapbox/actions/streaming';
2022-08-16 10:38:17 -07:00
import { ChatProvider } from 'soapbox/contexts/chat-context';
2022-09-22 09:55:29 -07:00
import { useAppDispatch, useOwnAccount } from 'soapbox/hooks';
2022-08-16 10:38:17 -07:00
2022-08-18 09:52:04 -07:00
import ChatPane from './chat-pane/chat-pane';
2022-08-16 10:38:17 -07:00
const ChatWidget = () => {
2022-09-22 09:55:29 -07:00
const account = useOwnAccount();
2022-08-25 12:56:53 -07:00
const dispatch = useAppDispatch();
const path = location.pathname;
const shouldHideWidget = Boolean(path.match(/^\/chats/));
2022-08-25 12:56:53 -07:00
useEffect(() => {
const disconnect = dispatch(connectDirectStream());
return (() => {
disconnect();
});
}, []);
if (!account?.chats_onboarded || shouldHideWidget) {
2022-09-22 09:55:29 -07:00
return null;
}
2022-08-16 10:38:17 -07:00
return (
<ChatProvider>
<ChatPane />
</ChatProvider>
);
};
export default ChatWidget;