2022-12-12 14:36:56 -08:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2022-12-15 14:51:30 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
2022-12-12 14:36:56 -08:00
|
|
|
|
|
|
|
import { groupCompose } from 'soapbox/actions/compose';
|
|
|
|
import { fetchGroup } from 'soapbox/actions/groups';
|
|
|
|
import { connectGroupStream } from 'soapbox/actions/streaming';
|
|
|
|
import { expandGroupTimeline } from 'soapbox/actions/timelines';
|
2022-12-15 14:51:30 -08:00
|
|
|
import { Avatar, HStack, Stack } from 'soapbox/components/ui';
|
2022-12-12 14:36:56 -08:00
|
|
|
import ComposeForm from 'soapbox/features/compose/components/compose-form';
|
2022-12-18 04:17:45 -08:00
|
|
|
import { useAppDispatch, useAppSelector, useOwnAccount } from 'soapbox/hooks';
|
2022-12-12 14:36:56 -08:00
|
|
|
|
|
|
|
import Timeline from '../ui/components/timeline';
|
|
|
|
|
|
|
|
type RouteParams = { id: string };
|
|
|
|
|
|
|
|
interface IGroupTimeline {
|
|
|
|
params: RouteParams,
|
|
|
|
}
|
|
|
|
|
|
|
|
const GroupTimeline: React.FC<IGroupTimeline> = (props) => {
|
2022-12-15 14:51:30 -08:00
|
|
|
const account = useOwnAccount();
|
2022-12-12 14:36:56 -08:00
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
const groupId = props.params.id;
|
|
|
|
|
2022-12-18 04:17:45 -08:00
|
|
|
const relationship = useAppSelector((state) => state.group_relationships.get(groupId));
|
|
|
|
|
2022-12-16 12:33:17 -08:00
|
|
|
const handleLoadMore = (maxId: string) => {
|
|
|
|
dispatch(expandGroupTimeline(groupId, { maxId }));
|
2022-12-12 14:36:56 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
dispatch(fetchGroup(groupId));
|
|
|
|
dispatch(expandGroupTimeline(groupId));
|
|
|
|
|
2022-12-16 15:07:35 -08:00
|
|
|
dispatch(groupCompose(`group:${groupId}`, groupId));
|
|
|
|
|
2022-12-12 14:36:56 -08:00
|
|
|
const disconnect = dispatch(connectGroupStream(groupId));
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
disconnect();
|
|
|
|
};
|
2022-12-16 15:07:35 -08:00
|
|
|
}, [groupId]);
|
2022-12-12 14:36:56 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Stack space={2}>
|
2022-12-18 04:17:45 -08:00
|
|
|
{!!account && relationship?.member && (
|
2023-02-01 14:13:42 -08:00
|
|
|
<div className='border-b border-solid border-gray-200 px-2 py-4 dark:border-gray-800'>
|
2022-12-15 14:51:30 -08:00
|
|
|
<HStack alignItems='start' space={4}>
|
|
|
|
<Link to={`/@${account.acct}`}>
|
|
|
|
<Avatar src={account.avatar} size={46} />
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<ComposeForm
|
|
|
|
id={`group:${groupId}`}
|
|
|
|
shouldCondense
|
|
|
|
autoFocus={false}
|
|
|
|
group={groupId}
|
|
|
|
/>
|
|
|
|
</HStack>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<Timeline
|
|
|
|
scrollKey='group_timeline'
|
|
|
|
timelineId={`group:${groupId}`}
|
|
|
|
onLoadMore={handleLoadMore}
|
|
|
|
emptyMessage={<FormattedMessage id='empty_column.group' defaultMessage='There are no posts in this group yet.' />}
|
2022-12-17 04:35:52 -08:00
|
|
|
divideType='border'
|
|
|
|
showGroup={false}
|
2022-12-15 14:51:30 -08:00
|
|
|
/>
|
2022-12-12 14:36:56 -08:00
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GroupTimeline;
|