import clsx from 'clsx'; import React, { useEffect, useRef } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { groupCompose, setGroupTimelineVisible, uploadCompose } from 'soapbox/actions/compose'; import { connectGroupStream } from 'soapbox/actions/streaming'; import { expandGroupTimeline } from 'soapbox/actions/timelines'; import { useGroup } from 'soapbox/api/hooks'; import { Avatar, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui'; import ComposeForm from 'soapbox/features/compose/components/compose-form'; import { useAppDispatch, useAppSelector, useDraggedFiles, useOwnAccount } from 'soapbox/hooks'; import Timeline from '../ui/components/timeline'; type RouteParams = { groupId: string }; interface IGroupTimeline { params: RouteParams } const GroupTimeline: React.FC = (props) => { const intl = useIntl(); const account = useOwnAccount(); const dispatch = useAppDispatch(); const composer = useRef(null); const { groupId } = props.params; const { group } = useGroup(groupId); const composeId = `group:${groupId}`; const canComposeGroupStatus = !!account && group?.relationship?.member; const groupTimelineVisible = useAppSelector((state) => !!state.compose.get(composeId)?.group_timeline_visible); const { isDragging, isDraggedOver } = useDraggedFiles(composer, (files) => { dispatch(uploadCompose(composeId, files, intl)); }); const handleLoadMore = (maxId: string) => { dispatch(expandGroupTimeline(groupId, { maxId })); }; const handleToggleChange = () => { dispatch(setGroupTimelineVisible(composeId, !groupTimelineVisible)); }; useEffect(() => { dispatch(expandGroupTimeline(groupId)); dispatch(groupCompose(composeId, groupId)); const disconnect = dispatch(connectGroupStream(groupId)); return () => { disconnect(); }; }, [groupId]); if (!group) { return null; } return ( {canComposeGroupStatus && (
)} />
)}
} emptyMessageCard={false} divideType='border' showGroup={false} /> ); }; export default GroupTimeline;