Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-08-18 20:59:50 +02:00
parent cbee2ff018
commit e73341d1a9
7 changed files with 35 additions and 20 deletions

View file

@ -133,7 +133,7 @@
"multiselect-react-dropdown": "^2.0.25",
"object-to-formdata": "^4.5.1",
"path-browserify": "^1.0.1",
"pl-api": "^0.0.5",
"pl-api": "^0.0.6",
"postcss": "^8.4.29",
"process": "^0.11.10",
"punycode": "^2.1.1",

View file

@ -50,7 +50,7 @@ const fetchOAuthTokens = () =>
dispatch({ type: FETCH_TOKENS_REQUEST });
return getClient(getState).settings.getOauthTokens().then((tokens) => {
dispatch({ type: FETCH_TOKENS_SUCCESS, tokens });
}).catch(() => {
}).catch((e) => {
dispatch({ type: FETCH_TOKENS_FAIL });
});
};

View file

@ -1,9 +1,10 @@
import { accountSchema, mutedAccountSchema, type Account as BaseAccount } from 'pl-api';
import { useInfiniteQuery } from '@tanstack/react-query';
import { PaginatedResponse, type Account as BaseAccount } from 'pl-api';
import { Entities } from 'soapbox/entity-store/entities';
import { useEntities } from 'soapbox/entity-store/hooks';
import { useClient } from 'soapbox/hooks';
import { normalizeAccount, type Account } from 'soapbox/normalizers';
import { type Account, normalizeAccount } from 'soapbox/normalizers';
import { flattenPages } from 'soapbox/utils/queries';
import { useRelationships } from './useRelationships';
@ -14,23 +15,36 @@ interface useAccountListOpts {
}
const useAccountList = (listKey: string[], entityFn: EntityFn<void>, opts: useAccountListOpts = {}) => {
const { entities, ...rest } = useEntities<BaseAccount, Account>(
[Entities.ACCOUNTS, ...listKey],
entityFn,
{ schema: listKey[0] === 'mutes' ? mutedAccountSchema : accountSchema, enabled: opts.enabled, transform: normalizeAccount },
);
const getAccounts = async (pageParam?: Pick<PaginatedResponse<BaseAccount>, 'next'>) => {
const response = await (pageParam?.next ? pageParam.next() : entityFn()) as PaginatedResponse<BaseAccount>;
return {
...response,
items: response.items.map(normalizeAccount),
};
};
const queryInfo = useInfiniteQuery({
queryKey: [Entities.ACCOUNTS, ...listKey],
queryFn: ({ pageParam }) => getAccounts(pageParam),
enabled: true,
initialPageParam: { next: null as (() => Promise<PaginatedResponse<BaseAccount>>) | null },
getNextPageParam: (config) => config.next ? config : undefined,
});
const data = flattenPages<Account>(queryInfo.data as any)?.toReversed() || [];
const { relationships } = useRelationships(
listKey,
entities.map(({ id }) => id),
data.map(({ id }) => id),
);
const accounts: Account[] = entities.map((account) => ({
const accounts = data.map((account) => ({
...account,
relationship: relationships[account.id],
}));
return { accounts, ...rest };
return { accounts, ...queryInfo };
};
const useBlocks = () => {

View file

@ -338,7 +338,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
{(account.is_admin || account.is_moderator) && (
<SidebarLink
to='/dashboard'
to='/admin'
icon={require('@tabler/icons/outline/dashboard.svg')}
text={intl.formatMessage(messages.dashboard)}
onClick={onClose}

View file

@ -87,6 +87,7 @@ const EventActionButton: React.FC<IEventAction> = ({ status, theme = 'secondary'
return (
<Button
className='min-w-max'
size='sm'
theme={theme}
icon={buttonIcon}

View file

@ -38,7 +38,7 @@ const useChatMessages = (chat: Chat) => {
gcTime: 0,
staleTime: 0,
initialPageParam: { next: null as (() => Promise<PaginatedResponse<BaseChatMessage>>) | null },
getNextPageParam: (config) => config,
getNextPageParam: (config) => config.next ? config : undefined,
});
const data = flattenPages<ChatMessage>(queryInfo.data as any)?.toReversed();
@ -76,7 +76,7 @@ const useChats = () => {
placeholderData: keepPreviousData,
enabled: features.chats && !!me,
initialPageParam: { next: null as (() => Promise<PaginatedResponse<Chat>>) | null },
getNextPageParam: (config) => config,
getNextPageParam: (config) => config.next ? config : undefined,
});
const data = flattenPages(queryInfo.data);

View file

@ -8390,10 +8390,10 @@ pkg-types@^1.0.3:
mlly "^1.2.0"
pathe "^1.1.0"
pl-api@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.5.tgz#23214f3308729e23a042af42b60f760a9fe6a781"
integrity sha512-TFYPVAjwtrr2SBDfbl8mZzFrCu3SyIJQbCouw4hbhQzapHZI/ZmhCL9SN/Vi5lWYmuwTqxCfRBE0AX4Zla0O7A==
pl-api@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.6.tgz#9f5c59e68666376e973403419a0d82ab322869e1"
integrity sha512-jSM+GkxeQW31A/cnCtX5E7SBhZy3nh7iHKvcqebSZJFH/LKpkpsaFbH6oNWsr5IWMX5uAJAW2W8u/VsaoOev/g==
dependencies:
blurhash "^2.0.5"
http-link-header "^1.1.3"