pl-fe: Remove unused code

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-11-29 20:36:47 +01:00
parent 65772abf87
commit 2053998732
9 changed files with 2 additions and 270 deletions

View file

@ -30,8 +30,6 @@ const TIMELINE_EXPAND_REQUEST = 'TIMELINE_EXPAND_REQUEST' as const;
const TIMELINE_EXPAND_SUCCESS = 'TIMELINE_EXPAND_SUCCESS' as const;
const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL' as const;
const TIMELINE_INSERT = 'TIMELINE_INSERT' as const;
const MAX_QUEUED_ITEMS = 40;
const processTimelineUpdate = (timeline: string, status: BaseStatus) =>
@ -329,8 +327,6 @@ const scrollTopTimeline = (timeline: string, top: boolean) => ({
top,
});
const insertSuggestionsIntoTimeline = () => ({ type: TIMELINE_INSERT, timeline: 'home' });
// TODO: other actions
type TimelineAction =
| ReturnType<typeof updateTimeline>
@ -341,8 +337,7 @@ type TimelineAction =
| ReturnType<typeof scrollTopTimeline>
| ReturnType<typeof expandTimelineRequest>
| ReturnType<typeof expandTimelineSuccess>
| ReturnType<typeof expandTimelineFail>
| ReturnType<typeof insertSuggestionsIntoTimeline>;
| ReturnType<typeof expandTimelineFail>;
export {
TIMELINE_UPDATE,
@ -354,11 +349,8 @@ export {
TIMELINE_EXPAND_REQUEST,
TIMELINE_EXPAND_SUCCESS,
TIMELINE_EXPAND_FAIL,
TIMELINE_INSERT,
MAX_QUEUED_ITEMS,
processTimelineUpdate,
updateTimeline,
updateTimelineQueue,
dequeueTimeline,
deleteFromTimelines,
clearTimeline,
@ -371,6 +363,5 @@ export {
fetchHashtagTimeline,
expandTimelineSuccess,
scrollTopTimeline,
insertSuggestionsIntoTimeline,
type TimelineAction,
};

View file

@ -1,55 +0,0 @@
import { getClient } from '../api';
import { importEntities } from './importer';
import type { Status } from 'pl-api';
import type { AppDispatch, RootState } from 'pl-fe/store';
const TRENDING_STATUSES_FETCH_REQUEST = 'TRENDING_STATUSES_FETCH_REQUEST' as const;
const TRENDING_STATUSES_FETCH_SUCCESS = 'TRENDING_STATUSES_FETCH_SUCCESS' as const;
const TRENDING_STATUSES_FETCH_FAIL = 'TRENDING_STATUSES_FETCH_FAIL' as const;
interface TrendingStatusesFetchRequestAction {
type: typeof TRENDING_STATUSES_FETCH_REQUEST;
}
interface TrendingStatusesFetchSuccessAction {
type: typeof TRENDING_STATUSES_FETCH_SUCCESS;
statuses: Array<Status>;
}
interface TrendingStatusesFetchFailAction {
type: typeof TRENDING_STATUSES_FETCH_FAIL;
error: any;
}
const fetchTrendingStatuses = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const client = getClient(state);
if (!client.features.trendingStatuses) return;
dispatch<TrendingStatusesFetchRequestAction>({ type: TRENDING_STATUSES_FETCH_REQUEST });
return client.trends.getTrendingStatuses().then((statuses) => {
dispatch(importEntities({ statuses }));
dispatch<TrendingStatusesFetchSuccessAction>({ type: TRENDING_STATUSES_FETCH_SUCCESS, statuses });
return statuses;
}).catch(error => {
dispatch<TrendingStatusesFetchFailAction>({ type: TRENDING_STATUSES_FETCH_FAIL, error });
});
};
type TrendingStatusesAction =
| TrendingStatusesFetchRequestAction
| TrendingStatusesFetchSuccessAction
| TrendingStatusesFetchFailAction;
export {
TRENDING_STATUSES_FETCH_REQUEST,
TRENDING_STATUSES_FETCH_SUCCESS,
TRENDING_STATUSES_FETCH_FAIL,
fetchTrendingStatuses,
type TrendingStatusesAction,
};

View file

@ -8,10 +8,8 @@ import ScrollableList, { type IScrollableListWithContainer } from 'pl-fe/compone
import Stack from 'pl-fe/components/ui/stack';
import Text from 'pl-fe/components/ui/text';
import StatusContainer from 'pl-fe/containers/status-container';
import FeedSuggestions from 'pl-fe/features/feed-suggestions/feed-suggestions';
import PlaceholderStatus from 'pl-fe/features/placeholder/components/placeholder-status';
import PendingStatus from 'pl-fe/features/ui/components/pending-status';
import { usePlFeConfig } from 'pl-fe/hooks/use-pl-fe-config';
interface IStatusList extends Omit<IScrollableListWithContainer, 'onLoadMore' | 'children'> {
/** Unique key to preserve the scroll position when navigating back. */
@ -54,8 +52,6 @@ const StatusList: React.FC<IStatusList> = ({
className,
...other
}) => {
const plFeConfig = usePlFeConfig();
const getFeaturedStatusCount = () => featuredStatusIds?.length || 0;
const getCurrentStatusIndex = (id: string, featured: boolean): number => {
@ -79,7 +75,7 @@ const StatusList: React.FC<IStatusList> = ({
const handleLoadOlder = useCallback(debounce(() => {
const maxId = lastStatusId || statusIds.at(-1);
if (onLoadMore && maxId) {
onLoadMore(maxId.replace('末suggestions-', ''));
onLoadMore(maxId);
}
}, 300, { leading: true }), [onLoadMore, lastStatusId, statusIds.at(-1)]);
@ -149,15 +145,6 @@ const StatusList: React.FC<IStatusList> = ({
));
};
const renderFeedSuggestions = (statusId: string): React.ReactNode => (
<FeedSuggestions
key='suggestions'
statusId={statusId}
onMoveUp={handleMoveUp}
onMoveDown={handleMoveDown}
/>
);
const renderStatuses = (): React.ReactNode[] => {
if (isLoading || statusIds.length > 0) {
return statusIds.reduce((acc, statusId, index) => {
@ -166,10 +153,6 @@ const StatusList: React.FC<IStatusList> = ({
if (gap) {
acc.push(gap);
}
} else if (statusId.startsWith('末suggestions-')) {
if (plFeConfig.feedInjection) {
acc.push(renderFeedSuggestions(statusId));
}
} else if (statusId.startsWith('末pending-')) {
acc.push(renderPendingStatus(statusId));
} else {

View file

@ -1,119 +0,0 @@
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { Link } from 'react-router-dom';
import { useAccount } from 'pl-fe/api/hooks/accounts/use-account';
import { useSuggestedAccounts } from 'pl-fe/api/hooks/trends/use-suggested-accounts';
import Card, { CardBody, CardTitle } from 'pl-fe/components/ui/card';
import HStack from 'pl-fe/components/ui/hstack';
import Stack from 'pl-fe/components/ui/stack';
import Text from 'pl-fe/components/ui/text';
import VerificationBadge from 'pl-fe/components/verification-badge';
import Emojify from '../emoji/emojify';
import ActionButton from '../ui/components/action-button';
import { HotKeys } from '../ui/components/hotkeys';
const messages = defineMessages({
heading: { id: 'feed_suggestions.heading', defaultMessage: 'Suggested profiles' },
viewAll: { id: 'feed_suggestions.view_all', defaultMessage: 'View all' },
});
interface ISuggestionItem {
accountId: string;
}
const SuggestionItem: React.FC<ISuggestionItem> = ({ accountId }) => {
const { account } = useAccount(accountId);
if (!account) return null;
return (
<Stack space={3} className='w-52 shrink-0 rounded-md border border-solid border-gray-300 p-4 dark:border-gray-800 md:w-full md:shrink md:border-transparent md:p-0 dark:md:border-transparent'>
<Link
to={`/@${account.acct}`}
title={account.acct}
>
<Stack space={3} className='mx-auto w-40 md:w-24'>
<img
src={account.avatar}
className='mx-auto block size-16 min-w-[56px] rounded-full object-cover'
alt={account.acct}
/>
<Stack>
<HStack alignItems='center' justifyContent='center' space={1}>
<Text weight='semibold' truncate align='center' size='sm' className='max-w-[95%]'>
<Emojify text={account.display_name} emojis={account.emojis} />
</Text>
{account.verified && <VerificationBadge />}
</HStack>
<Text theme='muted' align='center' size='sm' truncate>@{account.acct}</Text>
</Stack>
</Stack>
</Link>
<div className='text-center'>
<ActionButton account={account} />
</div>
</Stack>
);
};
interface IFeedSuggesetions {
statusId: string;
onMoveUp?: (statusId: string, featured?: boolean) => void;
onMoveDown?: (statusId: string, featured?: boolean) => void;
}
const FeedSuggestions: React.FC<IFeedSuggesetions> = ({ statusId, onMoveUp, onMoveDown }) => {
const intl = useIntl();
const { data: suggestedProfiles, isLoading } = useSuggestedAccounts();
if (!isLoading && suggestedProfiles?.length === 0) return null;
const handleHotkeyMoveUp = (e?: KeyboardEvent): void => {
if (onMoveUp) {
onMoveUp(statusId);
}
};
const handleHotkeyMoveDown = (e?: KeyboardEvent): void => {
if (onMoveDown) {
onMoveDown(statusId);
}
};
const handlers = {
moveUp: handleHotkeyMoveUp,
moveDown: handleHotkeyMoveDown,
};
return (
<HotKeys handlers={handlers}>
<Card size='lg' variant='rounded' className='focusable space-y-6' tabIndex={0}>
<HStack justifyContent='between' alignItems='center'>
<CardTitle title={intl.formatMessage(messages.heading)} />
<Link
to='/suggestions'
className='text-primary-600 hover:underline dark:text-accent-blue'
>
{intl.formatMessage(messages.viewAll)}
</Link>
</HStack>
<CardBody>
<HStack space={4} alignItems='center' className='overflow-x-auto md:space-x-0 lg:overflow-x-hidden'>
{suggestedProfiles?.slice(0, 4).map((suggestedProfile) => (
<SuggestionItem key={suggestedProfile.account_id} accountId={suggestedProfile.account_id} />
))}
</HStack>
</CardBody>
</Card>
</HotKeys>
);
};
export { FeedSuggestions as default };

View file

@ -45,8 +45,6 @@ const messages = defineMessages({
displayCtaLabel: { id: 'plfe_config.cta_label', defaultMessage: 'Display call to action panels if not authenticated' },
mediaPreviewLabel: { id: 'plfe_config.media_preview_label', defaultMessage: 'Prefer preview media for thumbnails' },
mediaPreviewHint: { id: 'plfe_config.media_preview_hint', defaultMessage: 'Some backends provide an optimized version of media for display in timelines. However, these preview images may be too small without additional configuration.' },
feedInjectionLabel: { id: 'plfe_config.feed_injection_label', defaultMessage: 'Feed injection' },
feedInjectionHint: { id: 'plfe_config.feed_injection_hint', defaultMessage: 'Inject the feed with additional content, such as suggested profiles.' },
tileServerLabel: { id: 'plfe_config.tile_server_label', defaultMessage: 'Map tile server' },
tileServerAttributionLabel: { id: 'plfe_config.tile_server_attribution_label', defaultMessage: 'Map tiles attribution' },
redirectRootNoLoginLabel: { id: 'plfe_config.redirect_root_no_login_label', defaultMessage: 'Redirect homepage' },
@ -231,16 +229,6 @@ const PlFeConfigEditor: React.FC = () => {
/>
</ListItem>
<ListItem
label={intl.formatMessage(messages.feedInjectionLabel)}
hint={intl.formatMessage(messages.feedInjectionHint)}
>
<Toggle
checked={plFe.feedInjection === true}
onChange={handleChange('feedInjection', (e) => e.target.checked)}
/>
</ListItem>
<ListItem
label={intl.formatMessage(messages.mediaPreviewLabel)}
hint={intl.formatMessage(messages.mediaPreviewHint)}

View file

@ -95,8 +95,6 @@ const plFeConfigSchema = v.pipe(coerceObject({
linkFooterMessage: v.fallback(v.string(), ''),
links: v.fallback(v.record(v.string(), v.string()), {}),
displayCta: v.fallback(v.boolean(), false),
/** Whether to inject suggested profiles into the Home feed. */
feedInjection: v.fallback(v.boolean(), true),
tileServer: v.fallback(v.string(), ''),
tileServerAttribution: v.fallback(v.string(), ''),
redirectRootNoLogin: v.fallback(v.pipe(v.string(), v.transform((url: string) => {

View file

@ -37,7 +37,6 @@ import status_lists from './status-lists';
import statuses from './statuses';
import tags from './tags';
import timelines from './timelines';
import trending_statuses from './trending-statuses';
import user_lists from './user-lists';
const reducers = {
@ -75,7 +74,6 @@ const reducers = {
statuses,
tags,
timelines,
trending_statuses,
user_lists,
};

View file

@ -1,4 +1,3 @@
import sample from 'lodash/sample';
import { create } from 'mutative';
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS, type AccountsAction } from '../actions/accounts';
@ -15,7 +14,6 @@ import {
TIMELINE_DEQUEUE,
MAX_QUEUED_ITEMS,
TIMELINE_SCROLL_TOP,
TIMELINE_INSERT,
type TimelineAction,
} from '../actions/timelines';
@ -333,21 +331,6 @@ const timelines = (state: State = initialState, action: AccountsAction | Interac
// return filterTimeline(state, 'home', action.relationship, action.statuses);
case TIMELINE_SCROLL_TOP:
return create(state, (draft) => updateTop(state, action.timeline, action.top));
case TIMELINE_INSERT:
return create(state, (draft) => updateTimeline(draft, action.timeline, (timeline) => {
let oldIdsArray = timeline.items;
const existingSuggestionId = oldIdsArray.find(key => key.includes('末suggestions'));
if (existingSuggestionId) {
oldIdsArray = oldIdsArray.slice(1);
}
const positionInTimeline = sample([5, 6, 7, 8, 9]) as number;
if (timeline.items.at(-1)) {
oldIdsArray.splice(positionInTimeline, 0, `末suggestions-${timeline.items.at(-1)}`);
}
timeline.items = oldIdsArray;
}));
case PIN_SUCCESS:
return create(state, (draft) => updateTimeline(draft, `account:${action.accountId}:with_replies:pinned`, (timeline) => {
timeline.items = [...new Set([action.statusId, ...timeline.items])];

View file

@ -1,35 +0,0 @@
import { create } from 'mutative';
import { TRENDING_STATUSES_FETCH_REQUEST, TRENDING_STATUSES_FETCH_SUCCESS, type TrendingStatusesAction } from 'pl-fe/actions/trending-statuses';
import type { Status } from 'pl-api';
interface State {
items: Array<string>;
isLoading: boolean;
}
const initialState: State = {
items: [],
isLoading: false,
};
const toIds = (items: Array<Status>) => items.map(item => item.id);
const trending_statuses = (state = initialState, action: TrendingStatusesAction) => {
switch (action.type) {
case TRENDING_STATUSES_FETCH_REQUEST:
return create(state, (draft) => {
draft.isLoading = true;
});
case TRENDING_STATUSES_FETCH_SUCCESS:
return create(state, (draft) => {
draft.items = toIds(action.statuses);
draft.isLoading = false;
});
default:
return state;
}
};
export { trending_statuses as default };