Hide unauth features if they're restricted by the backend

This commit is contained in:
Alex Gleason
2023-09-24 12:51:00 -05:00
parent aabaaee8b8
commit 8500e7bb9a
4 changed files with 59 additions and 25 deletions

View File

@@ -5,7 +5,7 @@ import { expandCommunityTimeline } from 'soapbox/actions/timelines';
import { useCommunityStream } from 'soapbox/api/hooks';
import PullToRefresh from 'soapbox/components/pull-to-refresh';
import { Column } from 'soapbox/components/ui';
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
import { useAppSelector, useAppDispatch, useInstance } from 'soapbox/hooks';
import Timeline from '../ui/components/timeline';
@@ -13,22 +13,31 @@ import { SiteBanner } from './components/site-banner';
const LandingTimeline = () => {
const dispatch = useAppDispatch();
const instance = useInstance();
const timelineEnabled = !instance.pleroma.metadata.restrict_unauthenticated.timelines.local;
const next = useAppSelector(state => state.timelines.get('community')?.next);
const timelineId = 'community';
const handleLoadMore = (maxId: string) => {
dispatch(expandCommunityTimeline({ url: next, maxId }));
if (timelineEnabled) {
dispatch(expandCommunityTimeline({ url: next, maxId }));
}
};
const handleRefresh = () => {
return dispatch(expandCommunityTimeline());
const handleRefresh = async () => {
if (timelineEnabled) {
return dispatch(expandCommunityTimeline());
}
};
useCommunityStream();
useCommunityStream({ enabled: timelineEnabled });
useEffect(() => {
dispatch(expandCommunityTimeline());
if (timelineEnabled) {
dispatch(expandCommunityTimeline());
}
}, []);
return (
@@ -37,16 +46,18 @@ const LandingTimeline = () => {
<SiteBanner />
</div>
<PullToRefresh onRefresh={handleRefresh}>
<Timeline
scrollKey={`${timelineId}_timeline`}
timelineId={timelineId}
prefix='home'
onLoadMore={handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
divideType='space'
/>
</PullToRefresh>
{timelineEnabled && (
<PullToRefresh onRefresh={handleRefresh}>
<Timeline
scrollKey={`${timelineId}_timeline`}
timelineId={timelineId}
prefix='home'
onLoadMore={handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
divideType='space'
/>
</PullToRefresh>
)}
</Column>
);
};