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-11-26 11:18:11 -08:00
|
|
|
import SubNavigation from 'soapbox/components/sub-navigation';
|
|
|
|
import { Column, HStack, Text } from 'soapbox/components/ui';
|
2022-05-09 20:22:01 -07:00
|
|
|
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
|
|
|
|
2022-11-15 11:00:40 -08:00
|
|
|
import PinnedHostsPicker from './components/pinned-hosts-picker';
|
2022-05-09 20:22:01 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2022-11-26 11:18:11 -08:00
|
|
|
heading: { id: 'column.remote', defaultMessage: 'Federated timeline' },
|
2022-05-09 20:22:01 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
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-11-26 11:18:11 -08:00
|
|
|
<Column label={intl.formatMessage(messages.heading)} transparent withHeader={false}>
|
|
|
|
<div className='px-4 pt-4 sm:p-0'>
|
|
|
|
<SubNavigation message={instance} />
|
|
|
|
|
|
|
|
{instance && <PinnedHostsPicker host={instance} />}
|
|
|
|
|
|
|
|
{!pinned && (
|
|
|
|
<HStack className='mb-4 px-2' space={2}>
|
|
|
|
<IconButton iconClassName='h-5 w-5' src={require('@tabler/icons/x.svg')} onClick={handleCloseClick} />
|
|
|
|
<Text>
|
|
|
|
<FormattedMessage
|
|
|
|
id='remote_timeline.filter_message'
|
|
|
|
defaultMessage='You are viewing the timeline of {instance}.'
|
|
|
|
values={{ instance }}
|
|
|
|
/>
|
|
|
|
</Text>
|
|
|
|
</HStack>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
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;
|