pl-fe: migrate /api/v*/instance to tanstack query

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2024-12-03 15:03:17 +01:00
parent 2086e027ad
commit 1f8b79f309
79 changed files with 240 additions and 337 deletions

View File

@ -56,10 +56,6 @@ const getAuthUserUrl = (state: RootState) => {
].filter(url => url).find(isURL);
};
/** Get the VAPID public key. */
const getVapidKey = (state: RootState) =>
state.auth.app?.vapid_key || state.instance.configuration.vapid.public_key;
const getMeUrl = (state: RootState) => selectOwnAccount(state)?.url;
export {
@ -71,6 +67,5 @@ export {
getAccessToken,
getAuthUserId,
getAuthUserUrl,
getVapidKey,
getMeUrl,
};

View File

@ -1,15 +1,16 @@
import { getFeatures, PLEROMA, TOKI, type Instance } from 'pl-api';
import type { RootState } from 'pl-fe/store';
import * as BuildConfig from 'pl-fe/build-config';
import { queryClient } from 'pl-fe/queries/client';
/**
* Get the OAuth scopes to use for login & signup.
* Mastodon will refuse scopes it doesn't know, so care is needed.
*/
const getInstanceScopes = (instance: Instance) => {
const v = getFeatures(instance).version;
const getInstanceScopes = (instance?: Instance) => {
const software = instance ? getFeatures(instance).version.software : null;
switch (v.software) {
switch (software) {
case TOKI:
return 'read write follow push write:bites';
case PLEROMA:
@ -20,7 +21,11 @@ const getInstanceScopes = (instance: Instance) => {
};
/** Convenience function to get scopes from instance in store. */
const getScopes = (state: RootState) => getInstanceScopes(state.instance);
const getScopes = (baseURL = BuildConfig.BACKEND_URL || '') => {
const instance = queryClient.getQueryData<Instance>(['instance', 'instanceInformation', baseURL]);
return getInstanceScopes(instance);
};
export {
getInstanceScopes,

View File

@ -9,14 +9,15 @@ import { isPrerendered } from 'pl-fe/precheck';
import { selectOwnAccount } from 'pl-fe/selectors';
import { isURL } from 'pl-fe/utils/auth';
import type { Instance } from 'pl-api';
import type { RootState } from 'pl-fe/store';
/** Whether to display the fqn instead of the acct. */
const displayFqn = (state: RootState): boolean => getPlFeConfig(state).displayFqn;
/** Whether the instance exposes instance blocks through the API. */
const federationRestrictionsDisclosed = (state: RootState): boolean =>
!!state.instance.pleroma.metadata.federation.mrf_policies;
const federationRestrictionsDisclosed = (instance: Instance): boolean =>
!!instance.pleroma.metadata.federation.mrf_policies;
/**
* Determine whether pl-fe is running in standalone mode.