diff --git a/packages/pl-api/lib/entities/account.ts b/packages/pl-api/lib/entities/account.ts index 068320331..e75290ff3 100644 --- a/packages/pl-api/lib/entities/account.ts +++ b/packages/pl-api/lib/entities/account.ts @@ -119,7 +119,7 @@ const baseAccountSchema = v.object({ following_count: v.fallback(v.number(), 0), roles: filteredArray(roleSchema), - fqn: v.fallback(v.nullable(v.string()), null), + fqn: v.string(), ap_id: v.fallback(v.nullable(v.string()), null), background_image: v.fallback(v.nullable(v.string()), null), relationship: v.fallback(v.optional(relationshipSchema), undefined), diff --git a/packages/pl-hooks/lib/hooks/statuses/use-status-translation.ts b/packages/pl-hooks/lib/hooks/statuses/use-status-translation.ts index 1a079adde..016460c47 100644 --- a/packages/pl-hooks/lib/hooks/statuses/use-status-translation.ts +++ b/packages/pl-hooks/lib/hooks/statuses/use-status-translation.ts @@ -3,13 +3,16 @@ import { useQuery } from '@tanstack/react-query'; import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client'; import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client'; +import type { Translation } from 'pl-api'; + const useStatusTranslation = (statusId: string, targetLanguage?: string) => { const { client } = usePlHooksApiClient(); const queryClient = usePlHooksQueryClient(); - return useQuery({ + return useQuery({ queryKey: ['statuses', 'translations', statusId, targetLanguage], - queryFn: () => client.statuses.translateStatus(statusId, targetLanguage), + queryFn: () => client.statuses.translateStatus(statusId, targetLanguage) + .then(translation => translation).catch(() => false), enabled: !!targetLanguage, }, queryClient); }; diff --git a/packages/pl-hooks/lib/importer.ts b/packages/pl-hooks/lib/importer.ts index ec9d94b3a..fea450318 100644 --- a/packages/pl-hooks/lib/importer.ts +++ b/packages/pl-hooks/lib/importer.ts @@ -38,13 +38,15 @@ const importStatus = (status: BaseStatus) => queryClient.setQueryData) => !Object.values(object).some(value => value); +type OptionalArray = Array; + const importEntities = (entities: { - accounts?: Array; - groups?: Array; - notifications?: Array; - polls?: Array; - statuses?: Array; - relationships?: Array; + accounts?: OptionalArray; + groups?: OptionalArray; + notifications?: OptionalArray; + polls?: OptionalArray; + statuses?: OptionalArray; + relationships?: OptionalArray; }, options = { withParents: true, }) => { @@ -90,14 +92,14 @@ const importEntities = (entities: { }; if (options.withParents) { - entities.groups?.forEach(group => groups[group.id] = group); - entities.polls?.forEach(poll => polls[poll.id] = poll); - entities.relationships?.forEach(relationship => relationships[relationship.id] = relationship); + entities.groups?.forEach(group => group && (groups[group.id] = group)); + entities.polls?.forEach(poll => poll && (polls[poll.id] = poll)); + entities.relationships?.forEach(relationship => relationship && (relationships[relationship.id] = relationship)); } - entities.accounts?.forEach((account) => processAccount(account, options.withParents)); - entities.notifications?.forEach((notification) => processNotification(notification, options.withParents)); - entities.statuses?.forEach((status) => processStatus(status, options.withParents)); + entities.accounts?.forEach((account) => account && processAccount(account, options.withParents)); + entities.notifications?.forEach((notification) => notification && processNotification(notification, options.withParents)); + entities.statuses?.forEach((status) => status && processStatus(status, options.withParents)); if (!isEmpty(accounts)) Object.values(accounts).forEach(importAccount); if (!isEmpty(groups)) Object.values(groups).forEach(importGroup); diff --git a/packages/pl-hooks/package.json b/packages/pl-hooks/package.json index ab831efc2..0c9f64118 100644 --- a/packages/pl-hooks/package.json +++ b/packages/pl-hooks/package.json @@ -35,7 +35,7 @@ "dependencies": { "@tanstack/react-query": "^5.59.16", "lodash": "^4.17.21", - "pl-api": "^0.1.5", + "pl-api": "^0.1.9", "react": "^18.3.1", "valibot": "^0.42.1" }, diff --git a/packages/pl-hooks/yarn.lock b/packages/pl-hooks/yarn.lock index 27943bcde..c32f4cc7f 100644 --- a/packages/pl-hooks/yarn.lock +++ b/packages/pl-hooks/yarn.lock @@ -1891,6 +1891,11 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" 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: version "4.4.0" 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" pathe "^1.1.2" -pl-api@^0.1.5: - version "0.1.5" - resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.1.5.tgz#373d58fc40ae23b12c6d20def8d3332112e2dd93" - integrity sha512-IMcwANPtTRMv+tTLW4ic/o/usYIHeapR+aOx5YhmmVQsXTiVUZQtCVLmrfIrqMnyXm8PHvE/arzzozRFU8+GXQ== +pl-api@^0.1.9: + version "0.1.9" + resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.1.9.tgz#250aacb4533de0acbe0aa487c2810806a2d99415" + integrity sha512-5r+TZXbEBU9BednnYXxdI1KgnvRSy/lhSLLU8ZsmMgapy+IyxG2yGmxSc7j0NuC59kBYxlKKwaRgdRvwclQOaQ== dependencies: blurhash "^2.0.5" http-link-header "^1.1.3" + lodash.omit "^4.5.0" lodash.pick "^4.4.0" object-to-formdata "^4.5.1" query-string "^9.1.0"