ProfileHoverCard: use useAccount hook, add usePatronUser hook
This commit is contained in:
@@ -3,22 +3,25 @@ import { useEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { type Account, accountSchema } from 'soapbox/schemas';
|
||||
|
||||
|
||||
import { useRelationships } from './useRelationships';
|
||||
|
||||
function useAccount(id: string) {
|
||||
function useAccount(accountId?: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entity: account, ...result } = useEntity<Account>(
|
||||
[Entities.ACCOUNTS, id],
|
||||
() => api.get(`/api/v1/accounts/${id}`),
|
||||
{ schema: accountSchema },
|
||||
[Entities.ACCOUNTS, accountId || ''],
|
||||
() => api.get(`/api/v1/accounts/${accountId}`),
|
||||
{ schema: accountSchema, enabled: !!accountId },
|
||||
);
|
||||
const { relationships, isLoading } = useRelationships([account?.id as string]);
|
||||
const {
|
||||
relationships,
|
||||
isLoading: isRelationshipLoading,
|
||||
} = useRelationships(accountId ? [accountId] : []);
|
||||
|
||||
return {
|
||||
...result,
|
||||
isLoading: result.isLoading || isLoading,
|
||||
isLoading: result.isLoading,
|
||||
isRelationshipLoading,
|
||||
account: account ? { ...account, relationship: relationships[0] || null } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
18
app/soapbox/api/hooks/accounts/usePatronUser.ts
Normal file
18
app/soapbox/api/hooks/accounts/usePatronUser.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { type PatronUser, patronUserSchema } from 'soapbox/schemas';
|
||||
|
||||
function usePatronUser(url?: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entity: patronUser, ...result } = useEntity<PatronUser>(
|
||||
[Entities.PATRON_USERS, url || ''],
|
||||
() => api.get(`/api/patron/v1/accounts/${encodeURIComponent(url!)}`),
|
||||
{ schema: patronUserSchema, enabled: !!url },
|
||||
);
|
||||
|
||||
return { patronUser, ...result };
|
||||
}
|
||||
|
||||
export { usePatronUser };
|
||||
@@ -3,6 +3,7 @@
|
||||
* Accounts
|
||||
*/
|
||||
export { useAccount } from './accounts/useAccount';
|
||||
export { usePatronUser } from './accounts/usePatronUser';
|
||||
|
||||
/**
|
||||
* Groups
|
||||
|
||||
Reference in New Issue
Block a user