2022-05-09 20:22:01 -07:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
|
|
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
|
2022-05-30 11:23:55 -07:00
|
|
|
import { connectRemoteStream } from 'soapbox/actions/streaming';
|
|
|
|
import { expandRemoteTimeline } from 'soapbox/actions/timelines';
|
2022-11-15 06:11:30 -08:00
|
|
|
import IconButton from 'soapbox/components/icon-button';
|
2022-05-28 09:02:04 -07:00
|
|
|
import { HStack, Text } from 'soapbox/components/ui';
|
2022-05-09 20:22:01 -07:00
|
|
|
import Column from 'soapbox/features/ui/components/column';
|
|
|
|
import { useAppDispatch, useSettings } from 'soapbox/hooks';
|
|
|
|
|
2022-06-03 10:31:23 -07:00
|
|
|
import Timeline from '../ui/components/timeline';
|
2022-05-09 20:22:01 -07:00
|
|
|
|
|
|
|
import PinnedHostsPicker from './components/pinned_hosts_picker';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'column.remote', defaultMessage: 'Federated timeline' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IRemoteTimeline {
|
|
|
|
params?: {
|
|
|
|
instance?: string,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** View statuses from a remote instance. */
|
|
|
|
const RemoteTimeline: React.FC<IRemoteTimeline> = ({ params }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const history = useHistory();
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
2022-06-18 11:58:42 -07:00
|
|
|
const instance = params?.instance as string;
|
2022-05-09 20:22:01 -07:00
|
|
|
const settings = useSettings();
|
|
|
|
|
|
|
|
const stream = useRef<any>(null);
|
|
|
|
|
|
|
|
const timelineId = 'remote';
|
|
|
|
const onlyMedia = !!settings.getIn(['remote', 'other', 'onlyMedia']);
|
|
|
|
|
|
|
|
const pinned: boolean = (settings.getIn(['remote_timeline', 'pinnedHosts']) as any).includes(instance);
|
|
|
|
|
|
|
|
const disconnect = () => {
|
|
|
|
if (stream.current) {
|
|
|
|
stream.current();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-11 10:22:10 -07:00
|
|
|
const handleCloseClick: React.MouseEventHandler = () => {
|
|
|
|
history.push('/timeline/fediverse');
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLoadMore = (maxId: string) => {
|
|
|
|
dispatch(expandRemoteTimeline(instance, { maxId, onlyMedia }));
|
|
|
|
};
|
|
|
|
|
2022-05-09 20:22:01 -07:00
|
|
|
useEffect(() => {
|
|
|
|
disconnect();
|
|
|
|
dispatch(expandRemoteTimeline(instance, { onlyMedia, maxId: undefined }));
|
|
|
|
stream.current = dispatch(connectRemoteStream(instance, { onlyMedia }));
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
disconnect();
|
|
|
|
stream.current = null;
|
|
|
|
};
|
|
|
|
}, [onlyMedia]);
|
|
|
|
|
|
|
|
return (
|
2022-07-15 15:03:21 -07:00
|
|
|
<Column label={intl.formatMessage(messages.title)} heading={instance} transparent withHeader={false}>
|
2022-05-09 20:22:01 -07:00
|
|
|
{instance && <PinnedHostsPicker host={instance} />}
|
2022-05-28 09:02:04 -07:00
|
|
|
{!pinned && <HStack className='mb-4 px-2' space={2}>
|
2022-07-09 09:20:02 -07:00
|
|
|
<IconButton iconClassName='h-5 w-5' src={require('@tabler/icons/x.svg')} onClick={handleCloseClick} />
|
2022-05-28 09:02:04 -07:00
|
|
|
<Text>
|
|
|
|
<FormattedMessage
|
|
|
|
id='remote_timeline.filter_message'
|
|
|
|
defaultMessage='You are viewing the timeline of {instance}.'
|
|
|
|
values={{ instance }}
|
|
|
|
/>
|
|
|
|
</Text>
|
|
|
|
</HStack>}
|
2022-06-03 10:31:23 -07:00
|
|
|
<Timeline
|
2022-05-09 20:22:01 -07:00
|
|
|
scrollKey={`${timelineId}_${instance}_timeline`}
|
|
|
|
timelineId={`${timelineId}${onlyMedia ? ':media' : ''}:${instance}`}
|
|
|
|
onLoadMore={handleLoadMore}
|
|
|
|
emptyMessage={
|
|
|
|
<FormattedMessage
|
|
|
|
id='empty_column.remote'
|
|
|
|
defaultMessage='There is nothing here! Manually follow users from {instance} to fill it up.'
|
|
|
|
values={{ instance }}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
divideType='space'
|
|
|
|
/>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RemoteTimeline;
|