Add usePublicStream hook
This commit is contained in:
parent
3cef200a44
commit
d99e266008
4 changed files with 21 additions and 13 deletions
|
@ -190,9 +190,6 @@ const connectTimelineStream = (
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const connectPublicStream = ({ onlyMedia }: Record<string, any> = {}) =>
|
|
||||||
connectTimelineStream(`public${onlyMedia ? ':media' : ''}`, `public${onlyMedia ? ':media' : ''}`);
|
|
||||||
|
|
||||||
const connectRemoteStream = (instance: string, { onlyMedia }: Record<string, any> = {}) =>
|
const connectRemoteStream = (instance: string, { onlyMedia }: Record<string, any> = {}) =>
|
||||||
connectTimelineStream(`remote${onlyMedia ? ':media' : ''}:${instance}`, `public:remote${onlyMedia ? ':media' : ''}&instance=${instance}`);
|
connectTimelineStream(`remote${onlyMedia ? ':media' : ''}:${instance}`, `public:remote${onlyMedia ? ':media' : ''}&instance=${instance}`);
|
||||||
|
|
||||||
|
@ -212,7 +209,6 @@ export {
|
||||||
STREAMING_CHAT_UPDATE,
|
STREAMING_CHAT_UPDATE,
|
||||||
STREAMING_FOLLOW_RELATIONSHIPS_UPDATE,
|
STREAMING_FOLLOW_RELATIONSHIPS_UPDATE,
|
||||||
connectTimelineStream,
|
connectTimelineStream,
|
||||||
connectPublicStream,
|
|
||||||
connectRemoteStream,
|
connectRemoteStream,
|
||||||
connectHashtagStream,
|
connectHashtagStream,
|
||||||
connectDirectStream,
|
connectDirectStream,
|
||||||
|
|
|
@ -47,4 +47,5 @@ export { useUpdateGroupTag } from './groups/useUpdateGroupTag';
|
||||||
// Streaming
|
// Streaming
|
||||||
export { useUserStream } from './streaming/useUserStream';
|
export { useUserStream } from './streaming/useUserStream';
|
||||||
export { useCommunityStream } from './streaming/useCommunityStream';
|
export { useCommunityStream } from './streaming/useCommunityStream';
|
||||||
|
export { usePublicStream } from './streaming/usePublicStream';
|
||||||
export { useNostrStream } from './streaming/useNostrStream';
|
export { useNostrStream } from './streaming/useNostrStream';
|
14
app/soapbox/api/hooks/streaming/usePublicStream.ts
Normal file
14
app/soapbox/api/hooks/streaming/usePublicStream.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { useTimelineStream } from './useTimelineStream';
|
||||||
|
|
||||||
|
interface UsePublicStreamOpts {
|
||||||
|
onlyMedia?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function usePublicStream({ onlyMedia }: UsePublicStreamOpts = {}) {
|
||||||
|
return useTimelineStream(
|
||||||
|
`public${onlyMedia ? ':media' : ''}`,
|
||||||
|
`public${onlyMedia ? ':media' : ''}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { usePublicStream };
|
|
@ -3,8 +3,8 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { changeSetting } from 'soapbox/actions/settings';
|
import { changeSetting } from 'soapbox/actions/settings';
|
||||||
import { connectPublicStream } from 'soapbox/actions/streaming';
|
|
||||||
import { expandPublicTimeline } from 'soapbox/actions/timelines';
|
import { expandPublicTimeline } from 'soapbox/actions/timelines';
|
||||||
|
import { usePublicStream } from 'soapbox/api/hooks';
|
||||||
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
||||||
import { Accordion, Column } from 'soapbox/components/ui';
|
import { Accordion, Column } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useAppDispatch, useInstance, useSettings } from 'soapbox/hooks';
|
import { useAppSelector, useAppDispatch, useInstance, useSettings } from 'soapbox/hooks';
|
||||||
|
@ -23,7 +23,7 @@ const CommunityTimeline = () => {
|
||||||
|
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const onlyMedia = settings.getIn(['public', 'other', 'onlyMedia']);
|
const onlyMedia = !!settings.getIn(['public', 'other', 'onlyMedia'], false);
|
||||||
const next = useAppSelector(state => state.timelines.get('public')?.next);
|
const next = useAppSelector(state => state.timelines.get('public')?.next);
|
||||||
|
|
||||||
const timelineId = 'public';
|
const timelineId = 'public';
|
||||||
|
@ -44,16 +44,13 @@ const CommunityTimeline = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
return dispatch(expandPublicTimeline({ onlyMedia } as any));
|
return dispatch(expandPublicTimeline({ onlyMedia }));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
usePublicStream({ onlyMedia });
|
||||||
dispatch(expandPublicTimeline({ onlyMedia } as any));
|
|
||||||
const disconnect = dispatch(connectPublicStream({ onlyMedia }));
|
|
||||||
|
|
||||||
return () => {
|
useEffect(() => {
|
||||||
disconnect();
|
dispatch(expandPublicTimeline({ onlyMedia }));
|
||||||
};
|
|
||||||
}, [onlyMedia]);
|
}, [onlyMedia]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue