pl-hooks: Updates, add useStatusTranslation query
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
39f975c793
commit
d6aa4bf388
10 changed files with 33 additions and 16 deletions
|
@ -7,7 +7,7 @@ const useAccountRelationship = (accountId?: string) => {
|
||||||
const { client } = usePlHooksApiClient();
|
const { client } = usePlHooksApiClient();
|
||||||
const queryClient = usePlHooksQueryClient();
|
const queryClient = usePlHooksQueryClient();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['accounts', 'entities', accountId],
|
queryKey: ['accounts', 'entities', accountId],
|
||||||
queryFn: async () => (await client.accounts.getRelationships([accountId!]))[0],
|
queryFn: async () => (await client.accounts.getRelationships([accountId!]))[0],
|
||||||
enabled: !!accountId,
|
enabled: !!accountId,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { useQuery, UseQueryResult } from '@tanstack/react-query';
|
||||||
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
||||||
import { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
import { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
||||||
import { importEntities } from 'pl-hooks/importer';
|
import { importEntities } from 'pl-hooks/importer';
|
||||||
import { normalizeAccount, type Account as NormalizedAccount } from 'pl-hooks/normalizers/account';
|
import { normalizeAccount, type NormalizedAccount } from 'pl-hooks/normalizers/account';
|
||||||
|
|
||||||
import { useAccountRelationship } from './use-account-relationship';
|
import { useAccountRelationship } from './use-account-relationship';
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ import { type NormalizedNotification, normalizeNotification } from 'pl-hooks/nor
|
||||||
import { useAccount } from '../accounts/use-account';
|
import { useAccount } from '../accounts/use-account';
|
||||||
import { useStatus } from '../statuses/use-status';
|
import { useStatus } from '../statuses/use-status';
|
||||||
|
|
||||||
import type { Account } from 'pl-hooks/normalizers/account';
|
import type { NormalizedAccount as Account } from 'pl-hooks/normalizers/account';
|
||||||
import type { Status } from 'pl-hooks/normalizers/status';
|
import type { NormalizedStatus as Status } from 'pl-hooks/normalizers/status';
|
||||||
|
|
||||||
const getNotificationStatusId = (n: NormalizedNotification) => {
|
const getNotificationStatusId = (n: NormalizedNotification) => {
|
||||||
if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request'].includes(n.type))
|
if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request'].includes(n.type))
|
||||||
|
|
|
@ -7,7 +7,7 @@ const usePoll = (pollId?: string) => {
|
||||||
const queryClient = usePlHooksQueryClient();
|
const queryClient = usePlHooksQueryClient();
|
||||||
const { client } = usePlHooksApiClient();
|
const { client } = usePlHooksApiClient();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['polls', 'entities', pollId],
|
queryKey: ['polls', 'entities', pollId],
|
||||||
queryFn: () => client.polls.getPoll(pollId!),
|
queryFn: () => client.polls.getPoll(pollId!),
|
||||||
enabled: !!pollId,
|
enabled: !!pollId,
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
||||||
|
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
||||||
|
|
||||||
|
const useStatusTranslation = (statusId: string, targetLanguage?: string) => {
|
||||||
|
const { client } = usePlHooksApiClient();
|
||||||
|
const queryClient = usePlHooksQueryClient();
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['statuses', 'translations', statusId, targetLanguage],
|
||||||
|
queryFn: () => client.statuses.translateStatus(statusId, targetLanguage),
|
||||||
|
enabled: !!targetLanguage,
|
||||||
|
}, queryClient);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useStatusTranslation };
|
|
@ -4,8 +4,8 @@ import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
||||||
import { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
import { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
||||||
import { importEntities } from 'pl-hooks/importer';
|
import { importEntities } from 'pl-hooks/importer';
|
||||||
import { usePoll } from 'pl-hooks/main';
|
import { usePoll } from 'pl-hooks/main';
|
||||||
import { type Account, normalizeAccount } from 'pl-hooks/normalizers/account';
|
import { normalizeAccount, type NormalizedAccount } from 'pl-hooks/normalizers/account';
|
||||||
import { type Status as NormalizedStatus, normalizeStatus } from 'pl-hooks/normalizers/status';
|
import { type NormalizedStatus, normalizeStatus } from 'pl-hooks/normalizers/status';
|
||||||
|
|
||||||
import type { Poll } from 'pl-api';
|
import type { Poll } from 'pl-api';
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ const importStatus = (status: NormalizedStatus) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Status = NormalizedStatus & {
|
type Status = NormalizedStatus & {
|
||||||
account: Account;
|
account: NormalizedAccount;
|
||||||
accounts: Array<Account>;
|
accounts: Array<NormalizedAccount>;
|
||||||
poll?: Poll;
|
poll?: Poll;
|
||||||
reblog?: Status;
|
reblog?: Status;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { queryClient } from 'pl-hooks/contexts/query-client';
|
import { queryClient } from 'pl-hooks/contexts/query-client';
|
||||||
|
|
||||||
import { type DeduplicatedNotification, type NormalizedNotification, normalizeNotification } from './normalizers/notification';
|
import { type DeduplicatedNotification, type NormalizedNotification, normalizeNotification } from './normalizers/notification';
|
||||||
import { normalizeStatus, type Status } from './normalizers/status';
|
import { normalizeStatus, type NormalizedStatus } from './normalizers/status';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Account as BaseAccount,
|
Account as BaseAccount,
|
||||||
|
@ -32,7 +32,7 @@ const importRelationship = (relationship: BaseRelationship) => queryClient.setQu
|
||||||
['relationships', 'entities', relationship.id], relationship,
|
['relationships', 'entities', relationship.id], relationship,
|
||||||
);
|
);
|
||||||
|
|
||||||
const importStatus = (status: BaseStatus) => queryClient.setQueryData<Status>(
|
const importStatus = (status: BaseStatus) => queryClient.setQueryData<NormalizedStatus>(
|
||||||
['statuses', 'entities', status.id], normalizeStatus(status),
|
['statuses', 'entities', status.id], normalizeStatus(status),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,8 @@ export * from './hooks/notifications/use-notification';
|
||||||
export * from './hooks/notifications/use-notification-list';
|
export * from './hooks/notifications/use-notification-list';
|
||||||
export * from './hooks/polls/use-poll';
|
export * from './hooks/polls/use-poll';
|
||||||
export * from './hooks/statuses/use-status';
|
export * from './hooks/statuses/use-status';
|
||||||
|
export * from './hooks/statuses/use-status-translation';
|
||||||
|
|
||||||
export * from './importer';
|
export * from './importer';
|
||||||
|
|
||||||
|
export type { NormalizedAccount } from './normalizers/account';
|
||||||
|
|
|
@ -7,4 +7,4 @@ const normalizeAccount = ({ moved, relationship, ...account }: BaseAccount) => (
|
||||||
|
|
||||||
type Account = ReturnType<typeof normalizeAccount>;
|
type Account = ReturnType<typeof normalizeAccount>;
|
||||||
|
|
||||||
export { normalizeAccount, type Account };
|
export { normalizeAccount, type Account as NormalizedAccount };
|
||||||
|
|
|
@ -55,14 +55,11 @@ const normalizeStatus = ({ account, accounts, reblog, poll, group, quote, ...sta
|
||||||
reblog_id: reblog?.id || null,
|
reblog_id: reblog?.id || null,
|
||||||
poll_id: poll?.id || null,
|
poll_id: poll?.id || null,
|
||||||
group_id: group?.id || null,
|
group_id: group?.id || null,
|
||||||
translating: false,
|
|
||||||
expectsCard: false,
|
expectsCard: false,
|
||||||
showFiltered: null as null | boolean,
|
showFiltered: null as null | boolean,
|
||||||
...status,
|
...status,
|
||||||
quote_id: quote?.id || status.quote_id || null,
|
quote_id: quote?.id || status.quote_id || null,
|
||||||
mentions,
|
mentions,
|
||||||
expanded: null,
|
|
||||||
hidden: null,
|
|
||||||
filtered: status.filtered?.map(result => result.filter.title),
|
filtered: status.filtered?.map(result => result.filter.title),
|
||||||
event,
|
event,
|
||||||
media_attachments,
|
media_attachments,
|
||||||
|
@ -75,5 +72,5 @@ export {
|
||||||
type StatusApprovalStatus,
|
type StatusApprovalStatus,
|
||||||
type StatusVisibility,
|
type StatusVisibility,
|
||||||
normalizeStatus,
|
normalizeStatus,
|
||||||
type Status,
|
type Status as NormalizedStatus,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue