pl-fe: remove unused

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-12-04 19:46:48 +01:00
parent 3f4045f029
commit 5efacc274f
4 changed files with 23 additions and 26 deletions

View file

@ -23,7 +23,7 @@ const removeFollowRequest = (accountId: string) =>
pages: data.pages.map(({ items, ...page }) => ({ ...page, items: items.filter((id) => id !== accountId) })),
} : undefined);
const useFollowRequests = () => {
const makeUseFollowRequests = <T>(select: ((data: InfiniteData<PaginatedResponse<string, true>, PaginatedResponse<string, true>>) => T)) => () => {
const client = useClient();
return useInfiniteQuery({
@ -31,10 +31,14 @@ const useFollowRequests = () => {
queryFn: ({ pageParam }) => pageParam.next?.() || client.myAccount.getFollowRequests().then(minifyAccountList),
initialPageParam: { previous: null, next: null, items: [], partial: false } as PaginatedResponse<string>,
getNextPageParam: (page) => page.next ? page : undefined,
select: (data) => data.pages.map(page => page.items).flat(),
select,
});
};
const useFollowRequests = makeUseFollowRequests((data) => data.pages.map(page => page.items).flat());
const useFollowRequestsCount = makeUseFollowRequests((data) => data.pages.map(page => page.items).flat().length);
const useAcceptFollowRequestMutation = (accountId: string) => {
const client = useClient();
@ -61,4 +65,11 @@ const prefetchFollowRequests = (client: PlApiClient) => queryClient.prefetchInfi
initialPageParam: { previous: null, next: null, items: [], partial: false } as PaginatedResponse<string>,
});
export { appendFollowRequest, useFollowRequests, useAcceptFollowRequestMutation, useRejectFollowRequestMutation, prefetchFollowRequests };
export {
appendFollowRequest,
useFollowRequests,
useFollowRequestsCount,
useAcceptFollowRequestMutation,
useRejectFollowRequestMutation,
prefetchFollowRequests,
};

View file

@ -5,6 +5,7 @@ import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
import { Link, NavLink } from 'react-router-dom';
import { fetchOwnAccounts, logOut, switchAccount } from 'pl-fe/actions/auth';
import { useFollowRequestsCount } from 'pl-fe/api/hooks/account-lists/use-follow-requests';
import { useAccount } from 'pl-fe/api/hooks/accounts/use-account';
import { useInteractionRequestsCount } from 'pl-fe/api/hooks/statuses/use-interaction-requests';
import Account from 'pl-fe/components/account';
@ -96,7 +97,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
const { account } = useAccount(me || undefined);
const otherAccounts = useAppSelector((state) => getOtherAccounts(state));
const { settings } = useSettingsStore();
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.length);
const followRequestsCount = useFollowRequestsCount().data || 0;
const interactionRequestsCount = useInteractionRequestsCount().data || 0;
const scheduledStatusCount = useAppSelector((state) => Object.keys(state.scheduled_statuses).length);
const draftCount = useAppSelector((state) => Object.keys(state.draft_statuses).length);

View file

@ -1,6 +1,7 @@
import React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { useFollowRequestsCount } from 'pl-fe/api/hooks/account-lists/use-follow-requests';
import { useInteractionRequestsCount } from 'pl-fe/api/hooks/statuses/use-interaction-requests';
import Icon from 'pl-fe/components/ui/icon';
import Stack from 'pl-fe/components/ui/stack';
@ -48,7 +49,7 @@ const SidebarNavigation = () => {
const logoSrc = useLogo();
const notificationCount = useAppSelector((state) => state.notifications.unread);
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.length);
const followRequestsCount = useFollowRequestsCount().data || 0;
const interactionRequestsCount = useInteractionRequestsCount().data || 0;
const dashboardCount = useAppSelector((state) => state.admin.openReports.length + state.admin.awaitingApproval.length);
const scheduledStatusCount = useAppSelector((state) => Object.keys(state.scheduled_statuses).length);

View file

@ -18,39 +18,23 @@ interface List {
isLoading: boolean;
}
type ListKey = 'follow_requests';
type NestedListKey = 'pinned' | 'familiar_followers' | 'membership_requests' | 'group_blocks';
type NestedListKey = 'pinned' | 'familiar_followers' | 'group_blocks';
type State = Record<ListKey, List> & Record<NestedListKey, Record<string, List>>;
type State = Record<NestedListKey, Record<string, List>>;
const initialState: State = {
follow_requests: { next: null, items: [], isLoading: false },
pinned: {},
familiar_followers: {},
membership_requests: {},
group_blocks: {},
};
type NestedListPath = [NestedListKey, string];
type ListPath = [ListKey];
const normalizeList = (state: State, path: NestedListPath | ListPath, accounts: Array<Pick<Account, 'id'>>, next: (() => Promise<PaginatedResponse<any>>) | null = null) =>
const normalizeList = (state: State, path: NestedListPath, accounts: Array<Pick<Account, 'id'>>, next: (() => Promise<PaginatedResponse<any>>) | null = null) =>
create(state, (draft) => {
let list: List;
if (path.length === 1) {
list = draft[path[0]];
} else {
list = draft[path[0]][path[1]];
}
const list = draft[path[0]][path[1]];
const newList = { ...list, next, items: accounts.map(item => item.id), isLoading: false };
if (path.length === 1) {
draft[path[0]] = newList;
} else {
draft[path[0]][path[1]] = newList;
}
draft[path[0]][path[1]] = newList;
});
const userLists = (state = initialState, action: AccountsAction | FamiliarFollowersAction | GroupsAction): State => {