Apply some changes from hooks-migration branch
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
91a4950b7b
commit
e62e09e387
5 changed files with 31 additions and 20 deletions
|
@ -119,7 +119,7 @@ const baseAccountSchema = v.object({
|
||||||
following_count: v.fallback(v.number(), 0),
|
following_count: v.fallback(v.number(), 0),
|
||||||
roles: filteredArray(roleSchema),
|
roles: filteredArray(roleSchema),
|
||||||
|
|
||||||
fqn: v.fallback(v.nullable(v.string()), null),
|
fqn: v.string(),
|
||||||
ap_id: v.fallback(v.nullable(v.string()), null),
|
ap_id: v.fallback(v.nullable(v.string()), null),
|
||||||
background_image: v.fallback(v.nullable(v.string()), null),
|
background_image: v.fallback(v.nullable(v.string()), null),
|
||||||
relationship: v.fallback(v.optional(relationshipSchema), undefined),
|
relationship: v.fallback(v.optional(relationshipSchema), undefined),
|
||||||
|
|
|
@ -3,13 +3,16 @@ import { useQuery } from '@tanstack/react-query';
|
||||||
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
|
||||||
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
||||||
|
|
||||||
|
import type { Translation } from 'pl-api';
|
||||||
|
|
||||||
const useStatusTranslation = (statusId: string, targetLanguage?: string) => {
|
const useStatusTranslation = (statusId: string, targetLanguage?: string) => {
|
||||||
const { client } = usePlHooksApiClient();
|
const { client } = usePlHooksApiClient();
|
||||||
const queryClient = usePlHooksQueryClient();
|
const queryClient = usePlHooksQueryClient();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery<Translation | false>({
|
||||||
queryKey: ['statuses', 'translations', statusId, targetLanguage],
|
queryKey: ['statuses', 'translations', statusId, targetLanguage],
|
||||||
queryFn: () => client.statuses.translateStatus(statusId, targetLanguage),
|
queryFn: () => client.statuses.translateStatus(statusId, targetLanguage)
|
||||||
|
.then(translation => translation).catch(() => false),
|
||||||
enabled: !!targetLanguage,
|
enabled: !!targetLanguage,
|
||||||
}, queryClient);
|
}, queryClient);
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,13 +38,15 @@ const importStatus = (status: BaseStatus) => queryClient.setQueryData<Normalized
|
||||||
|
|
||||||
const isEmpty = (object: Record<string, any>) => !Object.values(object).some(value => value);
|
const isEmpty = (object: Record<string, any>) => !Object.values(object).some(value => value);
|
||||||
|
|
||||||
|
type OptionalArray<T> = Array<T | undefined | null>;
|
||||||
|
|
||||||
const importEntities = (entities: {
|
const importEntities = (entities: {
|
||||||
accounts?: Array<BaseAccount>;
|
accounts?: OptionalArray<BaseAccount>;
|
||||||
groups?: Array<BaseGroup>;
|
groups?: OptionalArray<BaseGroup>;
|
||||||
notifications?: Array<DeduplicatedNotification>;
|
notifications?: OptionalArray<DeduplicatedNotification>;
|
||||||
polls?: Array<BasePoll>;
|
polls?: OptionalArray<BasePoll>;
|
||||||
statuses?: Array<BaseStatus>;
|
statuses?: OptionalArray<BaseStatus>;
|
||||||
relationships?: Array<BaseRelationship>;
|
relationships?: OptionalArray<BaseRelationship>;
|
||||||
}, options = {
|
}, options = {
|
||||||
withParents: true,
|
withParents: true,
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -90,14 +92,14 @@ const importEntities = (entities: {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.withParents) {
|
if (options.withParents) {
|
||||||
entities.groups?.forEach(group => groups[group.id] = group);
|
entities.groups?.forEach(group => group && (groups[group.id] = group));
|
||||||
entities.polls?.forEach(poll => polls[poll.id] = poll);
|
entities.polls?.forEach(poll => poll && (polls[poll.id] = poll));
|
||||||
entities.relationships?.forEach(relationship => relationships[relationship.id] = relationship);
|
entities.relationships?.forEach(relationship => relationship && (relationships[relationship.id] = relationship));
|
||||||
}
|
}
|
||||||
|
|
||||||
entities.accounts?.forEach((account) => processAccount(account, options.withParents));
|
entities.accounts?.forEach((account) => account && processAccount(account, options.withParents));
|
||||||
entities.notifications?.forEach((notification) => processNotification(notification, options.withParents));
|
entities.notifications?.forEach((notification) => notification && processNotification(notification, options.withParents));
|
||||||
entities.statuses?.forEach((status) => processStatus(status, options.withParents));
|
entities.statuses?.forEach((status) => status && processStatus(status, options.withParents));
|
||||||
|
|
||||||
if (!isEmpty(accounts)) Object.values(accounts).forEach(importAccount);
|
if (!isEmpty(accounts)) Object.values(accounts).forEach(importAccount);
|
||||||
if (!isEmpty(groups)) Object.values(groups).forEach(importGroup);
|
if (!isEmpty(groups)) Object.values(groups).forEach(importGroup);
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.59.16",
|
"@tanstack/react-query": "^5.59.16",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"pl-api": "^0.1.5",
|
"pl-api": "^0.1.9",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"valibot": "^0.42.1"
|
"valibot": "^0.42.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1891,6 +1891,11 @@ lodash.merge@^4.6.2:
|
||||||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
||||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||||
|
|
||||||
|
lodash.omit@^4.5.0:
|
||||||
|
version "4.5.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"
|
||||||
|
integrity sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==
|
||||||
|
|
||||||
lodash.pick@^4.4.0:
|
lodash.pick@^4.4.0:
|
||||||
version "4.4.0"
|
version "4.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
|
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
|
||||||
|
@ -2148,13 +2153,14 @@ pkg-types@^1.0.3, pkg-types@^1.1.1:
|
||||||
mlly "^1.7.1"
|
mlly "^1.7.1"
|
||||||
pathe "^1.1.2"
|
pathe "^1.1.2"
|
||||||
|
|
||||||
pl-api@^0.1.5:
|
pl-api@^0.1.9:
|
||||||
version "0.1.5"
|
version "0.1.9"
|
||||||
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.1.5.tgz#373d58fc40ae23b12c6d20def8d3332112e2dd93"
|
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.1.9.tgz#250aacb4533de0acbe0aa487c2810806a2d99415"
|
||||||
integrity sha512-IMcwANPtTRMv+tTLW4ic/o/usYIHeapR+aOx5YhmmVQsXTiVUZQtCVLmrfIrqMnyXm8PHvE/arzzozRFU8+GXQ==
|
integrity sha512-5r+TZXbEBU9BednnYXxdI1KgnvRSy/lhSLLU8ZsmMgapy+IyxG2yGmxSc7j0NuC59kBYxlKKwaRgdRvwclQOaQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
blurhash "^2.0.5"
|
blurhash "^2.0.5"
|
||||||
http-link-header "^1.1.3"
|
http-link-header "^1.1.3"
|
||||||
|
lodash.omit "^4.5.0"
|
||||||
lodash.pick "^4.4.0"
|
lodash.pick "^4.4.0"
|
||||||
object-to-formdata "^4.5.1"
|
object-to-formdata "^4.5.1"
|
||||||
query-string "^9.1.0"
|
query-string "^9.1.0"
|
||||||
|
|
Loading…
Reference in a new issue