pl-hooks: more prefetching
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
558f89ee10
commit
2fb53d92be
6 changed files with 24 additions and 9 deletions
|
@ -144,7 +144,6 @@
|
||||||
"vite-plugin-html": "^3.2.2",
|
"vite-plugin-html": "^3.2.2",
|
||||||
"vite-plugin-require": "^1.2.14",
|
"vite-plugin-require": "^1.2.14",
|
||||||
"vite-plugin-static-copy": "^1.0.6",
|
"vite-plugin-static-copy": "^1.0.6",
|
||||||
"wicg-inert": "^3.1.3",
|
|
||||||
"zustand": "^5.0.0-rc.2"
|
"zustand": "^5.0.0-rc.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -10172,11 +10172,6 @@ why-is-node-running@^2.3.0:
|
||||||
siginfo "^2.0.0"
|
siginfo "^2.0.0"
|
||||||
stackback "0.0.2"
|
stackback "0.0.2"
|
||||||
|
|
||||||
wicg-inert@^3.1.3:
|
|
||||||
version "3.1.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/wicg-inert/-/wicg-inert-3.1.3.tgz#e53dbc9ac1e0d7f8c60f25e707614a835986272a"
|
|
||||||
integrity sha512-5L0PKK7iP+0Q/jv2ccgmkz/pfXbumZtlEyWS/xnX+L+Og3f7WjL4+iEs18k4IuldOX3PgGpza3qGndL9xUBjCQ==
|
|
||||||
|
|
||||||
word-wrap@^1.2.5:
|
word-wrap@^1.2.5:
|
||||||
version "1.2.5"
|
version "1.2.5"
|
||||||
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
|
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import { useQuery } from '@tanstack/react-query';
|
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 { queryClient, usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
|
||||||
|
import { importEntities } from 'pl-hooks/importer';
|
||||||
import { type Account, normalizeAccount } from 'pl-hooks/normalizers/normalizeAccount';
|
import { type Account, normalizeAccount } from 'pl-hooks/normalizers/normalizeAccount';
|
||||||
|
|
||||||
import { useAccountRelationship } from './useAccountRelationship';
|
import { useAccountRelationship } from './useAccountRelationship';
|
||||||
|
|
||||||
|
import type { PlApiClient } from 'pl-api';
|
||||||
|
|
||||||
interface UseAccountOpts {
|
interface UseAccountOpts {
|
||||||
withRelationship?: boolean;
|
withRelationship?: boolean;
|
||||||
withScrobble?: boolean;
|
withScrobble?: boolean;
|
||||||
|
@ -38,4 +41,15 @@ const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => {
|
||||||
return { ...accountQuery, data };
|
return { ...accountQuery, data };
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useAccount, type UseAccountOpts };
|
const prefetchAccount = (client: PlApiClient, accountId: string) =>
|
||||||
|
queryClient.prefetchQuery({
|
||||||
|
queryKey: ['accounts', 'entities', accountId],
|
||||||
|
queryFn: () => client.accounts.getAccount(accountId!)
|
||||||
|
.then(account => {
|
||||||
|
importEntities({ accounts: [account] }, { withParents: false });
|
||||||
|
|
||||||
|
return normalizeAccount(account);
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export { useAccount, prefetchAccount, type UseAccountOpts };
|
||||||
|
|
|
@ -12,7 +12,6 @@ import type {
|
||||||
} from 'pl-api';
|
} from 'pl-api';
|
||||||
|
|
||||||
const importAccount = (account: BaseAccount) => {
|
const importAccount = (account: BaseAccount) => {
|
||||||
queryClient.setQueryData<string>(['accounts', 'byAcct', account.acct.toLocaleLowerCase()], account.id);
|
|
||||||
return queryClient.setQueryData<BaseAccount>(['accounts', 'entities', account.id], account);
|
return queryClient.setQueryData<BaseAccount>(['accounts', 'entities', account.id], account);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +57,8 @@ const importEntities = (entities: {
|
||||||
const statuses: Record<string, BaseStatus> = {};
|
const statuses: Record<string, BaseStatus> = {};
|
||||||
|
|
||||||
const processAccount = (account: BaseAccount) => {
|
const processAccount = (account: BaseAccount) => {
|
||||||
|
queryClient.setQueryData<string>(['accounts', 'byAcct', account.acct.toLocaleLowerCase()], account.id);
|
||||||
|
|
||||||
if (account.moved) processAccount(account.moved);
|
if (account.moved) processAccount(account.moved);
|
||||||
if (account.relationship) relationships[account.relationship.id] = account.relationship;
|
if (account.relationship) relationships[account.relationship.id] = account.relationship;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@ export * from './hooks/markers/useMarkers';
|
||||||
export * from './hooks/markers/useUpdateMarkerMutation';
|
export * from './hooks/markers/useUpdateMarkerMutation';
|
||||||
export * from './hooks/notifications/useNotification';
|
export * from './hooks/notifications/useNotification';
|
||||||
export * from './hooks/notifications/useNotificationList';
|
export * from './hooks/notifications/useNotificationList';
|
||||||
|
export * from './hooks/polls/usePoll';
|
||||||
export * from './hooks/statuses/useStatus';
|
export * from './hooks/statuses/useStatus';
|
||||||
|
|
||||||
export * from './importer';
|
export * from './importer';
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { resolve } from 'path';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import dts from 'vite-plugin-dts';
|
import dts from 'vite-plugin-dts';
|
||||||
|
|
||||||
|
import pkg from './package.json';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [dts({ include: ['lib'], insertTypesEntry: true })],
|
plugins: [dts({ include: ['lib'], insertTypesEntry: true })],
|
||||||
build: {
|
build: {
|
||||||
|
@ -16,6 +18,9 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
rollupOptions: {
|
||||||
|
external: Object.keys(pkg.dependencies),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: [
|
alias: [
|
||||||
|
|
Loading…
Reference in a new issue