Add useGroupStream hook

This commit is contained in:
Alex Gleason 2023-07-22 14:06:15 -05:00
parent 811a9af670
commit 4a4a2d1a87
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 14 additions and 12 deletions

View File

@ -193,14 +193,10 @@ const connectTimelineStream = (
const connectHashtagStream = (id: string, tag: string, accept: (status: APIEntity) => boolean) => const connectHashtagStream = (id: string, tag: string, accept: (status: APIEntity) => boolean) =>
connectTimelineStream(`hashtag:${id}`, `hashtag&tag=${tag}`, null, accept); connectTimelineStream(`hashtag:${id}`, `hashtag&tag=${tag}`, null, accept);
const connectGroupStream = (id: string) =>
connectTimelineStream(`group:${id}`, `group&group=${id}`);
export { export {
STREAMING_CHAT_UPDATE, STREAMING_CHAT_UPDATE,
STREAMING_FOLLOW_RELATIONSHIPS_UPDATE, STREAMING_FOLLOW_RELATIONSHIPS_UPDATE,
connectTimelineStream, connectTimelineStream,
connectHashtagStream, connectHashtagStream,
connectGroupStream,
type TimelineStreamOpts, type TimelineStreamOpts,
}; };

View File

@ -50,5 +50,6 @@ export { useCommunityStream } from './streaming/useCommunityStream';
export { usePublicStream } from './streaming/usePublicStream'; export { usePublicStream } from './streaming/usePublicStream';
export { useDirectStream } from './streaming/useDirectStream'; export { useDirectStream } from './streaming/useDirectStream';
export { useListStream } from './streaming/useListStream'; export { useListStream } from './streaming/useListStream';
export { useGroupStream } from './streaming/useGroupStream';
export { useRemoteStream } from './streaming/useRemoteStream'; export { useRemoteStream } from './streaming/useRemoteStream';
export { useNostrStream } from './streaming/useNostrStream'; export { useNostrStream } from './streaming/useNostrStream';

View File

@ -0,0 +1,10 @@
import { useTimelineStream } from './useTimelineStream';
function useGroupStream(groupId: string) {
return useTimelineStream(
`group:${groupId}`,
`group&group=${groupId}`,
);
}
export { useGroupStream };

View File

@ -4,9 +4,8 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { groupCompose, setGroupTimelineVisible, uploadCompose } from 'soapbox/actions/compose'; import { groupCompose, setGroupTimelineVisible, uploadCompose } from 'soapbox/actions/compose';
import { connectGroupStream } from 'soapbox/actions/streaming';
import { expandGroupFeaturedTimeline, expandGroupTimeline } from 'soapbox/actions/timelines'; import { expandGroupFeaturedTimeline, expandGroupTimeline } from 'soapbox/actions/timelines';
import { useGroup } from 'soapbox/api/hooks'; import { useGroup, useGroupStream } from 'soapbox/api/hooks';
import { Avatar, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui'; import { Avatar, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui';
import ComposeForm from 'soapbox/features/compose/components/compose-form'; import ComposeForm from 'soapbox/features/compose/components/compose-form';
import { useAppDispatch, useAppSelector, useDraggedFiles, useOwnAccount } from 'soapbox/hooks'; import { useAppDispatch, useAppSelector, useDraggedFiles, useOwnAccount } from 'soapbox/hooks';
@ -49,16 +48,12 @@ const GroupTimeline: React.FC<IGroupTimeline> = (props) => {
dispatch(setGroupTimelineVisible(composeId, !groupTimelineVisible)); dispatch(setGroupTimelineVisible(composeId, !groupTimelineVisible));
}; };
useGroupStream(groupId);
useEffect(() => { useEffect(() => {
dispatch(expandGroupTimeline(groupId)); dispatch(expandGroupTimeline(groupId));
dispatch(expandGroupFeaturedTimeline(groupId)); dispatch(expandGroupFeaturedTimeline(groupId));
dispatch(groupCompose(composeId, groupId)); dispatch(groupCompose(composeId, groupId));
const disconnect = dispatch(connectGroupStream(groupId));
return () => {
disconnect();
};
}, [groupId]); }, [groupId]);
if (!group) { if (!group) {