fixes
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
cbee2ff018
commit
e73341d1a9
7 changed files with 35 additions and 20 deletions
|
@ -133,7 +133,7 @@
|
||||||
"multiselect-react-dropdown": "^2.0.25",
|
"multiselect-react-dropdown": "^2.0.25",
|
||||||
"object-to-formdata": "^4.5.1",
|
"object-to-formdata": "^4.5.1",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
"pl-api": "^0.0.5",
|
"pl-api": "^0.0.6",
|
||||||
"postcss": "^8.4.29",
|
"postcss": "^8.4.29",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"punycode": "^2.1.1",
|
"punycode": "^2.1.1",
|
||||||
|
|
|
@ -50,7 +50,7 @@ const fetchOAuthTokens = () =>
|
||||||
dispatch({ type: FETCH_TOKENS_REQUEST });
|
dispatch({ type: FETCH_TOKENS_REQUEST });
|
||||||
return getClient(getState).settings.getOauthTokens().then((tokens) => {
|
return getClient(getState).settings.getOauthTokens().then((tokens) => {
|
||||||
dispatch({ type: FETCH_TOKENS_SUCCESS, tokens });
|
dispatch({ type: FETCH_TOKENS_SUCCESS, tokens });
|
||||||
}).catch(() => {
|
}).catch((e) => {
|
||||||
dispatch({ type: FETCH_TOKENS_FAIL });
|
dispatch({ type: FETCH_TOKENS_FAIL });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 { Entities } from 'soapbox/entity-store/entities';
|
||||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
|
||||||
import { useClient } from 'soapbox/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';
|
import { useRelationships } from './useRelationships';
|
||||||
|
|
||||||
|
@ -14,23 +15,36 @@ interface useAccountListOpts {
|
||||||
}
|
}
|
||||||
|
|
||||||
const useAccountList = (listKey: string[], entityFn: EntityFn<void>, opts: useAccountListOpts = {}) => {
|
const useAccountList = (listKey: string[], entityFn: EntityFn<void>, opts: useAccountListOpts = {}) => {
|
||||||
const { entities, ...rest } = useEntities<BaseAccount, Account>(
|
const getAccounts = async (pageParam?: Pick<PaginatedResponse<BaseAccount>, 'next'>) => {
|
||||||
[Entities.ACCOUNTS, ...listKey],
|
const response = await (pageParam?.next ? pageParam.next() : entityFn()) as PaginatedResponse<BaseAccount>;
|
||||||
entityFn,
|
|
||||||
{ schema: listKey[0] === 'mutes' ? mutedAccountSchema : accountSchema, enabled: opts.enabled, transform: normalizeAccount },
|
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(
|
const { relationships } = useRelationships(
|
||||||
listKey,
|
listKey,
|
||||||
entities.map(({ id }) => id),
|
data.map(({ id }) => id),
|
||||||
);
|
);
|
||||||
|
|
||||||
const accounts: Account[] = entities.map((account) => ({
|
const accounts = data.map((account) => ({
|
||||||
...account,
|
...account,
|
||||||
relationship: relationships[account.id],
|
relationship: relationships[account.id],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return { accounts, ...rest };
|
return { accounts, ...queryInfo };
|
||||||
};
|
};
|
||||||
|
|
||||||
const useBlocks = () => {
|
const useBlocks = () => {
|
||||||
|
|
|
@ -338,7 +338,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
|
||||||
|
|
||||||
{(account.is_admin || account.is_moderator) && (
|
{(account.is_admin || account.is_moderator) && (
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
to='/dashboard'
|
to='/admin'
|
||||||
icon={require('@tabler/icons/outline/dashboard.svg')}
|
icon={require('@tabler/icons/outline/dashboard.svg')}
|
||||||
text={intl.formatMessage(messages.dashboard)}
|
text={intl.formatMessage(messages.dashboard)}
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
|
|
|
@ -87,6 +87,7 @@ const EventActionButton: React.FC<IEventAction> = ({ status, theme = 'secondary'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
className='min-w-max'
|
||||||
size='sm'
|
size='sm'
|
||||||
theme={theme}
|
theme={theme}
|
||||||
icon={buttonIcon}
|
icon={buttonIcon}
|
||||||
|
|
|
@ -38,7 +38,7 @@ const useChatMessages = (chat: Chat) => {
|
||||||
gcTime: 0,
|
gcTime: 0,
|
||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
initialPageParam: { next: null as (() => Promise<PaginatedResponse<BaseChatMessage>>) | null },
|
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();
|
const data = flattenPages<ChatMessage>(queryInfo.data as any)?.toReversed();
|
||||||
|
@ -76,7 +76,7 @@ const useChats = () => {
|
||||||
placeholderData: keepPreviousData,
|
placeholderData: keepPreviousData,
|
||||||
enabled: features.chats && !!me,
|
enabled: features.chats && !!me,
|
||||||
initialPageParam: { next: null as (() => Promise<PaginatedResponse<Chat>>) | null },
|
initialPageParam: { next: null as (() => Promise<PaginatedResponse<Chat>>) | null },
|
||||||
getNextPageParam: (config) => config,
|
getNextPageParam: (config) => config.next ? config : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = flattenPages(queryInfo.data);
|
const data = flattenPages(queryInfo.data);
|
||||||
|
|
|
@ -8390,10 +8390,10 @@ pkg-types@^1.0.3:
|
||||||
mlly "^1.2.0"
|
mlly "^1.2.0"
|
||||||
pathe "^1.1.0"
|
pathe "^1.1.0"
|
||||||
|
|
||||||
pl-api@^0.0.5:
|
pl-api@^0.0.6:
|
||||||
version "0.0.5"
|
version "0.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.5.tgz#23214f3308729e23a042af42b60f760a9fe6a781"
|
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.6.tgz#9f5c59e68666376e973403419a0d82ab322869e1"
|
||||||
integrity sha512-TFYPVAjwtrr2SBDfbl8mZzFrCu3SyIJQbCouw4hbhQzapHZI/ZmhCL9SN/Vi5lWYmuwTqxCfRBE0AX4Zla0O7A==
|
integrity sha512-jSM+GkxeQW31A/cnCtX5E7SBhZy3nh7iHKvcqebSZJFH/LKpkpsaFbH6oNWsr5IWMX5uAJAW2W8u/VsaoOev/g==
|
||||||
dependencies:
|
dependencies:
|
||||||
blurhash "^2.0.5"
|
blurhash "^2.0.5"
|
||||||
http-link-header "^1.1.3"
|
http-link-header "^1.1.3"
|
||||||
|
|
Loading…
Reference in a new issue