From 20539987327e14e137f2303590997bbfcab00493 Mon Sep 17 00:00:00 2001 From: mkljczk Date: Fri, 29 Nov 2024 20:36:47 +0100 Subject: [PATCH] pl-fe: Remove unused code Signed-off-by: mkljczk --- packages/pl-fe/src/actions/timelines.ts | 11 +- .../pl-fe/src/actions/trending-statuses.ts | 55 -------- packages/pl-fe/src/components/status-list.tsx | 19 +-- .../feed-suggestions/feed-suggestions.tsx | 119 ------------------ .../pl-fe/src/features/pl-fe-config/index.tsx | 12 -- .../src/normalizers/pl-fe/pl-fe-config.ts | 2 - packages/pl-fe/src/reducers/index.ts | 2 - packages/pl-fe/src/reducers/timelines.ts | 17 --- .../pl-fe/src/reducers/trending-statuses.ts | 35 ------ 9 files changed, 2 insertions(+), 270 deletions(-) delete mode 100644 packages/pl-fe/src/actions/trending-statuses.ts delete mode 100644 packages/pl-fe/src/features/feed-suggestions/feed-suggestions.tsx delete mode 100644 packages/pl-fe/src/reducers/trending-statuses.ts diff --git a/packages/pl-fe/src/actions/timelines.ts b/packages/pl-fe/src/actions/timelines.ts index 275c38453..a51cd6b64 100644 --- a/packages/pl-fe/src/actions/timelines.ts +++ b/packages/pl-fe/src/actions/timelines.ts @@ -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 @@ -341,8 +337,7 @@ type TimelineAction = | ReturnType | ReturnType | ReturnType - | ReturnType - | ReturnType; + | ReturnType; 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, }; diff --git a/packages/pl-fe/src/actions/trending-statuses.ts b/packages/pl-fe/src/actions/trending-statuses.ts deleted file mode 100644 index 2d7222d62..000000000 --- a/packages/pl-fe/src/actions/trending-statuses.ts +++ /dev/null @@ -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; -} - -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({ type: TRENDING_STATUSES_FETCH_REQUEST }); - - return client.trends.getTrendingStatuses().then((statuses) => { - dispatch(importEntities({ statuses })); - dispatch({ type: TRENDING_STATUSES_FETCH_SUCCESS, statuses }); - return statuses; - }).catch(error => { - dispatch({ 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, -}; diff --git a/packages/pl-fe/src/components/status-list.tsx b/packages/pl-fe/src/components/status-list.tsx index 2f7829d0a..c089ad78b 100644 --- a/packages/pl-fe/src/components/status-list.tsx +++ b/packages/pl-fe/src/components/status-list.tsx @@ -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 { /** Unique key to preserve the scroll position when navigating back. */ @@ -54,8 +52,6 @@ const StatusList: React.FC = ({ 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 = ({ 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 = ({ )); }; - const renderFeedSuggestions = (statusId: string): React.ReactNode => ( - - ); - const renderStatuses = (): React.ReactNode[] => { if (isLoading || statusIds.length > 0) { return statusIds.reduce((acc, statusId, index) => { @@ -166,10 +153,6 @@ const StatusList: React.FC = ({ 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 { diff --git a/packages/pl-fe/src/features/feed-suggestions/feed-suggestions.tsx b/packages/pl-fe/src/features/feed-suggestions/feed-suggestions.tsx deleted file mode 100644 index 5b4e32126..000000000 --- a/packages/pl-fe/src/features/feed-suggestions/feed-suggestions.tsx +++ /dev/null @@ -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 = ({ accountId }) => { - const { account } = useAccount(accountId); - if (!account) return null; - - return ( - - - - {account.acct} - - - - - - - - {account.verified && } - - - @{account.acct} - - - - -
- -
-
- ); -}; - -interface IFeedSuggesetions { - statusId: string; - onMoveUp?: (statusId: string, featured?: boolean) => void; - onMoveDown?: (statusId: string, featured?: boolean) => void; -} - -const FeedSuggestions: React.FC = ({ 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 ( - - - - - - - {intl.formatMessage(messages.viewAll)} - - - - - - {suggestedProfiles?.slice(0, 4).map((suggestedProfile) => ( - - ))} - - - - - ); -}; - -export { FeedSuggestions as default }; diff --git a/packages/pl-fe/src/features/pl-fe-config/index.tsx b/packages/pl-fe/src/features/pl-fe-config/index.tsx index 0799ef402..58806ed09 100644 --- a/packages/pl-fe/src/features/pl-fe-config/index.tsx +++ b/packages/pl-fe/src/features/pl-fe-config/index.tsx @@ -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 = () => { /> - - e.target.checked)} - /> - - { diff --git a/packages/pl-fe/src/reducers/index.ts b/packages/pl-fe/src/reducers/index.ts index 1eba73eb7..d0becaf1d 100644 --- a/packages/pl-fe/src/reducers/index.ts +++ b/packages/pl-fe/src/reducers/index.ts @@ -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, }; diff --git a/packages/pl-fe/src/reducers/timelines.ts b/packages/pl-fe/src/reducers/timelines.ts index 465709a77..1a403b84f 100644 --- a/packages/pl-fe/src/reducers/timelines.ts +++ b/packages/pl-fe/src/reducers/timelines.ts @@ -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])]; diff --git a/packages/pl-fe/src/reducers/trending-statuses.ts b/packages/pl-fe/src/reducers/trending-statuses.ts deleted file mode 100644 index 1d2e04034..000000000 --- a/packages/pl-fe/src/reducers/trending-statuses.ts +++ /dev/null @@ -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; - isLoading: boolean; -} - -const initialState: State = { - items: [], - isLoading: false, -}; - -const toIds = (items: Array) => 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 };